From ed835149ec183bdbf7ec3b1972636a69f432e40c Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Fri, 3 Apr 2020 08:13:04 -0700 Subject: [PATCH] Convert document show/index views to support and use view components --- .../blacklight/document_component.html.erb | 29 ++++ .../blacklight/document_component.rb | 117 ++++++++++++++++ .../document_metadata_component.html.erb | 5 + .../blacklight/document_metadata_component.rb | 21 +++ .../metadata_field_component.html.erb | 8 ++ .../blacklight/metadata_field_component.rb | 31 +++++ .../metadata_field_layout_component.html.erb | 2 + .../metadata_field_layout_component.rb | 16 +++ .../blacklight/blacklight_helper_behavior.rb | 14 +- .../configuration_helper_behavior.rb | 4 + .../blacklight/document_presenter.rb | 10 +- app/presenters/blacklight/field_presenter.rb | 1 + app/views/catalog/_document.html.erb | 10 +- app/views/catalog/_index.html.erb | 11 +- app/views/catalog/_show.html.erb | 14 +- app/views/catalog/_show_main_content.html.erb | 28 ++-- lib/blacklight/configuration.rb | 2 + .../blacklight/document_component_spec.rb | 125 ++++++++++++++++++ .../document_metadata_component_spec.rb | 0 .../metadata_field_component_spec.rb | 29 ++++ spec/helpers/blacklight_helper_spec.rb | 5 +- spec/views/catalog/_document.html.erb_spec.rb | 16 +-- 22 files changed, 444 insertions(+), 54 deletions(-) create mode 100644 app/components/blacklight/document_component.html.erb create mode 100644 app/components/blacklight/document_component.rb create mode 100644 app/components/blacklight/document_metadata_component.html.erb create mode 100644 app/components/blacklight/document_metadata_component.rb create mode 100644 app/components/blacklight/metadata_field_component.html.erb create mode 100644 app/components/blacklight/metadata_field_component.rb create mode 100644 app/components/blacklight/metadata_field_layout_component.html.erb create mode 100644 app/components/blacklight/metadata_field_layout_component.rb create mode 100644 spec/components/blacklight/document_component_spec.rb create mode 100644 spec/components/blacklight/document_metadata_component_spec.rb create mode 100644 spec/components/blacklight/metadata_field_component_spec.rb diff --git a/app/components/blacklight/document_component.html.erb b/app/components/blacklight/document_component.html.erb new file mode 100644 index 0000000000..fcb05cc8dc --- /dev/null +++ b/app/components/blacklight/document_component.html.erb @@ -0,0 +1,29 @@ +<%= content_tag @component, + id: @id, + data: { + 'document-id': @document.id.to_s.parameterize, + 'document-counter': @counter, + }, + itemscope: true, + itemtype: @document.itemtype, + class: classes.flatten.join(' ') do %> + <%= header %> + <% if body.present? %> + <%= body %> + <% else %> +
+
+ <%= content_tag @title_component, class: 'index_title document-title-heading' do %> + <%= before_title %><%= title %><%= after_title %> + <% end %> + <%= actions %> +
+ + <%= content %> + <%= metadata %> +
+ + <%= thumbnail %> + <% end %> + <%= footer %> +<% end %> diff --git a/app/components/blacklight/document_component.rb b/app/components/blacklight/document_component.rb new file mode 100644 index 0000000000..ce4e1f716e --- /dev/null +++ b/app/components/blacklight/document_component.rb @@ -0,0 +1,117 @@ +# frozen_string_literal: true + +module Blacklight + class DocumentComponent < ::ViewComponent::Base + # Available content areas; some have defaults provided by + # the accessors below. + with_content_areas :header, :body, :footer, + :before_title, :title, :after_title, + :actions, :metadata, :thumbnail, + :partials + with_collection_parameter :document + + # rubocop:disable Metrics/ParameterLists + # @param document [Blacklight::Document] + # @param id [String] HTML id for the root element + # @param classes [Array, String] additional HTML classes for the root element + # @param component [Symbol, String] HTML tag type to use for the root element + # @param title_component [Symbol, String] HTML tag type to use for the title element + # @param presenter [Blacklight::DocumentPresenter] + # @param metadata_component [Blacklight::DocumentMetadataComponent] + # @param counter [Number, nil] + # @param show [Boolean] are we showing only a single document (vs a list of search results); used for backwards-compatibility + def initialize(document:, id: nil, classes: [], component: :article, title_component: :h4, presenter: nil, metadata_component: Blacklight::DocumentMetadataComponent, counter: nil, show: false) + @document = document + + @component = component + @title_component = title_component + @id = id || ('document' if show) + @classes = classes + + @presenter = presenter + @metadata_component = metadata_component + + @counter = counter + + @show = show + end + # rubocop:enable Metrics/ParameterLists + + # HTML classes to apply to the root element + def classes + [ + @classes, + @view_context.render_document_class(@document), + 'document', + ("document-position-#{@counter}" if @counter) + ].compact.flatten + end + + # Content for the document title area; should be an inline element + def title + @title || begin + if show? + content_tag('span', presenter.heading, itemprop: "name") + else + @view_context.link_to_document @document, counter: @counter, itemprop: 'name' + end + end + end + + # Content for the document actions area + def actions + return if @show + + @actions || begin + @view_context.render_index_doc_actions @document, wrapping_class: "index-document-functions col-sm-3 col-lg-2" + end + end + + # Content for the document thumbnail area + def thumbnail + return if @show + + @thumbnail || begin + return unless presenter.thumbnail.exists? + + content_tag :div, class: "document-thumbnail" do + presenter.thumbnail.thumbnail_tag({ alt: '' }, 'aria-hidden': true, tabindex: -1, counter: @counter) + end + end + end + + # Content for the document metadata area + def metadata + @metadata || @view_context.render(@metadata_component.new(fields: presenter.field_presenters, show: show?)) + end + + # Content that goes before the document title (e.g. the counter) + def before_title + @before_title || counter + end + + private + + def counter + return unless @counter + + content_tag :span, class: 'document-counter' do + t('blacklight.search.documents.counter', counter: @counter) + end + end + + def presenter + @presenter ||= begin + if show? + @view_context.show_presenter(@document) + else + @view_context.index_presenter(@document) + end + end + end + + def show? + @show + end + end +end diff --git a/app/components/blacklight/document_metadata_component.html.erb b/app/components/blacklight/document_metadata_component.html.erb new file mode 100644 index 0000000000..cc39173e06 --- /dev/null +++ b/app/components/blacklight/document_metadata_component.html.erb @@ -0,0 +1,5 @@ +
+ <% @fields.each do |field| -%> + <%= @view_context.render(field_component(field).new(field: field, show: @show)) %> + <% end -%> +
diff --git a/app/components/blacklight/document_metadata_component.rb b/app/components/blacklight/document_metadata_component.rb new file mode 100644 index 0000000000..87afa0b67e --- /dev/null +++ b/app/components/blacklight/document_metadata_component.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Blacklight + class DocumentMetadataComponent < ::ViewComponent::Base + with_collection_parameter :fields + + # @param fields [Enumerable] Document field presenters + def initialize(fields:, show: false) + @fields = fields + @show = show + end + + def render? + @fields.any? + end + + def field_component(field) + field.try(:component) || Blacklight::MetadataFieldComponent + end + end +end diff --git a/app/components/blacklight/metadata_field_component.html.erb b/app/components/blacklight/metadata_field_component.html.erb new file mode 100644 index 0000000000..c50ed3c9a1 --- /dev/null +++ b/app/components/blacklight/metadata_field_component.html.erb @@ -0,0 +1,8 @@ +<%= render(@layout.new(field: @field)) do |component| %> + <% component.with(:label) do %> + <%= label %> + <% end %> + <% component.with(:value) do %> + <%= @field.render %> + <% end %> +<% end %> diff --git a/app/components/blacklight/metadata_field_component.rb b/app/components/blacklight/metadata_field_component.rb new file mode 100644 index 0000000000..8be675e17c --- /dev/null +++ b/app/components/blacklight/metadata_field_component.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Blacklight + class MetadataFieldComponent < ::ViewComponent::Base + with_collection_parameter :field + + # @param field [Blacklight::FieldPresenter] + # @param layout [Blacklight::MetadataFieldLayoutComponent] alternate layout component to use + # @param show [Boolean] are we showing only a single document (vs a list of search results); used for backwards-compatibility + def initialize(field:, layout: nil, show: false) + @field = field + @layout = layout || Blacklight::MetadataFieldLayoutComponent + @show = show + end + + # @private + def label + Deprecation.silence(Blacklight::BlacklightHelperBehavior) do + if @show + @view_context.render_document_show_field_label @field.document, label: @field.label, field: @field.key + else + @view_context.render_index_field_label @field.document, label: @field.label, field: @field.key + end + end + end + + def render? + @field.render_field? + end + end +end diff --git a/app/components/blacklight/metadata_field_layout_component.html.erb b/app/components/blacklight/metadata_field_layout_component.html.erb new file mode 100644 index 0000000000..c405c7b56f --- /dev/null +++ b/app/components/blacklight/metadata_field_layout_component.html.erb @@ -0,0 +1,2 @@ +
<%= label %>
+
<%= value %>
diff --git a/app/components/blacklight/metadata_field_layout_component.rb b/app/components/blacklight/metadata_field_layout_component.rb new file mode 100644 index 0000000000..67f0fc8e2d --- /dev/null +++ b/app/components/blacklight/metadata_field_layout_component.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Blacklight + class MetadataFieldLayoutComponent < ::ViewComponent::Base + with_collection_parameter :field + with_content_areas :label, :value + + # @param field [Blacklight::FieldPresenter] + def initialize(field:, label_class: 'col-md-3', value_class: 'col-md-9') + @field = field + @key = @field.key.parameterize + @label_class = label_class + @value_class = value_class + end + end +end diff --git a/app/helpers/blacklight/blacklight_helper_behavior.rb b/app/helpers/blacklight/blacklight_helper_behavior.rb index a309802210..9b2ca09da7 100644 --- a/app/helpers/blacklight/blacklight_helper_behavior.rb +++ b/app/helpers/blacklight/blacklight_helper_behavior.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true # Methods added to this helper will be available to all templates in the hosting application module Blacklight::BlacklightHelperBehavior + extend Deprecation + include Blacklight::UrlHelperBehavior include Blacklight::HashAsHiddenFieldsHelperBehavior include Blacklight::LayoutHelperBehavior @@ -148,9 +150,12 @@ def render_index_field_label *args document = args.first field = options[:field] - label = options[:label] || index_field_label(document, field) + label = Deprecation.silence(Blacklight::ConfigurationHelperBehavior) do + options[:label] || index_field_label(document, field) + end html_escape t(:"blacklight.search.index.#{document_index_view_type}.label", default: :'blacklight.search.index.label', label: label) end + deprecation_deprecate render_index_field_label: 'Use Blacklight::MetadataFieldComponent instead' ## # Render the show field label for a document @@ -170,10 +175,13 @@ def render_document_show_field_label *args document = args.first field = options[:field] - label = options[:label] || document_show_field_label(document, field) + label = Deprecation.silence(Blacklight::ConfigurationHelperBehavior) do + options[:label] || document_show_field_label(document, field) + end t(:'blacklight.search.show.label', label: label) end + deprecation_deprecate render_document_show_field_label: 'Use Blacklight::MetadataFieldComponent instead' ## # Get the value of the document's "title" field, or a placeholder @@ -253,7 +261,7 @@ def with_format(format) # Should we render a grouped response (because the response # contains a grouped response instead of the normal response) def render_grouped_response? response = @response - response.grouped? + response&.grouped? end ## diff --git a/app/helpers/blacklight/configuration_helper_behavior.rb b/app/helpers/blacklight/configuration_helper_behavior.rb index ecda0bdcce..193ea0550f 100644 --- a/app/helpers/blacklight/configuration_helper_behavior.rb +++ b/app/helpers/blacklight/configuration_helper_behavior.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true module Blacklight::ConfigurationHelperBehavior + extend Deprecation + ## # Index fields to display for a type of document # @@ -60,6 +62,7 @@ def index_field_label document, field field_config.display_label('index') end + deprecation_deprecate :index_field_label ## # Look up the label for the show field @@ -69,6 +72,7 @@ def document_show_field_label document, field field_config.display_label('show') end + deprecation_deprecate :document_show_field_label ## # Look up the label for the facet field diff --git a/app/presenters/blacklight/document_presenter.rb b/app/presenters/blacklight/document_presenter.rb index 4f678e7182..7f365f7ce8 100644 --- a/app/presenters/blacklight/document_presenter.rb +++ b/app/presenters/blacklight/document_presenter.rb @@ -30,6 +30,12 @@ def fields_to_render end end + def field_presenters + return to_enum(:field_presenters) unless block_given? + + fields_to_render.each { |_, _, config| yield config } + end + ## # Get the value of the document's "title" field, or a placeholder # value (if empty) @@ -63,7 +69,7 @@ def display_type(base_name = nil, default: nil) # @param [Hash] options # @option options [String] :value def field_value field_config, options = {} - field_presenter(field_config, options).render + field_presenter(field_config, options)&.render end def thumbnail @@ -93,6 +99,8 @@ def retrieve_values(field_config) deprecation_deprecate retrieve_values: 'Use FieldPresenter#values' def field_presenter(field_config, options = {}) + return unless field_config + presenter_class = field_config.presenter || Blacklight::FieldPresenter presenter_class.new(view_context, document, field_config, options) end diff --git a/app/presenters/blacklight/field_presenter.rb b/app/presenters/blacklight/field_presenter.rb index ae5165efb9..3aa8fbe313 100644 --- a/app/presenters/blacklight/field_presenter.rb +++ b/app/presenters/blacklight/field_presenter.rb @@ -29,6 +29,7 @@ def initialize(view_context, document, field_config, options = {}) end attr_reader :view_context, :document, :field_config, :except_operations, :options + delegate :key, to: :field_config def render Rendering::Pipeline.new(values, field_config, document, view_context, pipeline_steps, options).render diff --git a/app/views/catalog/_document.html.erb b/app/views/catalog/_document.html.erb index 6478c5e88e..5ea0a7272e 100644 --- a/app/views/catalog/_document.html.erb +++ b/app/views/catalog/_document.html.erb @@ -1,6 +1,6 @@ <% # container for a single doc -%> -
- <%= render_document_partials document, - blacklight_config.view_config(document_index_view_type).partials, - document_counter: document_counter %> -
+<%= render (blacklight_config.view_config(document_index_view_type).document_component || Blacklight::DocumentComponent).new(document: document, counter: document_counter_with_offset(document_counter)) do |component| %> + <% component.with(blacklight_config.view_config(document_index_view_type).document_component.blank? && blacklight_config.view_config(document_index_view_type).partials.any? ? :body : :partials) do %> + <%= render_document_partials document, blacklight_config.view_config(document_index_view_type).partials, component: component, document_counter: document_counter %> + <% end %> +<% end %> diff --git a/app/views/catalog/_index.html.erb b/app/views/catalog/_index.html.erb index dc6c53a37e..9f9c4a8c79 100644 --- a/app/views/catalog/_index.html.erb +++ b/app/views/catalog/_index.html.erb @@ -1,10 +1 @@ -<% doc_presenter = index_presenter(document) %> -<%# default partial to display solr document fields in catalog index view -%> - +<%= render(Blacklight::DocumentMetadataComponent.new(fields: index_presenter(document).field_presenters)) %> diff --git a/app/views/catalog/_show.html.erb b/app/views/catalog/_show.html.erb index 8f99d4fb86..18ee86dcb7 100644 --- a/app/views/catalog/_show.html.erb +++ b/app/views/catalog/_show.html.erb @@ -1,8 +1,6 @@ -<% doc_presenter = show_presenter(document) %> -<%# default partial to display solr document fields in catalog show view -%> - +<%= render( + Blacklight::DocumentMetadataComponent.new( + fields: show_presenter(document).field_presenters, + show: true + ) +) %> diff --git a/app/views/catalog/_show_main_content.html.erb b/app/views/catalog/_show_main_content.html.erb index d591bc204d..739f6f8107 100644 --- a/app/views/catalog/_show_main_content.html.erb +++ b/app/views/catalog/_show_main_content.html.erb @@ -3,17 +3,21 @@ <% @page_title = t('blacklight.search.show.title', :document_title => document_show_html_title, :application_name => application_name).html_safe %> <% content_for(:head) { render_link_rel_alternates } %> -
-
- <%= render_document_partials @document, blacklight_config.view_config(:show).partials %> -
-
+<%= render (blacklight_config.show.document_component || Blacklight::DocumentComponent).new(document: @document, component: :div, title_component: :h1, show: true) do |component| %> + <% component.with(:footer) do %> + <% if @document.respond_to?(:export_as_openurl_ctx_kev) %> + + + <% end %> + <% end %> -<% if @document.respond_to?(:export_as_openurl_ctx_kev) %> - - + <% component.with(blacklight_config.show.document_component.blank? && blacklight_config.view_config(:show).partials.any? ? :body : :partials) do %> +
+ <%= render_document_partials @document, blacklight_config.view_config(:show).partials, component: component %> +
+ <% end %> <% end %> diff --git a/lib/blacklight/configuration.rb b/lib/blacklight/configuration.rb index 8e575699f0..eaf1478761 100644 --- a/lib/blacklight/configuration.rb +++ b/lib/blacklight/configuration.rb @@ -65,6 +65,7 @@ def default_values index: ViewConfig::Index.new( # document presenter class used by helpers and views document_presenter_class: nil, + document_component: nil, # solr field to use to render a document title title_field: nil, # solr field to use to render format-specific partials @@ -82,6 +83,7 @@ def default_values show: ViewConfig::Show.new( # document presenter class used by helpers and views document_presenter_class: nil, + document_component: nil, display_type_field: 'format', # Default route parameters for 'show' requests. # Set this to a hash with additional arguments to merge into the route, diff --git a/spec/components/blacklight/document_component_spec.rb b/spec/components/blacklight/document_component_spec.rb new file mode 100644 index 0000000000..b6b2a871ea --- /dev/null +++ b/spec/components/blacklight/document_component_spec.rb @@ -0,0 +1,125 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Blacklight::DocumentComponent, type: :component do + subject(:component) { described_class.new(document: document, **attr) } + + let(:attr) { {} } + let(:view_context) { controller.view_context } + let(:render) do + component.render_in(view_context) + end + + let(:rendered) do + Capybara::Node::Simple.new(render) + end + + let(:document) do + SolrDocument.new( + id: 'x', + thumbnail_path_ss: 'http://example.com/image.jpg', + title_tsim: 'Title', + isbn_ssim: ['Value'] + ) + end + + let(:blacklight_config) do + CatalogController.blacklight_config.deep_copy.tap do |config| + config.track_search_session = false + config.index.thumbnail_field = 'thumbnail_path_ss' + config.index.document_actions[:bookmark].partial = '/catalog/bookmark_control.html.erb' + end + end + + before do + allow(controller).to receive(:current_or_guest_user).and_return(User.new) + allow(controller).to receive(:blacklight_config).and_return(blacklight_config) + allow(view_context).to receive(:search_session).and_return({}) + allow(view_context).to receive(:current_search_session).and_return(nil) + allow(view_context).to receive(:current_bookmarks).and_return([]) + end + + it 'has some defined content areas' do + component.with(:title, 'Title') + component.with(:metadata, 'Metadata') + component.with(:thumbnail, 'Thumbnail') + component.with(:actions, 'Actions') + + expect(rendered).to have_content 'Title' + expect(rendered).to have_content 'Metadata' + expect(rendered).to have_content 'Thumbnail' + expect(rendered).to have_content 'Actions' + end + + it 'has schema.org properties' do + component.with(:body, '-') + + expect(rendered).to have_selector 'article[@itemtype="http://schema.org/Thing"]' + expect(rendered).to have_selector 'article[@itemscope]' + end + + context 'with a provided body' do + it 'opts-out of normal component content' do + component.with(:body, 'Body content') + + expect(rendered).to have_content 'Body content' + expect(rendered).not_to have_selector 'header' + expect(rendered).not_to have_selector 'dl' + end + end + + context 'index view' do + let(:attr) { { counter: 5 } } + + it 'has data properties' do + component.with(:body, '-') + + expect(rendered).to have_selector 'article[@data-document-id="x"]' + expect(rendered).to have_selector 'article[@data-document-counter="5"]' + end + + it 'renders a linked title' do + expect(rendered).to have_link 'Title', href: '/catalog/x' + end + + it 'renders a counter with the title' do + expect(rendered).to have_selector 'header', text: '5. Title' + end + + it 'renders actions' do + expect(rendered).to have_selector '.index-document-functions' + end + + it 'renders a thumbnail' do + expect(rendered).to have_selector 'a[href="/catalog/x"] img[src="http://example.com/image.jpg"]' + end + end + + context 'show view' do + let(:attr) { { title_component: :h1, show: true } } + + it 'renders with an id' do + component.with(:body, '-') + + expect(rendered).to have_selector 'article#document' + end + + it 'renders a title' do + expect(rendered).to have_selector 'h1', text: 'Title' + end + + it 'renders with show-specific metadata' do + expect(rendered).to have_selector 'dl.document-metadata' + expect(rendered).to have_selector 'dt', text: 'ISBN:' + expect(rendered).to have_selector 'dd', text: 'Value' + end + end + + it 'renders metadata' do + expect(rendered).to have_selector 'dl.document-metadata' + expect(rendered).to have_selector 'dt', text: 'Title:' + expect(rendered).to have_selector 'dd', text: 'Title' + expect(rendered).not_to have_selector 'dt', text: 'ISBN:' + end +end diff --git a/spec/components/blacklight/document_metadata_component_spec.rb b/spec/components/blacklight/document_metadata_component_spec.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/components/blacklight/metadata_field_component_spec.rb b/spec/components/blacklight/metadata_field_component_spec.rb new file mode 100644 index 0000000000..4f48a8cc81 --- /dev/null +++ b/spec/components/blacklight/metadata_field_component_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Blacklight::MetadataFieldComponent, type: :component do + subject(:render) do + render_inline(described_class.new(field: field)) + end + + let(:view_context) { controller.view_context } + let(:document) { SolrDocument.new('field' => ['Value']) } + let(:field_config) { Blacklight::Configuration::Field.new(key: 'field', field: 'field', label: 'Field label') } + + let(:field) do + Blacklight::FieldPresenter.new(view_context, document, field_config) + end + + let(:rendered) do + Capybara::Node::Simple.new(render) + end + + it 'renders the field label' do + expect(rendered).to have_selector 'dt.blacklight-field', text: 'Field label' + end + + it 'renders the field value' do + expect(rendered).to have_selector 'dd.blacklight-field', text: 'Value' + end +end diff --git a/spec/helpers/blacklight_helper_spec.rb b/spec/helpers/blacklight_helper_spec.rb index 2e8640fa83..6e773c60b7 100644 --- a/spec/helpers/blacklight_helper_spec.rb +++ b/spec/helpers/blacklight_helper_spec.rb @@ -291,15 +291,18 @@ describe "#render_document_index_with_view" do let(:obj1) { SolrDocument.new } + let(:blacklight_config) { CatalogController.blacklight_config.deep_copy } before do - allow(helper).to receive(:blacklight_config).and_return(CatalogController.blacklight_config) + allow(helper).to receive(:blacklight_config).and_return(blacklight_config) assign(:response, instance_double(Blacklight::Solr::Response, grouped?: false, start: 0)) allow(helper).to receive(:link_to_document).and_return('') allow(helper).to receive(:render_index_doc_actions).and_return('
') end it "ignores missing templates" do + blacklight_config.view.view_type.partials = %w[index_header a b] + response = helper.render_document_index_with_view :view_type, [obj1, obj1] expect(response).to have_selector "div#documents" end diff --git a/spec/views/catalog/_document.html.erb_spec.rb b/spec/views/catalog/_document.html.erb_spec.rb index e6a4adf26f..dd787add0f 100644 --- a/spec/views/catalog/_document.html.erb_spec.rb +++ b/spec/views/catalog/_document.html.erb_spec.rb @@ -7,6 +7,7 @@ before do allow(view).to receive(:render_grouped_response?).and_return(false) allow(view).to receive(:blacklight_config).and_return(blacklight_config) + assign(:response, instance_double(Blacklight::Solr::Response, start: 20)) end it "renders the header, thumbnail and index by default" do @@ -14,11 +15,10 @@ stub_template "catalog/_thumbnail.html.erb" => "thumbnail_default" stub_template "catalog/_index_default.html.erb" => "index_default" render partial: "catalog/document", locals: { document: document, document_counter: 1 } + expect(rendered).to have_selector 'article.document[@data-document-counter="22"]' expect(rendered).to match /document_header/ expect(rendered).to match /thumbnail_default/ expect(rendered).to match /index_default/ - expect(rendered).to have_selector('.document[@itemscope]') - expect(rendered).to have_selector('.document[@itemtype="http://schema.org/Thing"]') end it "uses the index.partials parameter to determine the partials to render" do @@ -31,16 +31,4 @@ expect(rendered).to match /b_partial/ expect(rendered).to match /c_partial/ end - - it 'has a css class with the document position' do - allow(view).to receive(:render_document_partials) - render partial: 'catalog/document', locals: { document: document, document_counter: 5 } - expect(rendered).to have_selector '.document-position-5' - end - - it 'has a data attribute with the document position' do - allow(view).to receive(:render_document_partials) - render partial: 'catalog/document', locals: { document: document, document_counter: 5 } - expect(rendered).to have_selector '.document[@data-document-counter="5"]' - end end