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