blob: 215061a68a2f9721de97a147e29e08afe989a0eb [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
Akron73f36082018-10-25 15:34:59 +020017my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server');
Akron32396632018-10-11 17:08:37 +020018my $fake_backend = $t->app->plugin(
19 Mount => {
20 $mount_point =>
Akron73f36082018-10-25 15:34:59 +020021 $fixtures_path->child('mock.pl')
Akron32396632018-10-11 17:08:37 +020022 }
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
Akron8ea84292018-10-24 13:41:52 +020028$t->get_ok('/?q=baum')
Akron0e1ed242018-10-11 13:22:00 +020029 ->status_is(200)
30 ->text_is('#error','')
Akron8ea84292018-10-24 13:41:52 +020031
Akron32396632018-10-11 17:08:37 +020032 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
33 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
Akron0e1ed242018-10-11 13:22:00 +020034 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
Akrondffa9392018-10-12 16:26:09 +020035
36 # Total results
Akron32396632018-10-11 17:08:37 +020037 ->text_is('#total-results', 51)
Akrondffa9392018-10-12 16:26:09 +020038
39 # Total pages
40 ->element_count_is('#pagination a', 5)
41
42 # api_response
43 ->content_like(qr/\"authorized\":null/)
44 ->content_like(qr/\"pubDate\",\"subTitle\",\"author\"/)
45
Akron8ea84292018-10-24 13:41:52 +020046 # No cutOff
47 ->content_unlike(qr!\"cutOff":true!)
48
Akrondffa9392018-10-12 16:26:09 +020049 ->element_exists('li[data-text-sigle=GOE/AGI/00000]')
50 ->element_exists('li:nth-of-type(1) div.flop')
51 ->element_exists('li[data-text-sigle=GOE/AGI/00001]')
52 ->element_exists('li:nth-of-type(2) div.flip')
53
54 # Match1
55 ->element_exists('li:nth-of-type(1)' .
56 '[data-match-id="p2030-2031"]' .
57 '[data-text-sigle="GOE/AGI/00000"]' .
58 '[id="GOE/AGI/00000#p2030-2031"]' .
59 '[data-available-info^="base/s=spans"]' .
60 '[data-info^="{"]')
61 ->text_is('li:nth-of-type(1) div.meta', 'GOE/AGI/00000')
62 ->element_exists('li:nth-of-type(1) div.match-main div.match-wrap div.snippet')
63 ->element_exists('li:nth-of-type(1) div.snippet.startMore.endMore')
64 ->text_like('li:nth-of-type(1) div.snippet span.context-left',qr!sie etwas bedeuten!)
65 ->text_like('li:nth-of-type(1) div.snippet span.context-left',qr!sie etwas bedeuten!)
66 ->text_is('li:nth-of-type(1) div.snippet span.match mark','Baum')
67 ->text_like('li:nth-of-type(1) div.snippet span.context-right',qr!es war!)
68 ->text_is('li:nth-of-type(1) p.ref strong', 'Italienische Reise')
69 ->text_like('li:nth-of-type(1) p.ref', qr!by Goethe, Johann Wolfgang!)
70 ->text_is('li:nth-of-type(1) p.ref time[datetime=1982]', 1982)
71 ->text_is('li:nth-of-type(1) p.ref span.sigle', '[GOE/AGI/00000]')
Akron8ea84292018-10-24 13:41:52 +020072 ->header_isnt('X-Kalamar-Cache', 'true')
Akron0e1ed242018-10-11 13:22:00 +020073 ;
74
Akron7093b812018-10-19 17:28:21 +020075
Akron8ea84292018-10-24 13:41:52 +020076$t->get_ok('/?q=[orth=das')
Akron7093b812018-10-19 17:28:21 +020077 ->status_is(400)
78 ->text_is('div.notify-error:nth-of-type(1)', '302: Parantheses/brackets unbalanced.')
79 ->text_like('div.notify-error:nth-of-type(2)', qr!302: Could not parse query .+? \[orth=das.+?!)
80 ;
81
Akron73f36082018-10-25 15:34:59 +020082# Check for query error with ql (from remote.t)
83$t->get_ok('/?q=[orth=das&ql=poliqarp')
84 ->element_exists('.notify-error')
85 ->text_is('.notify-error', '302: Parantheses/brackets unbalanced.')
86 ->content_like(qr!KorAP\.koralQuery =!)
87 ->text_is('.no-results:nth-of-type(1)', 'Unable to perform the search.')
88 ;
89
90
Akron8ea84292018-10-24 13:41:52 +020091# Query with partial cache (for total results)
92$t->get_ok('/?q=baum')
93 ->status_is(200)
94 ->text_is('#error','')
95 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
96 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
97 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
98 ->header_isnt('X-Kalamar-Cache', 'true')
99 ->content_like(qr!\"cutOff":true!)
100 ->text_is('#total-results', 51)
101 ;
102
Akron385249d2018-10-29 12:26:29 +0100103# Query without partial cache (unfortunately) (but no total results)
104$t->get_ok('/?q=baum&cutoff=true')
105 ->status_is(200)
106 ->text_is('#error','')
107 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
108 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
109 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
110 ->header_isnt('X-Kalamar-Cache', 'true')
111 ->content_like(qr!\"cutOff":true!)
112 ->element_exists_not('#total-results')
113 ;
114
115# Query with partial cache (but no total results)
116$t->get_ok('/?q=baum&cutoff=true')
117 ->status_is(200)
118 ->text_is('#error','')
119 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
120 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
121 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
122 ->header_is('X-Kalamar-Cache', 'true')
123 ->content_like(qr!\"cutOff":true!)
124 ->element_exists_not('#total-results')
125 ;
126
Akron8ea84292018-10-24 13:41:52 +0200127# Query with full cache
128$t->get_ok('/?q=baum')
129 ->status_is(200)
130 ->text_is('#error','')
131 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
132 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
133 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
134 ->header_is('X-Kalamar-Cache', 'true')
135 ->content_like(qr!\"cutOff":true!)
136 ->text_is('#total-results', 51)
137 ;
138
139
140# Query with page information
141$t->get_ok('/?q=der&p=1&count=2')
142 ->status_is(200)
143 ->text_is('#error','')
144 ->text_is('title', 'KorAP: Find »der« with Poliqarp')
145
146 # Total results
147 ->text_is('#total-results', '14,581')
148
149 # Total pages
150 ->element_count_is('#pagination a', 7)
151 ->text_is('#pagination a:nth-of-type(6) span', 7291)
152 ->content_like(qr!\"count":2!)
153 ->content_like(qr!\"startIndex":0!)
154 ->content_like(qr!\"itemsPerPage":2!)
155
156 # No caching
157 ->header_isnt('X-Kalamar-Cache', 'true')
158
159 # Not searched for "der" before
160 ->content_unlike(qr!\"cutOff":true!)
161 ;
162
163# Query with page information - next page
164$t->get_ok('/?q=der&p=2&count=2')
165 ->status_is(200)
166 ->text_is('#error','')
167 ->text_is('title', 'KorAP: Find »der« with Poliqarp')
168
169 # Total results
170 ->text_is('#total-results', '14,581')
171
172 # Total pages
173 ->element_count_is('#pagination a', 7)
174 ->text_is('#pagination a:nth-of-type(6) span', 7291)
175 ->content_like(qr!\"count":2!)
176 ->content_like(qr!\"itemsPerPage":2!)
177 ->content_like(qr!\"startIndex":2!)
178
179 # No caching
180 ->header_isnt('X-Kalamar-Cache', 'true')
181 ->content_like(qr!\"cutOff":true!)
182 ;
183
Akronc4be8192018-10-25 16:07:53 +0200184# Query with failing parameters
185$t->get_ok('/?q=fantastisch&ql=Fabelsprache')
186 ->status_is(400)
187 ->text_is('noscript div.notify-error', 'Parameter "ql" invalid')
188 ->element_count_is('noscript div.notify-error', 1)
189 ;
190$t->get_ok('/?q=fantastisch&cutoff=no')
191 ->status_is(400)
192 ->text_is('noscript div.notify-error', 'Parameter "cutoff" invalid')
193 ->element_count_is('noscript div.notify-error', 1)
194 ;
195$t->get_ok('/?q=fantastisch&p=hui&o=hui&count=-8')
196 ->status_is(400)
197 ->text_like('noscript div.notify-error', qr!Parameter ".+?" invalid!)
198 ->element_count_is('noscript div.notify-error', 3)
199 ;
Akron8ea84292018-10-24 13:41:52 +0200200
201
Akron0e1ed242018-10-11 13:22:00 +0200202done_testing;
Akron8ea84292018-10-24 13:41:52 +0200203__END__