blob: 328b4ef9165cf8c1b7191782cf0940b06be458ba [file] [log] [blame]
Nils Diewald034ea702015-01-16 19:41:52 +00001use Mojo::Base -strict;
Akron0e1ed242018-10-11 13:22:00 +02002use Mojo::File qw/path/;
Akron3042f242017-04-15 16:57:55 +02003use Test::More;
Nils Diewald034ea702015-01-16 19:41:52 +00004use Test::Mojo;
5
Akron0e1ed242018-10-11 13:22:00 +02006my $mount_point = '/api/';
7$ENV{KALAMAR_API} = $mount_point;
Akron3042f242017-04-15 16:57:55 +02008
Nils Diewald2fe12e12015-03-06 16:47:06 +00009my $t = Test::Mojo->new('Kalamar');
Akron0e1ed242018-10-11 13:22:00 +020010$t->app->defaults('auth_support' => 1);
11
12# Mount fake backend
13# Get the fixture path
14my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'fixtures');
15my $fake_backend = $t->app->plugin(
16 Mount => {
17 $mount_point =>
Akron6d49c1f2018-10-11 14:22:21 +020018 $fixtures_path->child('fake_backend.pl')
Akron0e1ed242018-10-11 13:22:00 +020019 }
20);
21
22# Configure fake backend
23$fake_backend->pattern->defaults->{app}->log($t->app->log);
24
Akron3042f242017-04-15 16:57:55 +020025
Akron8eef3462018-09-20 16:45:10 +020026if (0) {
27
Nils Diewald034ea702015-01-16 19:41:52 +000028$t->get_ok('/')
29 ->status_is(200)
Nils Diewalda748b0e2015-05-19 22:54:06 +000030 ->text_is('title', 'KorAP - Corpus Analysis Platform')
31 ->text_like('h1 span', qr/KorAP - Corpus Analysis Platform/i)
Nils Diewald034ea702015-01-16 19:41:52 +000032 ;
33
34# Check paging
Akron3042f242017-04-15 16:57:55 +020035$t->get_ok('/?q=Baum')
36 ->text_like('h1 span', qr/KorAP: Find .Baum./i)
Nils Diewalda748b0e2015-05-19 22:54:06 +000037 # ->text_is('pre.query.serial span', 'JSON-LD Serialization for "test"')
38 ->text_like('#total-results', qr/\d+$/)
Nils Diewald034ea702015-01-16 19:41:52 +000039 ->text_is('#pagination a[rel=self] span', 1)
Akron45cd0ce2017-04-18 23:24:29 +020040 ->element_exists_not('#ql-field option[value=poliqarp][selected]')
41 ->element_exists_not('#ql-field option[value=cosmas2][selected]')
Akron3042f242017-04-15 16:57:55 +020042 ;
43
Nils Diewald034ea702015-01-16 19:41:52 +000044# Check paging
Akron45cd0ce2017-04-18 23:24:29 +020045$t->get_ok('/?q=test&p=2&ql=cosmas2')
Nils Diewalda748b0e2015-05-19 22:54:06 +000046 ->text_like('#total-results', qr/\d+$/)
Nils Diewald034ea702015-01-16 19:41:52 +000047 ->text_is('#pagination a[rel=self] span', 2)
Akron45cd0ce2017-04-18 23:24:29 +020048 ->element_exists('#ql-field option[value=cosmas2][selected]')
49 ->element_exists_not('#ql-field option[value=poliqarp][selected]')
Nils Diewald034ea702015-01-16 19:41:52 +000050;
51
Akron14a79e62017-04-24 20:16:58 +020052# Check paging
53$t->get_ok('/?q=test&p=2&ql=cosmas2')
54 ->text_like('#total-results', qr/\d+$/)
55 ->text_is('#pagination a[rel=self] span', 2)
56 ->element_exists('#ql-field option[value=cosmas2][selected]')
57 ->element_exists_not('#ql-field option[value=poliqarp][selected]')
58;
59
60# Check for authorization
61# this should just trigger a fixture - it's not serious
62$t->get_ok('/?q=test&p=2&ql=cosmas3')
63 ->element_exists_not('#pagination a[rel=self] span')
64 ->element_exists('#search #no-results')
65 ->text_like('.notify-error', qr!No entity found!)
66 ;
67
Akron1b0c2652017-04-27 15:28:49 +020068
Akron3fe9fc32018-03-20 13:12:31 +010069# Check for server error
70$t->get_ok('/?q=server_fail&ql=poliqarp')
71 ->element_exists('.notify-error')
72 ->text_is('.notify-error', '500: Internal Server Error (remote)')
73 ;
Akron1b0c2652017-04-27 15:28:49 +020074
Akron8eef3462018-09-20 16:45:10 +020075};
76
Akronf44a0a22018-07-05 11:19:49 +020077
Akron0e1ed242018-10-11 13:22:00 +020078
79
Akronf44a0a22018-07-05 11:19:49 +020080# Check for query error
81$t->get_ok('/?q=[orth=das&ql=poliqarp')
82 ->element_exists('.notify-error')
83 ->text_is('.notify-error', '302: Parantheses/brackets unbalanced.')
Akron8eef3462018-09-20 16:45:10 +020084 ->content_like(qr!KorAP\.koralQuery =!)
Akronf44a0a22018-07-05 11:19:49 +020085 ;
86
Nils Diewalda748b0e2015-05-19 22:54:06 +000087done_testing;
88__END__