Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset "page" param on "per_page" change #528

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/stylesheets/blacklight/_dropdown.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
&:hover {
background: whiteSmoke;
}
a {
span {
padding: 5px 10px;
display: block;
}
Expand Down
9 changes: 5 additions & 4 deletions app/views/catalog/_per_page_widget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
<li class="btn">
<%= link_to(t(:'blacklight.search.per_page.button_label', :count => current_per_page), "#") %> <span class="caret"></span>
<ul>
<%- blacklight_config.per_page.each do |count| %>
<li><%= link_to(t(:'blacklight.search.per_page.label', :count => count).html_safe, url_for(params_for_search.merge(:per_page => count))) %></li>
<%- end -%>
<%- blacklight_config.per_page.each do |count| %>
<li><span><%= link_to_unless(count == current_per_page, t(:'blacklight.search.per_page.label', :count => count).html_safe,
url_for(params_for_search.merge(:per_page => count, :page => 1))) %></span></li>
<%- end -%>
</ul>
</li>
</ul>
</div>
<% end %>
<% end %>
5 changes: 3 additions & 2 deletions app/views/catalog/_sort_widget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<%= link_to(t('blacklight.search.sort.label', :field =>current_sort_field.label), "#") %> <span class="caret"></span>
<ul>
<%- blacklight_config.sort_fields.each do |sort_key, field| %>
<li><%= link_to(field.label, url_for(params_for_search.merge(:sort => sort_key))) %></li>
<li><span><%= link_to_unless(field.label == current_sort_field.label, field.label,
url_for(params_for_search.merge(:sort => sort_key))) %></span></li>
<%- end -%>
</ul>
</li>
</ul>
</div>
<% end %>
<% end %>
3 changes: 0 additions & 3 deletions test_support/features/search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ Feature: Search
And I should see "All Fields"
And I should see "history"
And I should see select list "select#search_field" with "All Fields" selected
And I should see "per page"
And I should see a selectable list with per page choices
And I should see "1."
And I should see "2."
And I should see "3."
And I should see "Sort by"


Scenario: Submitting a Search with specific field selected
When I am on the home page
Expand Down
53 changes: 53 additions & 0 deletions test_support/features/search_pagination.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@search_pagination
Feature: Search Pagination
In order to find lower ranked documents
As a user
I want to be able to page through search results and be able to choose how
many documents to display per page

Background:
Given the application is configured to have per page with values "10, 20, 50"

Scenario: Results Page Supports Paging
Given I am on the home page
When I fill in "q" with ""
And I press "search"
Then I should see "1 - 10 of"
When I follow "Next »"
Then I should see "11 - 20 of"
When I follow "« Previous"
Then I should see "1 - 10 of"

Scenario: Results Page Has Per Page Available
Given I am on the home page
When I fill in "q" with ""
And I press "search"
Then I should see "per page"
And I should see the per_page dropdown with values "10, 20, 50"

Scenario: Results Page Can Display 20 Items Per Page
Given I am on the home page
And I fill in "q" with ""
When I press "search"
Then I should see "1 - 10 of"
When I show 20 per page
Then I should see "1 - 20 of"

Scenario: Application Can Be Configured for Other Per Page Values
Given the application is configured to have per page with values "15, 30"
And I am on the home page
When I fill in "q" with ""
And I press "search"
Then I should see the per_page dropdown with values "15, 30"
And I should see "1 - 15 of"
When I show 30 per page
Then I should see "1 - 30 of"

Scenario: Page Offset Resets to 1 When Changing Per Page
Given I am on the home page
And I fill in "q" with ""
When I press "search"
And I follow "Next »"
Then I should see "11 - 20 of"
When I show 20 per page
Then I should see "1 - 20 of"
29 changes: 29 additions & 0 deletions test_support/features/step_definitions/search_pagination_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- encoding : utf-8 -*-
Given /^the application is configured to have per page with values "([^\"]*)"$/ do |values|
values = values.split(", ")
CatalogController.blacklight_config[:per_page] = []
values.each do |value|
CatalogController.blacklight_config[:per_page] << value
end
CatalogController.blacklight_config[:default_solr_params][:rows] = values[0]
end


Then /^I should see a selectable list with per page choices$/ do
page.should have_selector("#per_page-dropdown")
end

Then /^I should see the per_page dropdown with values "(.*?)"$/ do |arg1|
page.should have_selector('#per_page-dropdown') do
labels = values.split(", ")
labels.each do |label|
with_tag('li', label)
end
end
end

When /^I show (\d+) per page$/ do |value|
within('#per_page-dropdown .css-dropdown ul') do
click_link("#{value} per page")
end
end
11 changes: 0 additions & 11 deletions test_support/features/step_definitions/search_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@
page.should have_selector("select#search_field")
end

Then /^I should see a selectable list with per page choices$/ do
page.should have_selector("#per_page-dropdown")
end


When /^I show (\d+) per page$/ do |value|
page.should have_selector('#per_page-dropdown') do
click_link(value)
end
end

Then /^I should see the sort dropdown$/ do
page.should have_selector("#sort-dropdown")
end
Expand Down