blob: a04ca5c17e55f68dc739d4bf15c8ecbadedf06fc [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
Akron8ea84292018-10-24 13:41:52 +020026
Akron8eef3462018-09-20 16:45:10 +020027if (0) {
28
Nils Diewald034ea702015-01-16 19:41:52 +000029
30# Check paging
Akron3042f242017-04-15 16:57:55 +020031$t->get_ok('/?q=Baum')
32 ->text_like('h1 span', qr/KorAP: Find .Baum./i)
Nils Diewalda748b0e2015-05-19 22:54:06 +000033 # ->text_is('pre.query.serial span', 'JSON-LD Serialization for "test"')
34 ->text_like('#total-results', qr/\d+$/)
Nils Diewald034ea702015-01-16 19:41:52 +000035 ->text_is('#pagination a[rel=self] span', 1)
Akron45cd0ce2017-04-18 23:24:29 +020036 ->element_exists_not('#ql-field option[value=poliqarp][selected]')
37 ->element_exists_not('#ql-field option[value=cosmas2][selected]')
Akron3042f242017-04-15 16:57:55 +020038 ;
39
Nils Diewald034ea702015-01-16 19:41:52 +000040# Check paging
Akron45cd0ce2017-04-18 23:24:29 +020041$t->get_ok('/?q=test&p=2&ql=cosmas2')
Nils Diewalda748b0e2015-05-19 22:54:06 +000042 ->text_like('#total-results', qr/\d+$/)
Nils Diewald034ea702015-01-16 19:41:52 +000043 ->text_is('#pagination a[rel=self] span', 2)
Akron45cd0ce2017-04-18 23:24:29 +020044 ->element_exists('#ql-field option[value=cosmas2][selected]')
45 ->element_exists_not('#ql-field option[value=poliqarp][selected]')
Nils Diewald034ea702015-01-16 19:41:52 +000046;
47
Akron14a79e62017-04-24 20:16:58 +020048# Check paging
49$t->get_ok('/?q=test&p=2&ql=cosmas2')
50 ->text_like('#total-results', qr/\d+$/)
51 ->text_is('#pagination a[rel=self] span', 2)
52 ->element_exists('#ql-field option[value=cosmas2][selected]')
53 ->element_exists_not('#ql-field option[value=poliqarp][selected]')
54;
55
56# Check for authorization
57# this should just trigger a fixture - it's not serious
58$t->get_ok('/?q=test&p=2&ql=cosmas3')
59 ->element_exists_not('#pagination a[rel=self] span')
60 ->element_exists('#search #no-results')
61 ->text_like('.notify-error', qr!No entity found!)
62 ;
63
Akron1b0c2652017-04-27 15:28:49 +020064
Akron3fe9fc32018-03-20 13:12:31 +010065# Check for server error
66$t->get_ok('/?q=server_fail&ql=poliqarp')
67 ->element_exists('.notify-error')
68 ->text_is('.notify-error', '500: Internal Server Error (remote)')
69 ;
Akron1b0c2652017-04-27 15:28:49 +020070
Akron8eef3462018-09-20 16:45:10 +020071};
72
Akronf44a0a22018-07-05 11:19:49 +020073
74# Check for query error
75$t->get_ok('/?q=[orth=das&ql=poliqarp')
76 ->element_exists('.notify-error')
77 ->text_is('.notify-error', '302: Parantheses/brackets unbalanced.')
Akron8eef3462018-09-20 16:45:10 +020078 ->content_like(qr!KorAP\.koralQuery =!)
Akron8ea84292018-10-24 13:41:52 +020079 ->text_is('.no-results:nth-of-type(1)', 'Unable to perform the search.')
Akronf44a0a22018-07-05 11:19:49 +020080 ;
81
Nils Diewalda748b0e2015-05-19 22:54:06 +000082done_testing;
83__END__