blob: e7f4fc6ec3e731897330e29ccdb3012733552065 [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
Akrond1ff8d82018-11-08 13:16:55 +010027if (0) {
28
Akron0e1ed242018-10-11 13:22:00 +020029# Query passed
Akron8ea84292018-10-24 13:41:52 +020030$t->get_ok('/?q=baum')
Akron0e1ed242018-10-11 13:22:00 +020031 ->status_is(200)
32 ->text_is('#error','')
Akron8ea84292018-10-24 13:41:52 +020033
Akron32396632018-10-11 17:08:37 +020034 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
35 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
Akron0e1ed242018-10-11 13:22:00 +020036 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
Akrondffa9392018-10-12 16:26:09 +020037
38 # Total results
Akron32396632018-10-11 17:08:37 +020039 ->text_is('#total-results', 51)
Akrondffa9392018-10-12 16:26:09 +020040
41 # Total pages
42 ->element_count_is('#pagination a', 5)
43
44 # api_response
45 ->content_like(qr/\"authorized\":null/)
46 ->content_like(qr/\"pubDate\",\"subTitle\",\"author\"/)
47
Akron8ea84292018-10-24 13:41:52 +020048 # No cutOff
49 ->content_unlike(qr!\"cutOff":true!)
50
Akrondffa9392018-10-12 16:26:09 +020051 ->element_exists('li[data-text-sigle=GOE/AGI/00000]')
52 ->element_exists('li:nth-of-type(1) div.flop')
53 ->element_exists('li[data-text-sigle=GOE/AGI/00001]')
54 ->element_exists('li:nth-of-type(2) div.flip')
55
56 # Match1
57 ->element_exists('li:nth-of-type(1)' .
58 '[data-match-id="p2030-2031"]' .
59 '[data-text-sigle="GOE/AGI/00000"]' .
60 '[id="GOE/AGI/00000#p2030-2031"]' .
61 '[data-available-info^="base/s=spans"]' .
62 '[data-info^="{"]')
63 ->text_is('li:nth-of-type(1) div.meta', 'GOE/AGI/00000')
64 ->element_exists('li:nth-of-type(1) div.match-main div.match-wrap div.snippet')
65 ->element_exists('li:nth-of-type(1) div.snippet.startMore.endMore')
66 ->text_like('li:nth-of-type(1) div.snippet span.context-left',qr!sie etwas bedeuten!)
67 ->text_like('li:nth-of-type(1) div.snippet span.context-left',qr!sie etwas bedeuten!)
68 ->text_is('li:nth-of-type(1) div.snippet span.match mark','Baum')
69 ->text_like('li:nth-of-type(1) div.snippet span.context-right',qr!es war!)
70 ->text_is('li:nth-of-type(1) p.ref strong', 'Italienische Reise')
71 ->text_like('li:nth-of-type(1) p.ref', qr!by Goethe, Johann Wolfgang!)
72 ->text_is('li:nth-of-type(1) p.ref time[datetime=1982]', 1982)
73 ->text_is('li:nth-of-type(1) p.ref span.sigle', '[GOE/AGI/00000]')
Akron8ea84292018-10-24 13:41:52 +020074 ->header_isnt('X-Kalamar-Cache', 'true')
Akron0e1ed242018-10-11 13:22:00 +020075 ;
76
Akron7093b812018-10-19 17:28:21 +020077
Akron8ea84292018-10-24 13:41:52 +020078$t->get_ok('/?q=[orth=das')
Akron7093b812018-10-19 17:28:21 +020079 ->status_is(400)
80 ->text_is('div.notify-error:nth-of-type(1)', '302: Parantheses/brackets unbalanced.')
81 ->text_like('div.notify-error:nth-of-type(2)', qr!302: Could not parse query .+? \[orth=das.+?!)
82 ;
83
Akron73f36082018-10-25 15:34:59 +020084# Check for query error with ql (from remote.t)
85$t->get_ok('/?q=[orth=das&ql=poliqarp')
86 ->element_exists('.notify-error')
87 ->text_is('.notify-error', '302: Parantheses/brackets unbalanced.')
88 ->content_like(qr!KorAP\.koralQuery =!)
89 ->text_is('.no-results:nth-of-type(1)', 'Unable to perform the search.')
90 ;
91
92
Akron8ea84292018-10-24 13:41:52 +020093# Query with partial cache (for total results)
94$t->get_ok('/?q=baum')
95 ->status_is(200)
96 ->text_is('#error','')
97 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
98 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
99 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
100 ->header_isnt('X-Kalamar-Cache', 'true')
101 ->content_like(qr!\"cutOff":true!)
102 ->text_is('#total-results', 51)
103 ;
104
Akron385249d2018-10-29 12:26:29 +0100105# Query without partial cache (unfortunately) (but no total results)
106$t->get_ok('/?q=baum&cutoff=true')
107 ->status_is(200)
108 ->text_is('#error','')
109 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
110 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
111 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
112 ->header_isnt('X-Kalamar-Cache', 'true')
113 ->content_like(qr!\"cutOff":true!)
114 ->element_exists_not('#total-results')
115 ;
116
117# Query with partial cache (but no total results)
118$t->get_ok('/?q=baum&cutoff=true')
119 ->status_is(200)
120 ->text_is('#error','')
121 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
122 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
123 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
124 ->header_is('X-Kalamar-Cache', 'true')
125 ->content_like(qr!\"cutOff":true!)
126 ->element_exists_not('#total-results')
127 ;
128
Akron8ea84292018-10-24 13:41:52 +0200129# Query with full cache
130$t->get_ok('/?q=baum')
131 ->status_is(200)
132 ->text_is('#error','')
133 ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
134 ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
135 ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
136 ->header_is('X-Kalamar-Cache', 'true')
137 ->content_like(qr!\"cutOff":true!)
138 ->text_is('#total-results', 51)
139 ;
140
141
142# Query with page information
143$t->get_ok('/?q=der&p=1&count=2')
144 ->status_is(200)
145 ->text_is('#error','')
146 ->text_is('title', 'KorAP: Find »der« with Poliqarp')
147
148 # Total results
149 ->text_is('#total-results', '14,581')
150
151 # Total pages
152 ->element_count_is('#pagination a', 7)
153 ->text_is('#pagination a:nth-of-type(6) span', 7291)
154 ->content_like(qr!\"count":2!)
155 ->content_like(qr!\"startIndex":0!)
156 ->content_like(qr!\"itemsPerPage":2!)
157
158 # No caching
159 ->header_isnt('X-Kalamar-Cache', 'true')
160
161 # Not searched for "der" before
162 ->content_unlike(qr!\"cutOff":true!)
163 ;
164
165# Query with page information - next page
166$t->get_ok('/?q=der&p=2&count=2')
167 ->status_is(200)
168 ->text_is('#error','')
169 ->text_is('title', 'KorAP: Find »der« with Poliqarp')
170
171 # Total results
172 ->text_is('#total-results', '14,581')
173
174 # Total pages
175 ->element_count_is('#pagination a', 7)
176 ->text_is('#pagination a:nth-of-type(6) span', 7291)
177 ->content_like(qr!\"count":2!)
178 ->content_like(qr!\"itemsPerPage":2!)
179 ->content_like(qr!\"startIndex":2!)
180
181 # No caching
182 ->header_isnt('X-Kalamar-Cache', 'true')
183 ->content_like(qr!\"cutOff":true!)
184 ;
185
Akronc4be8192018-10-25 16:07:53 +0200186# Query with failing parameters
187$t->get_ok('/?q=fantastisch&ql=Fabelsprache')
188 ->status_is(400)
189 ->text_is('noscript div.notify-error', 'Parameter "ql" invalid')
190 ->element_count_is('noscript div.notify-error', 1)
191 ;
192$t->get_ok('/?q=fantastisch&cutoff=no')
193 ->status_is(400)
194 ->text_is('noscript div.notify-error', 'Parameter "cutoff" invalid')
195 ->element_count_is('noscript div.notify-error', 1)
196 ;
197$t->get_ok('/?q=fantastisch&p=hui&o=hui&count=-8')
198 ->status_is(400)
199 ->text_like('noscript div.notify-error', qr!Parameter ".+?" invalid!)
200 ->element_count_is('noscript div.notify-error', 3)
201 ;
Akron8ea84292018-10-24 13:41:52 +0200202
Akrond1ff8d82018-11-08 13:16:55 +0100203};
204
205# Query too long
206my $long_query = 'b' x 2000;
207$t->get_ok('/?q=' . $long_query)
208 ->status_is(400)
209 ->text_is('#error','')
210 ->text_like('noscript div.notify-error', qr!Parameter ".+?" invalid!)
211 ;
212
Akron8ea84292018-10-24 13:41:52 +0200213
Akron0e1ed242018-10-11 13:22:00 +0200214done_testing;
Akron8ea84292018-10-24 13:41:52 +0200215__END__