blob: 4bc97dc090ee066a0c0a5132ad4d3a0454c32180 [file] [log] [blame]
Akron0e1ed242018-10-11 13:22:00 +02001use Mojo::Base -strict;
2use Test::Mojo;
3use Test::More;
Akron32396632018-10-11 17:08:37 +02004use Mojo::File qw/path/;
5
6
7#####################
8# Start Fake server #
9#####################
10my $mount_point = '/api/';
11$ENV{KALAMAR_API} = $mount_point;
Akron0e1ed242018-10-11 13:22:00 +020012
13my $t = Test::Mojo->new('Kalamar');
14
Akron32396632018-10-11 17:08:37 +020015# Mount fake backend
16# Get the fixture path
17my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'fixtures');
18my $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
Akron0e1ed242018-10-11 13:22:00 +020027# Query passed
Akron32396632018-10-11 17:08:37 +020028$t->get_ok('/q2?q=baum')
Akron0e1ed242018-10-11 13:22:00 +020029 ->status_is(200)
30 ->text_is('#error','')
Akron32396632018-10-11 17:08:37 +020031 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
32 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
Akron0e1ed242018-10-11 13:22:00 +020033 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
Akrondffa9392018-10-12 16:26:09 +020034
35 # Total results
Akron32396632018-10-11 17:08:37 +020036 ->text_is('#total-results', 51)
Akrondffa9392018-10-12 16:26:09 +020037
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]')
Akron0e1ed242018-10-11 13:22:00 +020068 ;
69
Akron7093b812018-10-19 17:28:21 +020070
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
Akron0e1ed242018-10-11 13:22:00 +020077done_testing;