From 9ae58e3a8d04a732ec78eaf17b085692fb3ae98d Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Wed, 24 Feb 2016 11:39:12 +0100 Subject: [PATCH] Add spec for search result pagination --- app/views/search/index.html.slim | 2 +- spec/features/basic_search_spec.rb | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/views/search/index.html.slim b/app/views/search/index.html.slim index 8434175..4437428 100644 --- a/app/views/search/index.html.slim +++ b/app/views/search/index.html.slim @@ -23,5 +23,5 @@ div span.published = l doc.published_at.to_date /! score: #{doc._score} -div +div#pagination = paginate @papers diff --git a/spec/features/basic_search_spec.rb b/spec/features/basic_search_spec.rb index e89cc83..6824294 100644 --- a/spec/features/basic_search_spec.rb +++ b/spec/features/basic_search_spec.rb @@ -18,13 +18,31 @@ RSpec.feature "Basic search", type: :feature, elasticsearch: true do expect(page).to have_field("paper_search_sort_by_score", type: "radio") end - scenario "It displays a list of search results" do + scenario "With empty query displays all documents" do visit search_path body: "leipzig" expect(page).to have_selector("ul#search_results") - expect(page).to have_css("li.search-result", count: 10) expect(page).to have_content("#{@papers.size} Dokumente in der Datenbank") end + scenario "Search results are paginated" do + visit search_path body: "leipzig" + expect(page).to have_css("li.search-result", count: 10) + expect(page).to have_css("div#pagination") + within("div#pagination") do + expect(page).to have_css("li", count: 4) # two pages + next + last + expect(page).to have_css("li.current", text: "1") + expect(page).to have_link("2") + expect(page).to have_link("Weiter") + expect(page).to have_link("Ende") + end + + page.find("div#pagination").click_link("2") + expect(page).to have_css("li.search-result", count: 1) + within("div#pagination") do + expect(page).to have_css("li.current", text: "2") + end + end + scenario "Search results have basic information" do visit search_path body: "leipzig" paper = @papers.first