-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy SearchContextComponent to ServerItemPaginationComponent to ease …
…BL8 upgrade path (#3421) * Copy SearchContextComponent to ServerItemPaginationComponent to ease BL8 upgrade path Closes #3313 * Keep using old component for backwards compatibility - Test components Co-authored-by: Jane Sandberg <[email protected]> * Have copied component inherit from main component, just with updated signature --------- Co-authored-by: Jane Sandberg <[email protected]>
- Loading branch information
1 parent
6847a50
commit 9409ccc
Showing
8 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
app/components/blacklight/search_context/server_item_pagination_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class='pagination-search-widgets'> | ||
|
||
<div class="page-links"> | ||
<%= link_to_previous_document %> | | ||
|
||
<%= item_page_entry_info %> | | ||
|
||
<%= link_to_next_document %> | ||
</div> | ||
</div> |
15 changes: 15 additions & 0 deletions
15
app/components/blacklight/search_context/server_item_pagination_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module SearchContext | ||
class ServerItemPaginationComponent < Blacklight::SearchContextComponent | ||
with_collection_parameter :search_context | ||
|
||
def initialize(search_context:, search_session:, current_document:) | ||
@search_context = search_context | ||
@search_session = search_session | ||
@current_document_id = current_document.id | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<% Deprecation.warn(self, 'The partial _previous_next_doc.html.erb will be removed in 8.0. Render Blacklight::SearchContextComponent instead.') %> | ||
<% Deprecation.warn(self, 'The partial _previous_next_doc.html.erb will be removed in 8.0. Render Blacklight::SearchContext::ServerItemPaginationComponent instead.') %> | ||
<%= render(Blacklight::SearchContextComponent.new(search_context: @search_context, search_session: search_session)) %> |
35 changes: 35 additions & 0 deletions
35
spec/components/blacklight/search_context/server_item_pagination_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Blacklight::SearchContext::ServerItemPaginationComponent, type: :component do | ||
subject(:render) { render_inline(instance) } | ||
|
||
let(:current_document_id) { 9 } | ||
let(:current_document) { SolrDocument.new(id: current_document_id) } | ||
let(:search_session) { { 'document_id' => current_document_id, 'counter' => 1, 'total' => '3' } } | ||
let(:instance) { described_class.new(search_context: search_context, search_session: search_session, current_document: current_document) } | ||
|
||
before do | ||
allow(controller).to receive(:search_session).and_return(search_session) | ||
allow(controller).to receive(:current_search_session).and_return(double(id: current_document_id)) | ||
controller.class.helper_method :search_session | ||
controller.class.helper_method :current_search_session | ||
end | ||
|
||
context 'when there is next and previous' do | ||
let(:search_context) { { next: next_doc, prev: prev_doc } } | ||
let(:prev_doc) { SolrDocument.new(id: '777') } | ||
let(:next_doc) { SolrDocument.new(id: '888') } | ||
|
||
before do | ||
# allow(controller).to receive(:controller_tracking_method).and_return('track_catalog_path') | ||
|
||
allow(controller).to receive_messages(controller_name: 'catalog', link_to_previous_document: '', link_to_next_document: '') | ||
end | ||
|
||
it "renders content" do | ||
expect(render.css('.page-links').to_html).not_to be_blank | ||
end | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
spec/components/blacklight/search_context_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
RSpec.describe Blacklight::SearchContextComponent, type: :component do | ||
subject(:render) { render_inline(instance) } | ||
|
||
let(:current_document_id) { 9 } | ||
let(:search_session) { { 'document_id' => current_document_id, 'counter' => 1, 'total' => '3' } } | ||
let(:instance) { described_class.new(search_context: search_context, search_session: search_session) } | ||
|
||
before do | ||
allow(controller).to receive(:search_session).and_return(search_session) | ||
allow(controller).to receive(:current_search_session).and_return(double(id: current_document_id)) | ||
controller.class.helper_method :search_session | ||
controller.class.helper_method :current_search_session | ||
end | ||
|
||
context 'when there is next and previous' do | ||
let(:search_context) { { next: next_doc, prev: prev_doc } } | ||
let(:prev_doc) { SolrDocument.new(id: '777') } | ||
let(:next_doc) { SolrDocument.new(id: '888') } | ||
|
||
before do | ||
allow(controller).to receive_messages(controller_name: 'catalog', link_to_previous_document: '', link_to_next_document: '') | ||
end | ||
|
||
it "renders content" do | ||
expect(render.css('.page-links').to_html).not_to be_blank | ||
end | ||
end | ||
end |