Improve error handling

Change-Id: I1f54cf9cd4770d6602f70036cf0e27c9ede8c893
diff --git a/t/query.t b/t/query.t
index 4bc97dc..97f4997 100644
--- a/t/query.t
+++ b/t/query.t
@@ -25,9 +25,10 @@
 $fake_backend->pattern->defaults->{app}->log($t->app->log);
 
 # Query passed
-$t->get_ok('/q2?q=baum')
+$t->get_ok('/?q=baum')
   ->status_is(200)
   ->text_is('#error','')
+
   ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
   ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
   ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
@@ -42,6 +43,9 @@
   ->content_like(qr/\"authorized\":null/)
   ->content_like(qr/\"pubDate\",\"subTitle\",\"author\"/)
 
+  # No cutOff
+  ->content_unlike(qr!\"cutOff":true!)
+
   ->element_exists('li[data-text-sigle=GOE/AGI/00000]')
   ->element_exists('li:nth-of-type(1) div.flop')
   ->element_exists('li[data-text-sigle=GOE/AGI/00001]')
@@ -65,13 +69,87 @@
   ->text_like('li:nth-of-type(1) p.ref', qr!by Goethe, Johann Wolfgang!)
   ->text_is('li:nth-of-type(1) p.ref time[datetime=1982]', 1982)
   ->text_is('li:nth-of-type(1) p.ref span.sigle', '[GOE/AGI/00000]')
+  ->header_isnt('X-Kalamar-Cache', 'true')
   ;
 
 
-$t->get_ok('/q2?q=[orth=das')
+$t->get_ok('/?q=[orth=das')
   ->status_is(400)
   ->text_is('div.notify-error:nth-of-type(1)', '302: Parantheses/brackets unbalanced.')
   ->text_like('div.notify-error:nth-of-type(2)', qr!302: Could not parse query .+? \[orth=das.+?!)
   ;
 
+# Query with partial cache (for total results)
+$t->get_ok('/?q=baum')
+  ->status_is(200)
+  ->text_is('#error','')
+  ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
+  ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
+  ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
+  ->header_isnt('X-Kalamar-Cache', 'true')
+  ->content_like(qr!\"cutOff":true!)
+  ->text_is('#total-results', 51)
+  ;
+
+# Query with full cache
+$t->get_ok('/?q=baum')
+  ->status_is(200)
+  ->text_is('#error','')
+  ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
+  ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
+  ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
+  ->header_is('X-Kalamar-Cache', 'true')
+  ->content_like(qr!\"cutOff":true!)
+  ->text_is('#total-results', 51)
+  ;
+
+
+# Query with page information
+$t->get_ok('/?q=der&p=1&count=2')
+  ->status_is(200)
+  ->text_is('#error','')
+  ->text_is('title', 'KorAP: Find »der« with Poliqarp')
+
+  # Total results
+  ->text_is('#total-results', '14,581')
+
+  # Total pages
+  ->element_count_is('#pagination a', 7)
+  ->text_is('#pagination a:nth-of-type(6) span', 7291)
+  ->content_like(qr!\"count":2!)
+  ->content_like(qr!\"startIndex":0!)
+  ->content_like(qr!\"itemsPerPage":2!)
+
+  # No caching
+  ->header_isnt('X-Kalamar-Cache', 'true')
+
+  # Not searched for "der" before
+  ->content_unlike(qr!\"cutOff":true!)
+  ;
+
+# Query with page information - next page
+$t->get_ok('/?q=der&p=2&count=2')
+  ->status_is(200)
+  ->text_is('#error','')
+  ->text_is('title', 'KorAP: Find »der« with Poliqarp')
+
+  # Total results
+  ->text_is('#total-results', '14,581')
+
+  # Total pages
+  ->element_count_is('#pagination a', 7)
+  ->text_is('#pagination a:nth-of-type(6) span', 7291)
+  ->content_like(qr!\"count":2!)
+  ->content_like(qr!\"itemsPerPage":2!)
+  ->content_like(qr!\"startIndex":2!)
+
+  # No caching
+  ->header_isnt('X-Kalamar-Cache', 'true')
+  ->content_like(qr!\"cutOff":true!)
+  ;
+
+
+
+
 done_testing;
+__END__