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 | 8eef346 | 2018-09-20 16:45:10 +0200 | [diff] [blame] | 26 | if (0) { |
| 27 | |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 28 | $t->get_ok('/') |
| 29 | ->status_is(200) |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 30 | ->text_is('title', 'KorAP - Corpus Analysis Platform') |
| 31 | ->text_like('h1 span', qr/KorAP - Corpus Analysis Platform/i) |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 32 | ; |
| 33 | |
| 34 | # Check paging |
Akron | 3042f24 | 2017-04-15 16:57:55 +0200 | [diff] [blame] | 35 | $t->get_ok('/?q=Baum') |
| 36 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 37 | # ->text_is('pre.query.serial span', 'JSON-LD Serialization for "test"') |
| 38 | ->text_like('#total-results', qr/\d+$/) |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 39 | ->text_is('#pagination a[rel=self] span', 1) |
Akron | 45cd0ce | 2017-04-18 23:24:29 +0200 | [diff] [blame] | 40 | ->element_exists_not('#ql-field option[value=poliqarp][selected]') |
| 41 | ->element_exists_not('#ql-field option[value=cosmas2][selected]') |
Akron | 3042f24 | 2017-04-15 16:57:55 +0200 | [diff] [blame] | 42 | ; |
| 43 | |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 44 | # Check paging |
Akron | 45cd0ce | 2017-04-18 23:24:29 +0200 | [diff] [blame] | 45 | $t->get_ok('/?q=test&p=2&ql=cosmas2') |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 46 | ->text_like('#total-results', qr/\d+$/) |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 47 | ->text_is('#pagination a[rel=self] span', 2) |
Akron | 45cd0ce | 2017-04-18 23:24:29 +0200 | [diff] [blame] | 48 | ->element_exists('#ql-field option[value=cosmas2][selected]') |
| 49 | ->element_exists_not('#ql-field option[value=poliqarp][selected]') |
Nils Diewald | 034ea70 | 2015-01-16 19:41:52 +0000 | [diff] [blame] | 50 | ; |
| 51 | |
Akron | 14a79e6 | 2017-04-24 20:16:58 +0200 | [diff] [blame] | 52 | # 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 | |
Akron | 1b0c265 | 2017-04-27 15:28:49 +0200 | [diff] [blame] | 68 | |
Akron | 3fe9fc3 | 2018-03-20 13:12:31 +0100 | [diff] [blame] | 69 | # 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 | ; |
Akron | 1b0c265 | 2017-04-27 15:28:49 +0200 | [diff] [blame] | 74 | |
Akron | 8eef346 | 2018-09-20 16:45:10 +0200 | [diff] [blame] | 75 | }; |
| 76 | |
Akron | f44a0a2 | 2018-07-05 11:19:49 +0200 | [diff] [blame] | 77 | |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 78 | |
| 79 | |
Akron | f44a0a2 | 2018-07-05 11:19:49 +0200 | [diff] [blame] | 80 | # 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.') |
Akron | 8eef346 | 2018-09-20 16:45:10 +0200 | [diff] [blame] | 84 | ->content_like(qr!KorAP\.koralQuery =!) |
Akron | f44a0a2 | 2018-07-05 11:19:49 +0200 | [diff] [blame] | 85 | ; |
| 86 | |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 87 | done_testing; |
| 88 | __END__ |