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/; |
Akron | 909ed08 | 2019-12-11 21:38:27 +0100 | [diff] [blame] | 5 | use Kalamar::Controller::Search; |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 6 | |
| 7 | |
| 8 | ##################### |
| 9 | # Start Fake server # |
| 10 | ##################### |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 11 | my $mount_point = '/realapi/'; |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 12 | $ENV{KALAMAR_API} = $mount_point; |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 13 | |
Akron | c417749 | 2023-11-29 08:35:37 +0100 | [diff] [blame] | 14 | my $t = Test::Mojo->new('Kalamar' => { |
| 15 | Localize => { |
| 16 | dict => { |
| 17 | title_addon => 'Test' |
| 18 | } |
| 19 | } |
| 20 | }); |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 21 | |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 22 | # Mount fake backend |
| 23 | # Get the fixture path |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 24 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server'); |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 25 | my $fake_backend = $t->app->plugin( |
| 26 | Mount => { |
| 27 | $mount_point => |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 28 | $fixtures_path->child('mock.pl') |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 29 | } |
| 30 | ); |
| 31 | # Configure fake backend |
| 32 | $fake_backend->pattern->defaults->{app}->log($t->app->log); |
| 33 | |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 34 | my $q = qr!(?:\"|")!; |
| 35 | |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 36 | # Query passed |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 37 | my $err = $t->get_ok('/?q=baum') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 38 | ->status_is(200) |
Akron | 69481a4 | 2021-03-22 10:31:16 +0100 | [diff] [blame] | 39 | ->content_type_is('text/html;charset=UTF-8') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 40 | |
Akron | c417749 | 2023-11-29 08:35:37 +0100 | [diff] [blame] | 41 | ->text_is('title', 'KorAP-Test: Find »baum« with Poliqarp') |
| 42 | ->element_exists('meta[name="DC.title"][content="KorAP-Test: Find »baum« with Poliqarp"]') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 43 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 44 | |
| 45 | # Total results |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 46 | ->text_is('#total-results', 51) |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 47 | |
| 48 | # Total pages |
Akron | 18a2a27 | 2020-06-16 11:47:38 +0200 | [diff] [blame] | 49 | ->element_count_is('#pagination > a', 5) |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 50 | |
Akron | 9bd140e | 2021-07-27 16:20:03 +0200 | [diff] [blame] | 51 | ->element_exists_not('#resultinfo > #pagination') |
| 52 | |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 53 | # api_response |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 54 | ->content_like(qr/${q}authorized${q}:null/) |
| 55 | ->content_like(qr/${q}pubDate${q},${q}subTitle${q},${q}author${q}/) |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 56 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 57 | # No cutOff |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 58 | ->content_unlike(qr!${q}cutOff${q}:true!) |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 59 | |
Akron | dffa939 | 2018-10-12 16:26:09 +0200 | [diff] [blame] | 60 | ->element_exists('li[data-text-sigle=GOE/AGI/00000]') |
| 61 | ->element_exists('li:nth-of-type(1) div.flop') |
| 62 | ->element_exists('li[data-text-sigle=GOE/AGI/00001]') |
| 63 | ->element_exists('li:nth-of-type(2) div.flip') |
| 64 | |
| 65 | # Match1 |
| 66 | ->element_exists('li:nth-of-type(1)' . |
| 67 | '[data-match-id="p2030-2031"]' . |
| 68 | '[data-text-sigle="GOE/AGI/00000"]' . |
| 69 | '[id="GOE/AGI/00000#p2030-2031"]' . |
| 70 | '[data-available-info^="base/s=spans"]' . |
| 71 | '[data-info^="{"]') |
| 72 | ->text_is('li:nth-of-type(1) div.meta', 'GOE/AGI/00000') |
| 73 | ->element_exists('li:nth-of-type(1) div.match-main div.match-wrap div.snippet') |
| 74 | ->element_exists('li:nth-of-type(1) div.snippet.startMore.endMore') |
| 75 | ->text_like('li:nth-of-type(1) div.snippet span.context-left',qr!sie etwas bedeuten!) |
| 76 | ->text_like('li:nth-of-type(1) div.snippet span.context-left',qr!sie etwas bedeuten!) |
| 77 | ->text_is('li:nth-of-type(1) div.snippet span.match mark','Baum') |
| 78 | ->text_like('li:nth-of-type(1) div.snippet span.context-right',qr!es war!) |
| 79 | ->text_is('li:nth-of-type(1) p.ref strong', 'Italienische Reise') |
| 80 | ->text_like('li:nth-of-type(1) p.ref', qr!by Goethe, Johann Wolfgang!) |
| 81 | ->text_is('li:nth-of-type(1) p.ref time[datetime=1982]', 1982) |
| 82 | ->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] | 83 | ->header_isnt('X-Kalamar-Cache', 'true') |
Akron | 26d57f2 | 2021-09-10 16:48:57 +0200 | [diff] [blame] | 84 | ->attr_is('#pagination','data-page','1') |
| 85 | ->attr_is('#pagination','data-total','3') |
| 86 | ->attr_is('#pagination','data-count','25') |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 87 | ->tx->res->dom->at('#error') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 88 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 89 | is(defined $err ? $err->text : '', ''); |
| 90 | |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 91 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 92 | $t->get_ok('/?q=[orth=das') |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 93 | ->status_is(400) |
| 94 | ->text_is('div.notify-error:nth-of-type(1)', '302: Parantheses/brackets unbalanced.') |
Akron | bc33beb | 2018-11-30 13:46:08 +0100 | [diff] [blame] | 95 | ->element_exists('#search') |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 96 | ->text_like('div.notify-error:nth-of-type(2)', qr!302: Could not parse query .+? \[orth=das.+?!) |
| 97 | ; |
| 98 | |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 99 | # Check for query error with ql (from remote.t) |
| 100 | $t->get_ok('/?q=[orth=das&ql=poliqarp') |
| 101 | ->element_exists('.notify-error') |
| 102 | ->text_is('.notify-error', '302: Parantheses/brackets unbalanced.') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 103 | ->content_like(qr!data-koralquery=!) |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 104 | ->text_is('.no-results:nth-of-type(1)', 'Unable to perform the action.') |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 105 | ; |
| 106 | |
| 107 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 108 | # Query with partial cache (for total results) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 109 | $err = $t->get_ok('/?q=baum') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 110 | ->status_is(200) |
Akron | c417749 | 2023-11-29 08:35:37 +0100 | [diff] [blame] | 111 | ->text_is('title', 'KorAP-Test: Find »baum« with Poliqarp') |
| 112 | ->element_exists('meta[name="DC.title"][content="KorAP-Test: Find »baum« with Poliqarp"]') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 113 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 114 | ->header_isnt('X-Kalamar-Cache', 'true') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 115 | ->content_like(qr!${q}cutOff${q}:true!) |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 116 | ->text_is('#total-results', 51) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 117 | ->tx->res->dom->at('#error') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 118 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 119 | is(defined $err ? $err->text : '', ''); |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 120 | |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 121 | # Query without partial cache (unfortunately) (but no total results) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 122 | $err = $t->get_ok('/?q=baum&cutoff=true') |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 123 | ->status_is(200) |
Akron | c417749 | 2023-11-29 08:35:37 +0100 | [diff] [blame] | 124 | ->text_is('title', 'KorAP-Test: Find »baum« with Poliqarp') |
| 125 | ->element_exists('meta[name="DC.title"][content="KorAP-Test: Find »baum« with Poliqarp"]') |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 126 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 127 | ->header_isnt('X-Kalamar-Cache', 'true') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 128 | ->content_like(qr!${q}cutOff${q}:true!) |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 129 | ->element_exists_not('#total-results') |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 130 | ->tx->res->dom->at('#error') |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 131 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 132 | is(defined $err ? $err->text : '', ''); |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 133 | |
| 134 | # Query with partial cache (but no total results) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 135 | $err = $t->get_ok('/?q=baum&cutoff=true') |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 136 | ->status_is(200) |
Akron | c417749 | 2023-11-29 08:35:37 +0100 | [diff] [blame] | 137 | ->text_is('title', 'KorAP-Test: Find »baum« with Poliqarp') |
| 138 | ->element_exists('meta[name="DC.title"][content="KorAP-Test: Find »baum« with Poliqarp"]') |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 139 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 140 | ->header_is('X-Kalamar-Cache', 'true') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 141 | ->content_like(qr!${q}cutOff${q}:true!) |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 142 | ->element_exists_not('#total-results') |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 143 | ->tx->res->dom->at('#error') |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 144 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 145 | is(defined $err ? $err->text : '', ''); |
| 146 | |
Akron | 385249d | 2018-10-29 12:26:29 +0100 | [diff] [blame] | 147 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 148 | # Query with full cache |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 149 | $err = $t->get_ok('/?q=baum') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 150 | ->status_is(200) |
Akron | c417749 | 2023-11-29 08:35:37 +0100 | [diff] [blame] | 151 | ->text_is('title', 'KorAP-Test: Find »baum« with Poliqarp') |
| 152 | ->element_exists('meta[name="DC.title"][content="KorAP-Test: Find »baum« with Poliqarp"]') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 153 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 154 | ->header_is('X-Kalamar-Cache', 'true') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 155 | ->content_like(qr!${q}cutOff${q}:true!) |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 156 | ->text_is('#total-results', 51) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 157 | ->tx->res->dom->at('#error') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 158 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 159 | is(defined $err ? $err->text : '', ''); |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 160 | |
| 161 | |
| 162 | # Query with page information |
Akron | c23ce66 | 2021-12-14 12:39:42 +0100 | [diff] [blame] | 163 | $err = $t->get_ok('/?q=der&p=1&count=2' => { 'Accept-Language' => 'en-US, en, de-DE' }) |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 164 | ->status_is(200) |
Akron | c417749 | 2023-11-29 08:35:37 +0100 | [diff] [blame] | 165 | ->text_is('title', 'KorAP-Test: Find »der« with Poliqarp') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 166 | |
| 167 | # Total results |
| 168 | ->text_is('#total-results', '14,581') |
| 169 | |
| 170 | # Total pages |
Akron | 18a2a27 | 2020-06-16 11:47:38 +0200 | [diff] [blame] | 171 | ->element_count_is('#pagination > a', 7) |
Akron | c23ce66 | 2021-12-14 12:39:42 +0100 | [diff] [blame] | 172 | ->text_is('#pagination a:nth-of-type(6) span', '7,291') |
Akron | a4b17f7 | 2021-11-04 15:37:02 +0100 | [diff] [blame] | 173 | ->element_exists('#pagination a.ellipsis.inactive') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 174 | ->content_like(qr!${q}count${q}:2!) |
| 175 | ->content_like(qr!${q}startIndex${q}:0!) |
| 176 | ->content_like(qr!${q}itemsPerPage${q}:2!) |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 177 | |
| 178 | # No caching |
| 179 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 180 | |
| 181 | # Not searched for "der" before |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 182 | ->content_unlike(qr!${q}cutOff${q}:true!) |
Akron | 26d57f2 | 2021-09-10 16:48:57 +0200 | [diff] [blame] | 183 | |
| 184 | ->attr_is('#pagination','data-page','1') |
| 185 | ->attr_is('#pagination','data-total','7291') |
| 186 | ->attr_is('#pagination','data-count','2') |
| 187 | |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 188 | ->tx->res->dom->at('#error') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 189 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 190 | is(defined $err ? $err->text : '', ''); |
| 191 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 192 | |
Akron | 4c7cf95 | 2019-08-29 09:31:35 +0200 | [diff] [blame] | 193 | # Check pagination repetion of page |
| 194 | my $next_href = $t->get_ok('/?q=der&p=1&count=2') |
| 195 | ->tx->res->dom->at('#pagination a[rel=next]')->attr('href'); |
| 196 | like($next_href, qr/p=2/); |
| 197 | unlike($next_href, qr/p=1/); |
| 198 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 199 | # Query with page information - next page |
Akron | c23ce66 | 2021-12-14 12:39:42 +0100 | [diff] [blame] | 200 | $err = $t->get_ok('/?q=der&p=2&count=2' => { 'Accept-Language' => 'de-DE, en-US, en' }) |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 201 | ->status_is(200) |
Akron | c417749 | 2023-11-29 08:35:37 +0100 | [diff] [blame] | 202 | ->text_is('div.logoaddon', 'Test') |
| 203 | ->text_is('title', 'KorAP-Test: Finde »der« mit Poliqarp') |
Akron | bc33beb | 2018-11-30 13:46:08 +0100 | [diff] [blame] | 204 | ->element_exists('#search') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 205 | |
| 206 | # Total results |
Akron | c23ce66 | 2021-12-14 12:39:42 +0100 | [diff] [blame] | 207 | ->text_is('#total-results', '14.581') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 208 | |
| 209 | # Total pages |
Akron | 18a2a27 | 2020-06-16 11:47:38 +0200 | [diff] [blame] | 210 | ->element_count_is('#pagination > a', 7) |
Akron | c23ce66 | 2021-12-14 12:39:42 +0100 | [diff] [blame] | 211 | ->text_is('#pagination a:nth-of-type(6) span', '7.291') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 212 | ->content_like(qr!${q}count${q}:2!) |
| 213 | ->content_like(qr!${q}itemsPerPage${q}:2!) |
| 214 | ->content_like(qr!${q}startIndex${q}:2!) |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 215 | |
Akron | 26d57f2 | 2021-09-10 16:48:57 +0200 | [diff] [blame] | 216 | ->attr_is('#pagination','data-page','2') |
| 217 | ->attr_is('#pagination','data-total','7291') |
| 218 | ->attr_is('#pagination','data-count','2') |
| 219 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 220 | # No caching |
| 221 | ->header_isnt('X-Kalamar-Cache', 'true') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 222 | ->content_like(qr!${q}cutOff${q}:true!) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 223 | ->tx->res->dom->at('#error') |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 224 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 225 | is(defined $err ? $err->text : '', ''); |
| 226 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 227 | |
Akron | c4be819 | 2018-10-25 16:07:53 +0200 | [diff] [blame] | 228 | # Query with failing parameters |
| 229 | $t->get_ok('/?q=fantastisch&ql=Fabelsprache') |
| 230 | ->status_is(400) |
Akron | cb5c171 | 2021-01-26 18:01:04 +0100 | [diff] [blame] | 231 | ->text_is('#notifications div.notify-error', 'Parameter "ql" invalid') |
Akron | bc33beb | 2018-11-30 13:46:08 +0100 | [diff] [blame] | 232 | ->element_exists('#search') |
Akron | cb5c171 | 2021-01-26 18:01:04 +0100 | [diff] [blame] | 233 | ->element_count_is('#notifications div.notify-error', 1) |
Akron | c4be819 | 2018-10-25 16:07:53 +0200 | [diff] [blame] | 234 | ; |
| 235 | $t->get_ok('/?q=fantastisch&cutoff=no') |
| 236 | ->status_is(400) |
Akron | cb5c171 | 2021-01-26 18:01:04 +0100 | [diff] [blame] | 237 | ->text_is('#notifications div.notify-error', 'Parameter "cutoff" invalid') |
| 238 | ->element_count_is('#notifications div.notify-error', 1) |
Akron | c4be819 | 2018-10-25 16:07:53 +0200 | [diff] [blame] | 239 | ; |
| 240 | $t->get_ok('/?q=fantastisch&p=hui&o=hui&count=-8') |
| 241 | ->status_is(400) |
Akron | cb5c171 | 2021-01-26 18:01:04 +0100 | [diff] [blame] | 242 | ->text_like('#notifications div.notify-error', qr!Parameter ".+?" invalid!) |
| 243 | ->element_count_is('#notifications div.notify-error', 3) |
Akron | c4be819 | 2018-10-25 16:07:53 +0200 | [diff] [blame] | 244 | ; |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 245 | |
Marc Kupietz | 4dc3d50 | 2022-07-06 16:50:14 +0200 | [diff] [blame] | 246 | # Long, but not too long query |
| 247 | my $long_query = 'b' x 4096; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 248 | $err = $t->get_ok('/?q=' . $long_query) |
Akron | d1ff8d8 | 2018-11-08 13:16:55 +0100 | [diff] [blame] | 249 | ->status_is(400) |
Marc Kupietz | 4dc3d50 | 2022-07-06 16:50:14 +0200 | [diff] [blame] | 250 | ->text_like('#notifications div.notify-error', qr!Unable to load query response from!) |
| 251 | ->tx->res->dom->at('#error') |
| 252 | ; |
| 253 | |
| 254 | # Query too long |
| 255 | my $too_long_query = 'b' x 4097; |
| 256 | $err = $t->get_ok('/?q=' . $too_long_query) |
| 257 | ->status_is(400) |
Akron | cb5c171 | 2021-01-26 18:01:04 +0100 | [diff] [blame] | 258 | ->text_like('#notifications div.notify-error', qr!Parameter ".+?" invalid!) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 259 | ->tx->res->dom->at('#error') |
Akron | d1ff8d8 | 2018-11-08 13:16:55 +0100 | [diff] [blame] | 260 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 261 | is(defined $err ? $err->text : '', ''); |
Akron | d1ff8d8 | 2018-11-08 13:16:55 +0100 | [diff] [blame] | 262 | |
Akron | a3c353c | 2019-02-14 23:50:00 +0100 | [diff] [blame] | 263 | # Query with timeout |
| 264 | $t->get_ok('/?q=timeout') |
| 265 | ->status_is(200) |
Akron | cb5c171 | 2021-01-26 18:01:04 +0100 | [diff] [blame] | 266 | ->text_like('#notifications div.notify-warn', qr!Response time exceeded!) |
Akron | a3c353c | 2019-02-14 23:50:00 +0100 | [diff] [blame] | 267 | ->text_is('#total-results', '> 4,274,841'); |
| 268 | ; |
| 269 | |
Akron | cce055c | 2021-07-02 12:18:03 +0200 | [diff] [blame] | 270 | # Query with error |
| 271 | $t->get_ok('/?q=error') |
| 272 | ->status_is(400) |
| 273 | ->text_is('#notifications .notify-error','500: Internal Server Error') |
| 274 | ; |
| 275 | |
Akron | a3c353c | 2019-02-14 23:50:00 +0100 | [diff] [blame] | 276 | # Do not cache |
| 277 | $t->get_ok('/?q=timeout') |
| 278 | ->status_is(200) |
Akron | cb5c171 | 2021-01-26 18:01:04 +0100 | [diff] [blame] | 279 | # ->text_like('#notifications div.notify-warning', qr!Response time exceeded!) |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 280 | ->element_exists("input#cq") |
| 281 | ->element_exists_not("input#cq[value]") |
Akron | a3c353c | 2019-02-14 23:50:00 +0100 | [diff] [blame] | 282 | ->text_is('#total-results', '> 4,274,841'); |
| 283 | ; |
| 284 | |
Akron | 91a7685 | 2019-08-28 12:35:37 +0200 | [diff] [blame] | 285 | $t->app->defaults(no_cache => 1); |
| 286 | |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 287 | # Query with collection |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 288 | $err = $t->get_ok('/?q=baum&collection=availability+%3D+%2FCC-BY.*%2F') |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 289 | ->status_is(200) |
| 290 | ->element_exists("input#cq[value='availability = /CC-BY.*/']") |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 291 | ->content_like(qr!${q}availability${q}!) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 292 | ->tx->res->dom->at('#error') |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 293 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 294 | is(defined $err ? $err->text : '', ''); |
| 295 | |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 296 | |
Akron | 4cdc4fc | 2020-04-28 12:19:11 +0200 | [diff] [blame] | 297 | $t->app->hook( |
Akron | 7c87c1a | 2020-04-28 12:35:55 +0200 | [diff] [blame] | 298 | after_search => sub { |
Akron | 4cdc4fc | 2020-04-28 12:19:11 +0200 | [diff] [blame] | 299 | my $c = shift; |
| 300 | $c->content_for('after_search_results' => '<p id="special">Funny</p>'); |
| 301 | } |
| 302 | ); |
| 303 | |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 304 | # Query with corpus query |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 305 | $err = $t->get_ok('/?q=baum&cq=availability+%3D+%2FCC-BY.*%2F') |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 306 | ->status_is(200) |
| 307 | ->element_exists("input#cq[value='availability = /CC-BY.*/']") |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 308 | ->content_like(qr!${q}availability${q}!) |
Akron | 4cdc4fc | 2020-04-28 12:19:11 +0200 | [diff] [blame] | 309 | ->text_is('#special', 'Funny') |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 310 | ->tx->res->dom->at('#error') |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 311 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 312 | is(defined $err ? $err->text : '', ''); |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 313 | |
Akron | 909ed08 | 2019-12-11 21:38:27 +0100 | [diff] [blame] | 314 | my $match = { |
| 315 | matchID => 'match-FOLK/00070-SE-01/T-04-p5441-5442', |
| 316 | textSigle => 'FOLK/00070-SE-01/T-04' |
| 317 | }; |
| 318 | |
| 319 | $match = Kalamar::Controller::Search::_map_match($match); |
| 320 | |
| 321 | is($match->{matchID}, 'p5441-5442'); |
| 322 | |
Akron | 7b9a196 | 2020-07-02 09:52:53 +0200 | [diff] [blame] | 323 | # Query with pipe |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 324 | $err = $t->get_ok('/?q=baum&pipe=glemm') |
Akron | 7b9a196 | 2020-07-02 09:52:53 +0200 | [diff] [blame] | 325 | ->status_is(200) |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 326 | ->content_like(qr/${q}pipes${q}:${q}glemm${q}/) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 327 | ->tx->res->dom->at('#error') |
Akron | 7b9a196 | 2020-07-02 09:52:53 +0200 | [diff] [blame] | 328 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 329 | is(defined $err ? $err->text : '', ''); |
Akron | 7b9a196 | 2020-07-02 09:52:53 +0200 | [diff] [blame] | 330 | |
Akron | 909ed08 | 2019-12-11 21:38:27 +0100 | [diff] [blame] | 331 | |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 332 | done_testing; |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 333 | __END__ |