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 | ##################### |
| 10 | my $mount_point = '/api/'; |
| 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 |
| 17 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'fixtures'); |
| 18 | my $fake_backend = $t->app->plugin( |
| 19 | Mount => { |
| 20 | $mount_point => |
| 21 | $fixtures_path->child('fake_backend.pl') |
| 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.') |
| 79 | ->text_like('div.notify-error:nth-of-type(2)', qr!302: Could not parse query .+? \[orth=das.+?!) |
| 80 | ; |
| 81 | |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 82 | # Query with partial cache (for total results) |
| 83 | $t->get_ok('/?q=baum') |
| 84 | ->status_is(200) |
| 85 | ->text_is('#error','') |
| 86 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 87 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 88 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 89 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 90 | ->content_like(qr!\"cutOff":true!) |
| 91 | ->text_is('#total-results', 51) |
| 92 | ; |
| 93 | |
| 94 | # Query with full cache |
| 95 | $t->get_ok('/?q=baum') |
| 96 | ->status_is(200) |
| 97 | ->text_is('#error','') |
| 98 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 99 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 100 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 101 | ->header_is('X-Kalamar-Cache', 'true') |
| 102 | ->content_like(qr!\"cutOff":true!) |
| 103 | ->text_is('#total-results', 51) |
| 104 | ; |
| 105 | |
| 106 | |
| 107 | # Query with page information |
| 108 | $t->get_ok('/?q=der&p=1&count=2') |
| 109 | ->status_is(200) |
| 110 | ->text_is('#error','') |
| 111 | ->text_is('title', 'KorAP: Find »der« with Poliqarp') |
| 112 | |
| 113 | # Total results |
| 114 | ->text_is('#total-results', '14,581') |
| 115 | |
| 116 | # Total pages |
| 117 | ->element_count_is('#pagination a', 7) |
| 118 | ->text_is('#pagination a:nth-of-type(6) span', 7291) |
| 119 | ->content_like(qr!\"count":2!) |
| 120 | ->content_like(qr!\"startIndex":0!) |
| 121 | ->content_like(qr!\"itemsPerPage":2!) |
| 122 | |
| 123 | # No caching |
| 124 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 125 | |
| 126 | # Not searched for "der" before |
| 127 | ->content_unlike(qr!\"cutOff":true!) |
| 128 | ; |
| 129 | |
| 130 | # Query with page information - next page |
| 131 | $t->get_ok('/?q=der&p=2&count=2') |
| 132 | ->status_is(200) |
| 133 | ->text_is('#error','') |
| 134 | ->text_is('title', 'KorAP: Find »der« with Poliqarp') |
| 135 | |
| 136 | # Total results |
| 137 | ->text_is('#total-results', '14,581') |
| 138 | |
| 139 | # Total pages |
| 140 | ->element_count_is('#pagination a', 7) |
| 141 | ->text_is('#pagination a:nth-of-type(6) span', 7291) |
| 142 | ->content_like(qr!\"count":2!) |
| 143 | ->content_like(qr!\"itemsPerPage":2!) |
| 144 | ->content_like(qr!\"startIndex":2!) |
| 145 | |
| 146 | # No caching |
| 147 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 148 | ->content_like(qr!\"cutOff":true!) |
| 149 | ; |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 154 | done_testing; |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 155 | __END__ |