Skip to content

Commit

Permalink
Fix for beta5
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 9, 2023
1 parent 7fc651a commit de2b7eb
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<%= render(Blacklight::DocumentComponent.new(classes: 'col', component: :div, document: @document, counter: @counter, presenter: @presenter)) do |component| %>
<% component = Blacklight::VERSION > '8' ?
Blacklight::DocumentComponent.new(classes: 'col', component: :div, document: @presenter, counter: @counter) :
Blacklight::DocumentComponent.new(classes: 'col', component: :div, document: @document, presenter: @presenter, counter: @counter)
%>
<%= render(component) do |component| %>
<% component.body do %>
<div class="thumbnail-container">
<%= thumbnail %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<%= render(Blacklight::DocumentComponent.new(classes: 'slideshow-preview-thumbnail', component: :div, document: @document, counter: @counter, presenter: @presenter)) do |component| %>
<% component = Blacklight::VERSION > '8' ?
Blacklight::DocumentComponent.new(classes: 'slideshow-preview-thumbnail', component: :div, document: @presenter, counter: @counter) :
Blacklight::DocumentComponent.new(classes: 'slideshow-preview-thumbnail', component: :div, document: @document, presenter: @presenter, counter: @counter)
%>
<%= render(component) do |component| %>
<% component.body do %>
<%= @view_context.link_to_document(@document, thumbnail, class: 'thumbnail', data: { 'context-href': nil, 'slide-to': @document_counter - 1, toggle: "modal", target: "#slideshow-modal" }) %>
<% end %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/catalog/_document_gallery.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<% view_config = local_assigns[:view_config] || blacklight_config&.view_config(document_index_view_type) %>
<div class="container">
<div id="documents" class="<%= (Array(view_config.classes || 'row-cols-2 row-cols-md-3') + ["row documents-#{view_config.key}"]).join(' ') %>">
<%= render documents, as: :document, view_config: view_config %>
<% document_presenters = Blacklight::VERSION > '8' ? documents.map { |doc| document_presenter(doc) } : documents %>
<%= render view_config.document_component.with_collection(document_presenters, counter_offset: @response&.start || 0) %>
</div>
</div>
3 changes: 2 additions & 1 deletion app/views/catalog/_document_masonry.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<% view_config = local_assigns[:view_config] || blacklight_config&.view_config(document_index_view_type) %>
<div id="documents" class="<%= (Array(view_config.classes) + ["documents-#{view_config.key}"]).join(' ') %>">
<%= render documents, as: :document, view_config: view_config %>
<% document_presenters = Blacklight::VERSION > '8' ? documents.map { |doc| document_presenter(doc) } : documents%>
<%= render view_config.document_component.with_collection(document_presenters, counter_offset: @response&.start || 0) %>
</div>
5 changes: 3 additions & 2 deletions app/views/catalog/_document_slideshow.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<% view_config = local_assigns[:view_config] || blacklight_config&.view_config(document_index_view_type) %>

<div id="documents" class="<%= (Array(view_config.classes) + ["documents-#{view_config.key}"]).join(' ') %>">
<% document_presenters = Blacklight::VERSION > '8' ? documents.map { |document| document_presenter(document) }: documents %>
<div class="grid">
<%= render((view_config.preview_component || Blacklight::Gallery::SlideshowPreviewComponent).with_collection(documents)) %>
<%= render((view_config.preview_component || Blacklight::Gallery::SlideshowPreviewComponent).with_collection(document_presenters)) %>
</div>

<%= render layout: 'slideshow_modal' do %>
<div id="slideshow" class="slideshow-presenter">
<!-- Wrapper for slides -->
<div class="slideshow-inner">
<%= render documents, as: :document %>
<%= render view_config.document_component.with_collection(document_presenters, counter_offset: @response&.start || 0) %>
</div>

<!-- Controls -->
Expand Down
14 changes: 12 additions & 2 deletions spec/components/blacklight/gallery/document_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
require 'spec_helper'

RSpec.describe Blacklight::Gallery::DocumentComponent, type: :component do
subject(:component) { described_class.new(document: document, presenter: presenter, **attr) }
subject(:component) do
if Blacklight::VERSION > '8'
described_class.new(document: presenter, **attr)
else
described_class.new(document: document, presenter: presenter, **attr)
end
end

let(:attr) { {} }
let(:view_context) { controller.view_context }
Expand All @@ -27,7 +33,11 @@

let(:blacklight_config) do
CatalogController.blacklight_config.deep_copy.tap do |config|
config.track_search_session = false
if Blacklight::VERSION > '8'
config.track_search_session.storage = false
else
config.track_search_session = false
end
config.index.thumbnail_field = 'thumbnail_path_ss'
end
end
Expand Down
38 changes: 31 additions & 7 deletions spec/components/blacklight/gallery/slideshow_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
require 'spec_helper'

RSpec.describe Blacklight::Gallery::SlideshowComponent, type: :component do
subject(:component) { described_class.new(document: document, presenter: presenter, **attr) }
subject(:component) do
if Blacklight::VERSION > '8'
described_class.new(document: presenter, **attr)
else
described_class.new(document: document, presenter: presenter, **attr)
end
end

let(:attr) { {} }
let(:view_context) { controller.view_context }
Expand Down Expand Up @@ -36,7 +42,11 @@
let(:blacklight_config) do
Blacklight::Configuration.new.tap do |config|
config.index.slideshow_method = :xyz
config.track_search_session = false
if Blacklight::VERSION > '8'
config.track_search_session.storage = false
else
config.track_search_session = false
end
end
end

Expand All @@ -55,7 +65,11 @@
let(:blacklight_config) do
Blacklight::Configuration.new.tap do |config|
config.index.slideshow_field = :xyz
config.track_search_session = false
if Blacklight::VERSION > '8'
config.track_search_session.storage = false
else
config.track_search_session = false
end
end
end
let(:document) { SolrDocument.new({ xyz: 'http://example.com/some.jpg', id: 'x' }) }
Expand All @@ -70,17 +84,27 @@
end

context 'with no view_config' do
let(:blacklight_config) { Blacklight::Configuration.new.tap { |config|
config.track_search_session = false
} }
let(:blacklight_config) do
Blacklight::Configuration.new.tap do |config|
if Blacklight::VERSION > '8'
config.track_search_session.storage = false
else
config.track_search_session = false
end
end
end
it { is_expected.not_to have_selector 'img' }
end

context 'falling back to a thumbnail' do
let(:blacklight_config) do
Blacklight::Configuration.new.tap do |config|
config.index.thumbnail_field = :xyz
config.track_search_session = false
if Blacklight::VERSION > '8'
config.track_search_session.storage = false
else
config.track_search_session = false
end
end
end
let(:document) { SolrDocument.new({ xyz: 'http://example.com/thumb.jpg', id: 'x' }) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
require 'spec_helper'

RSpec.describe Blacklight::Gallery::SlideshowPreviewComponent, type: :component do
subject(:component) { described_class.new(document: document, document_counter: 5, presenter: presenter, **attr) }
subject(:component) do
if Blacklight::VERSION > '8'
described_class.new(document: presenter, document_counter: 5, **attr)
else
described_class.new(document: document, document_counter: 5, presenter: presenter, **attr)
end
end

let(:attr) { {} }
let(:view_context) { controller.view_context }
Expand All @@ -30,15 +36,18 @@
let(:blacklight_config) do
Blacklight::Configuration.new.tap do |config|
config.index.thumbnail_field = 'thumbnail_path_ss'
config.track_search_session = false
if Blacklight::VERSION > '8'
config.track_search_session.storage = false
else
config.track_search_session = false
end
end
end

describe 'default thumbnail' do
let(:document) { SolrDocument.new(id: 'abc', thumbnail_path_ss: 'http://example.com/image.jpg') }

it 'renders the thumbnail' do
puts render
expect(rendered).to have_selector '.thumbnail img[@src="http://example.com/image.jpg"]'
end

Expand Down
4 changes: 2 additions & 2 deletions spec/features/gallery_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'spec_helper'

describe "Gallery view", :type => :feature do
RSpec.describe "Gallery view", :type => :feature do
before { visit search_catalog_path :q => 'medicine', :view => 'gallery' }

it "should display results in a galley view" do
it "displays results in a galley view" do
expect(page).to have_selector("#documents.documents-gallery")
expect(page).to have_selector(".caption", text: "Strong Medicine speaks")
end
Expand Down
12 changes: 9 additions & 3 deletions spec/views/catalog/_document_slideshow.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
require 'spec_helper'

describe "catalog/_document_slideshow", :type => :view do
RSpec.describe "catalog/_document_slideshow", :type => :view do
let(:blacklight_config) do
Blacklight::Configuration.new do |config|
config.track_search_session = false
if Blacklight::VERSION > '8'
config.track_search_session.storage = false
else
config.track_search_session = false
end
end
end

let(:document) { stub_model(::SolrDocument) }
let(:view_config) { Blacklight::Configuration::ViewConfig.new(document_component: Blacklight::Gallery::SlideshowComponent) }

before do
allow(view).to receive_messages(
Expand All @@ -19,10 +24,11 @@
allow(view).to receive(:current_search_session).and_return(nil)
allow(view).to receive(:search_session).and_return({})
allow(view).to receive(:search_state).and_return(Blacklight::SearchState.new({}, blacklight_config))
@response = instance_double(Blacklight::Solr::Response, start: 0)
end

it 'has a modal' do
render
render 'catalog/document_slideshow', view_config: view_config
expect(rendered).to have_selector '#slideshow-modal'
expect(rendered).to have_selector '[data-slide="prev"]'
expect(rendered).to have_selector '[data-slide="next"]'
Expand Down

0 comments on commit de2b7eb

Please sign in to comment.