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 | ##################### |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 10 | my $mount_point = '/realapi/'; |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 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 |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 17 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server'); |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 18 | my $fake_backend = $t->app->plugin( |
| 19 | Mount => { |
| 20 | $mount_point => |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 21 | $fixtures_path->child('mock.pl') |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 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 | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 28 | $t->get_ok('/?q=baum') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 29 | ->status_is(200) |
| 30 | ->text_is('#error','') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 31 | |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 32 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 33 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 34 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 35 | |
| 36 | # Total results |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 37 | ->text_is('#total-results', 51) |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 38 | |
| 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 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 46 | # No cutOff |
| 47 | ->content_unlike(qr!\"cutOff":true!) |
| 48 | |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 49 | ->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]') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 72 | ->header_isnt('X-Kalamar-Cache', 'true') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 73 | ; |
| 74 | |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 75 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 76 | $t->get_ok('/?q=[orth=das') |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 77 | ->status_is(400) |
| 78 | ->text_is('div.notify-error:nth-of-type(1)', '302: Parantheses/brackets unbalanced.') |
Akron | bc33beb | 2018-11-30 13:46:08 +0100 | [diff] [blame] | 79 | ->element_exists('#search') |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 80 | ->text_like('div.notify-error:nth-of-type(2)', qr!302: Could not parse query .+? \[orth=das.+?!) |
| 81 | ; |
| 82 | |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 83 | # Check for query error with ql (from remote.t) |
| 84 | $t->get_ok('/?q=[orth=das&ql=poliqarp') |
| 85 | ->element_exists('.notify-error') |
| 86 | ->text_is('.notify-error', '302: Parantheses/brackets unbalanced.') |
| 87 | ->content_like(qr!KorAP\.koralQuery =!) |
| 88 | ->text_is('.no-results:nth-of-type(1)', 'Unable to perform the search.') |
| 89 | ; |
| 90 | |
| 91 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 92 | # Query with partial cache (for total results) |
| 93 | $t->get_ok('/?q=baum') |
| 94 | ->status_is(200) |
| 95 | ->text_is('#error','') |
| 96 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 97 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 98 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 99 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 100 | ->content_like(qr!\"cutOff":true!) |
| 101 | ->text_is('#total-results', 51) |
| 102 | ; |
| 103 | |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 104 | # Query without partial cache (unfortunately) (but no total results) |
| 105 | $t->get_ok('/?q=baum&cutoff=true') |
| 106 | ->status_is(200) |
| 107 | ->text_is('#error','') |
| 108 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 109 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 110 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 111 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 112 | ->content_like(qr!\"cutOff":true!) |
| 113 | ->element_exists_not('#total-results') |
| 114 | ; |
| 115 | |
| 116 | # Query with partial cache (but no total results) |
| 117 | $t->get_ok('/?q=baum&cutoff=true') |
| 118 | ->status_is(200) |
| 119 | ->text_is('#error','') |
| 120 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 121 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 122 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 123 | ->header_is('X-Kalamar-Cache', 'true') |
| 124 | ->content_like(qr!\"cutOff":true!) |
| 125 | ->element_exists_not('#total-results') |
| 126 | ; |
| 127 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 128 | # Query with full cache |
| 129 | $t->get_ok('/?q=baum') |
| 130 | ->status_is(200) |
| 131 | ->text_is('#error','') |
| 132 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 133 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 134 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 135 | ->header_is('X-Kalamar-Cache', 'true') |
| 136 | ->content_like(qr!\"cutOff":true!) |
| 137 | ->text_is('#total-results', 51) |
| 138 | ; |
| 139 | |
| 140 | |
| 141 | # Query with page information |
| 142 | $t->get_ok('/?q=der&p=1&count=2') |
| 143 | ->status_is(200) |
| 144 | ->text_is('#error','') |
| 145 | ->text_is('title', 'KorAP: Find »der« with Poliqarp') |
| 146 | |
| 147 | # Total results |
| 148 | ->text_is('#total-results', '14,581') |
| 149 | |
| 150 | # Total pages |
| 151 | ->element_count_is('#pagination a', 7) |
| 152 | ->text_is('#pagination a:nth-of-type(6) span', 7291) |
| 153 | ->content_like(qr!\"count":2!) |
| 154 | ->content_like(qr!\"startIndex":0!) |
| 155 | ->content_like(qr!\"itemsPerPage":2!) |
| 156 | |
| 157 | # No caching |
| 158 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 159 | |
| 160 | # Not searched for "der" before |
| 161 | ->content_unlike(qr!\"cutOff":true!) |
| 162 | ; |
| 163 | |
| 164 | # Query with page information - next page |
| 165 | $t->get_ok('/?q=der&p=2&count=2') |
| 166 | ->status_is(200) |
| 167 | ->text_is('#error','') |
| 168 | ->text_is('title', 'KorAP: Find »der« with Poliqarp') |
Akron | bc33beb | 2018-11-30 13:46:08 +0100 | [diff] [blame] | 169 | ->element_exists('#search') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 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 | |
Akron | c4be819 | 2018-10-25 16:07:53 +0200 | [diff] [blame] | 186 | # 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') |
Akron | bc33beb | 2018-11-30 13:46:08 +0100 | [diff] [blame] | 190 | ->element_exists('#search') |
Akron | c4be819 | 2018-10-25 16:07:53 +0200 | [diff] [blame] | 191 | ->element_count_is('noscript div.notify-error', 1) |
| 192 | ; |
| 193 | $t->get_ok('/?q=fantastisch&cutoff=no') |
| 194 | ->status_is(400) |
| 195 | ->text_is('noscript div.notify-error', 'Parameter "cutoff" invalid') |
| 196 | ->element_count_is('noscript div.notify-error', 1) |
| 197 | ; |
| 198 | $t->get_ok('/?q=fantastisch&p=hui&o=hui&count=-8') |
| 199 | ->status_is(400) |
| 200 | ->text_like('noscript div.notify-error', qr!Parameter ".+?" invalid!) |
| 201 | ->element_count_is('noscript div.notify-error', 3) |
| 202 | ; |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 203 | |
Akron | d1ff8d8 | 2018-11-08 13:16:55 +0100 | [diff] [blame] | 204 | # Query too long |
| 205 | my $long_query = 'b' x 2000; |
| 206 | $t->get_ok('/?q=' . $long_query) |
| 207 | ->status_is(400) |
| 208 | ->text_is('#error','') |
| 209 | ->text_like('noscript div.notify-error', qr!Parameter ".+?" invalid!) |
| 210 | ; |
| 211 | |
Akron | a3c353c | 2019-02-14 23:50:00 +0100 | [diff] [blame] | 212 | # Query with timeout |
| 213 | $t->get_ok('/?q=timeout') |
| 214 | ->status_is(200) |
| 215 | ->text_like('noscript div.notify-warn', qr!Response time exceeded!) |
| 216 | ->text_is('#total-results', '> 4,274,841'); |
| 217 | ; |
| 218 | |
| 219 | # Do not cache |
| 220 | $t->get_ok('/?q=timeout') |
| 221 | ->status_is(200) |
| 222 | # ->text_like('noscript div.notify-warning', qr!Response time exceeded!) |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame^] | 223 | ->element_exists("input#cq") |
| 224 | ->element_exists_not("input#cq[value]") |
Akron | a3c353c | 2019-02-14 23:50:00 +0100 | [diff] [blame] | 225 | ->text_is('#total-results', '> 4,274,841'); |
| 226 | ; |
| 227 | |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame^] | 228 | # Query with collection |
| 229 | $t->get_ok('/?q=baum&collection=availability+%3D+%2FCC-BY.*%2F') |
| 230 | ->status_is(200) |
| 231 | ->element_exists("input#cq[value='availability = /CC-BY.*/']") |
| 232 | ->text_is('#error','') |
| 233 | ; |
| 234 | |
| 235 | # Query with corpus query |
| 236 | $t->get_ok('/?q=baum&cq=availability+%3D+%2FCC-BY.*%2F') |
| 237 | ->status_is(200) |
| 238 | ->element_exists("input#cq[value='availability = /CC-BY.*/']") |
| 239 | ->text_is('#error','') |
| 240 | ; |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 241 | |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 242 | done_testing; |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 243 | __END__ |