Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use Test::Mojo; |
| 3 | use Test::More; |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 4 | use Mojo::File qw/path/; |
| 5 | |
| 6 | |
| 7 | ##################### |
| 8 | # Start Fake server # |
| 9 | ##################### |
| 10 | my $mount_point = '/api/'; |
| 11 | $ENV{KALAMAR_API} = $mount_point; |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 12 | |
| 13 | my $t = Test::Mojo->new('Kalamar'); |
| 14 | |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 15 | # Mount fake backend |
| 16 | # Get the fixture path |
| 17 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'fixtures'); |
| 18 | my $fake_backend = $t->app->plugin( |
| 19 | Mount => { |
| 20 | $mount_point => |
| 21 | $fixtures_path->child('fake_backend.pl') |
| 22 | } |
| 23 | ); |
| 24 | # Configure fake backend |
| 25 | $fake_backend->pattern->defaults->{app}->log($t->app->log); |
| 26 | |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 27 | # Query passed |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 28 | $t->get_ok('/q2?q=baum') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 29 | ->status_is(200) |
| 30 | ->text_is('#error','') |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 31 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 32 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 33 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 34 | |
| 35 | # Total results |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 36 | ->text_is('#total-results', 51) |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 37 | |
| 38 | # Total pages |
| 39 | ->element_count_is('#pagination a', 5) |
| 40 | |
| 41 | # api_response |
| 42 | ->content_like(qr/\"authorized\":null/) |
| 43 | ->content_like(qr/\"pubDate\",\"subTitle\",\"author\"/) |
| 44 | |
| 45 | ->element_exists('li[data-text-sigle=GOE/AGI/00000]') |
| 46 | ->element_exists('li:nth-of-type(1) div.flop') |
| 47 | ->element_exists('li[data-text-sigle=GOE/AGI/00001]') |
| 48 | ->element_exists('li:nth-of-type(2) div.flip') |
| 49 | |
| 50 | # Match1 |
| 51 | ->element_exists('li:nth-of-type(1)' . |
| 52 | '[data-match-id="p2030-2031"]' . |
| 53 | '[data-text-sigle="GOE/AGI/00000"]' . |
| 54 | '[id="GOE/AGI/00000#p2030-2031"]' . |
| 55 | '[data-available-info^="base/s=spans"]' . |
| 56 | '[data-info^="{"]') |
| 57 | ->text_is('li:nth-of-type(1) div.meta', 'GOE/AGI/00000') |
| 58 | ->element_exists('li:nth-of-type(1) div.match-main div.match-wrap div.snippet') |
| 59 | ->element_exists('li:nth-of-type(1) div.snippet.startMore.endMore') |
| 60 | ->text_like('li:nth-of-type(1) div.snippet span.context-left',qr!sie etwas bedeuten!) |
| 61 | ->text_like('li:nth-of-type(1) div.snippet span.context-left',qr!sie etwas bedeuten!) |
| 62 | ->text_is('li:nth-of-type(1) div.snippet span.match mark','Baum') |
| 63 | ->text_like('li:nth-of-type(1) div.snippet span.context-right',qr!es war!) |
| 64 | ->text_is('li:nth-of-type(1) p.ref strong', 'Italienische Reise') |
| 65 | ->text_like('li:nth-of-type(1) p.ref', qr!by Goethe, Johann Wolfgang!) |
| 66 | ->text_is('li:nth-of-type(1) p.ref time[datetime=1982]', 1982) |
| 67 | ->text_is('li:nth-of-type(1) p.ref span.sigle', '[GOE/AGI/00000]') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 68 | ; |
| 69 | |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 70 | |
| 71 | $t->get_ok('/q2?q=[orth=das') |
| 72 | ->status_is(400) |
| 73 | ->text_is('div.notify-error:nth-of-type(1)', '302: Parantheses/brackets unbalanced.') |
| 74 | ->text_like('div.notify-error:nth-of-type(2)', qr!302: Could not parse query .+? \[orth=das.+?!) |
| 75 | ; |
| 76 | |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 77 | done_testing; |