Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 1 | use Mojo::Base -strict; |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 2 | use Mojo::File qw/path/; |
Akron | 3042f24 | 2017-04-15 16:57:55 +0200 | [diff] [blame] | 3 | use Test::More; |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 4 | use Test::Mojo; |
| 5 | |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 6 | my $mount_point = '/api/'; |
| 7 | $ENV{KALAMAR_API} = $mount_point; |
Akron | 3042f24 | 2017-04-15 16:57:55 +0200 | [diff] [blame] | 8 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 9 | my $t = Test::Mojo->new('Kalamar'); |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 10 | $t->app->defaults('auth_support' => 1); |
| 11 | |
| 12 | # Mount fake backend |
| 13 | # Get the fixture path |
| 14 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'fixtures'); |
| 15 | my $fake_backend = $t->app->plugin( |
| 16 | Mount => { |
| 17 | $mount_point => |
Akron | 6d49c1f | 2018-10-11 14:22:21 +0200 | [diff] [blame] | 18 | $fixtures_path->child('fake_backend.pl') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 19 | } |
| 20 | ); |
| 21 | |
| 22 | # Configure fake backend |
| 23 | $fake_backend->pattern->defaults->{app}->log($t->app->log); |
| 24 | |
Akron | 3042f24 | 2017-04-15 16:57:55 +0200 | [diff] [blame] | 25 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame^] | 26 | |
Akron | 8eef346 | 2018-09-20 16:45:10 +0200 | [diff] [blame] | 27 | if (0) { |
| 28 | |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 29 | |
| 30 | # Check paging |
Akron | 3042f24 | 2017-04-15 16:57:55 +0200 | [diff] [blame] | 31 | $t->get_ok('/?q=Baum') |
| 32 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 33 | # ->text_is('pre.query.serial span', 'JSON-LD Serialization for "test"') |
| 34 | ->text_like('#total-results', qr/\d+$/) |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 35 | ->text_is('#pagination a[rel=self] span', 1) |
Akron | 45cd0ce | 2017-04-18 23:24:29 +0200 | [diff] [blame] | 36 | ->element_exists_not('#ql-field option[value=poliqarp][selected]') |
| 37 | ->element_exists_not('#ql-field option[value=cosmas2][selected]') |
Akron | 3042f24 | 2017-04-15 16:57:55 +0200 | [diff] [blame] | 38 | ; |
| 39 | |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 40 | # Check paging |
Akron | 45cd0ce | 2017-04-18 23:24:29 +0200 | [diff] [blame] | 41 | $t->get_ok('/?q=test&p=2&ql=cosmas2') |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 42 | ->text_like('#total-results', qr/\d+$/) |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 43 | ->text_is('#pagination a[rel=self] span', 2) |
Akron | 45cd0ce | 2017-04-18 23:24:29 +0200 | [diff] [blame] | 44 | ->element_exists('#ql-field option[value=cosmas2][selected]') |
| 45 | ->element_exists_not('#ql-field option[value=poliqarp][selected]') |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 46 | ; |
| 47 | |
Akron | 14a79e6 | 2017-04-24 20:16:58 +0200 | [diff] [blame] | 48 | # 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 | |
Akron | 1b0c265 | 2017-04-27 15:28:49 +0200 | [diff] [blame] | 64 | |
Akron | 3fe9fc3 | 2018-03-20 13:12:31 +0100 | [diff] [blame] | 65 | # 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 | ; |
Akron | 1b0c265 | 2017-04-27 15:28:49 +0200 | [diff] [blame] | 70 | |
Akron | 8eef346 | 2018-09-20 16:45:10 +0200 | [diff] [blame] | 71 | }; |
| 72 | |
Akron | f44a0a2 | 2018-07-05 11:19:49 +0200 | [diff] [blame] | 73 | |
| 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.') |
Akron | 8eef346 | 2018-09-20 16:45:10 +0200 | [diff] [blame] | 78 | ->content_like(qr!KorAP\.koralQuery =!) |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame^] | 79 | ->text_is('.no-results:nth-of-type(1)', 'Unable to perform the search.') |
Akron | f44a0a2 | 2018-07-05 11:19:49 +0200 | [diff] [blame] | 80 | ; |
| 81 | |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 82 | done_testing; |
| 83 | __END__ |