<%= render 'collection_description', presenter: @presenter %>
- <% if @presenter.collection_type_is_nestable? && @parent_collection_count > 0 %>
-
-
-
- <%= t('.parent_collection_header') %> (<%= @parent_collection_count %>)
-
-
+ <% if @presenter.collection_type_is_nestable? && @presenter.parent_collection_count > 0 %>
+
+
+ <%= t('.parent_collection_header') %> (<%= @presenter.parent_collection_count %>)
+
-
-
- <%= render 'show_parent_collections', collection: @parent_collections %>
-
+
+ <%= render 'show_parent_collections', presenter: @presenter %>
<% end %>
diff --git a/app/views/hyrax/dashboard/collections/_show_parent_collections.html.erb b/app/views/hyrax/dashboard/collections/_show_parent_collections.html.erb
index 8917b2f5ea..456788b6e5 100644
--- a/app/views/hyrax/dashboard/collections/_show_parent_collections.html.erb
+++ b/app/views/hyrax/dashboard/collections/_show_parent_collections.html.erb
@@ -1,15 +1,32 @@
-<% if @parent_collections.nil? || @parent_collections.empty? %>
-
<%= t('hyrax.collections.show.no_visible_parent_collections') %>
+<% if presenter.parent_collection_count <= 0 %>
+
<%= t('hyrax.collections.show.no_visible_parent_collections') %>
<% else %>
-
+
<% end %>
diff --git a/app/views/hyrax/dashboard/collections/show.html.erb b/app/views/hyrax/dashboard/collections/show.html.erb
index 98fa2c7900..110e0eb31b 100644
--- a/app/views/hyrax/dashboard/collections/show.html.erb
+++ b/app/views/hyrax/dashboard/collections/show.html.erb
@@ -19,8 +19,8 @@
- <% if @presenter.collection_type_is_nestable? %>
-
<%= t('.parent_collection_header') %> (<%= @parent_collection_count %>)
+ <% if @presenter.collection_type_is_nestable? && @presenter.parent_collection_count > 0 %>
+ <%= t('.parent_collection_header') %> (<%= @presenter.parent_collection_count %>)
<%= render 'hyrax/dashboard/collections/show_parent_collections', presenter: @presenter %>
diff --git a/config/locales/hyrax.en.yml b/config/locales/hyrax.en.yml
index a106f94b09..48fec3fce4 100644
--- a/config/locales/hyrax.en.yml
+++ b/config/locales/hyrax.en.yml
@@ -490,6 +490,8 @@ en:
no_visible_parent_collections: "There are no visible parent collections."
no_visible_subcollections: "There are no visible subcollections."
parent_collection_header: "Parent Collections"
+ show_less_parent_collections: "...show less"
+ show_more_parent_collections: "show more..."
subcollection_count: "Subcollections"
works_in_collection: "Works"
collection_type:
@@ -631,6 +633,8 @@ en:
parent_collection_header: "Parent Collections"
public_view_label: "Public view of Collection"
search_results: "Search Results within this Collection"
+ show_less_parent_collections: "...show less"
+ show_more_parent_collections: "show more..."
subcollection_count: "Subcollections"
collection_type_actions:
close: "Close"
diff --git a/spec/presenters/hyrax/collection_presenter_spec.rb b/spec/presenters/hyrax/collection_presenter_spec.rb
index e027e573e6..53e00dc00f 100644
--- a/spec/presenters/hyrax/collection_presenter_spec.rb
+++ b/spec/presenters/hyrax/collection_presenter_spec.rb
@@ -274,6 +274,130 @@
it { is_expected.to eq '0 Bytes' }
end
+ describe "#parent_collection_count" do
+ subject { presenter.parent_collection_count }
+
+ context('when parent_collections is nil') do
+ before do
+ allow(presenter).to receive(:parent_collections).and_return(nil)
+ end
+
+ it { is_expected.to eq 0 }
+ end
+
+ context('when parent_collections is has no collections') do
+ before do
+ allow(presenter).to receive(:parent_collections).and_return([])
+ end
+
+ it { is_expected.to eq 0 }
+ end
+
+ context('when parent_collections is has collections') do
+ let(:collection1) { build(:collection, title: ['col1']) }
+ let(:collection2) { build(:collection, title: ['col2']) }
+ let!(:parent_collections) { [collection1, collection2] }
+
+ before do
+ presenter.parent_collections = parent_collections
+ end
+
+ it { is_expected.to eq 2 }
+ end
+ end
+
+ describe "#more_parent_collections?" do
+ subject { presenter.more_parent_collections? }
+
+ context('when parent_collections is has no collections') do
+ before do
+ allow(presenter).to receive(:parent_collection_count).and_return(0)
+ end
+
+ it { is_expected.to eq false }
+ end
+
+ context('when parent_collections has less than or equal to show limit') do
+ before do
+ allow(presenter).to receive(:parent_collection_count).and_return(3)
+ end
+
+ it { is_expected.to eq false }
+ end
+
+ context('when parent_collections has more than show limit') do
+ before do
+ allow(presenter).to receive(:parent_collection_count).and_return(4)
+ end
+
+ it { is_expected.to eq true }
+ end
+ end
+
+ describe "#visible_parent_collections" do
+ subject { presenter.visible_parent_collections }
+
+ let(:collection1) { build(:collection, title: ['col1']) }
+ let(:collection2) { build(:collection, title: ['col2']) }
+ let(:collection3) { build(:collection, title: ['col3']) }
+ let(:collection4) { build(:collection, title: ['col4']) }
+ let(:collection5) { build(:collection, title: ['col5']) }
+
+ before do
+ presenter.parent_collections = parent_collections
+ end
+
+ context('when parent_collections is nil') do
+ let(:parent_collections) { nil }
+
+ it { is_expected.to eq [] }
+ end
+
+ context('when parent_collections has less than or equal to show limit') do
+ let(:parent_collections) { [collection1, collection2, collection3] }
+
+ it { is_expected.to include(collection1, collection2, collection3) }
+ end
+
+ context('when parent_collections has more than show limit') do
+ let(:parent_collections) { [collection1, collection2, collection3, collection4, collection5] }
+
+ it { is_expected.to include(collection1, collection2, collection3) }
+ end
+ end
+
+ describe "#more_parent_collections" do
+ subject { presenter.more_parent_collections }
+
+ let(:collection1) { build(:collection, title: ['col1']) }
+ let(:collection2) { build(:collection, title: ['col2']) }
+ let(:collection3) { build(:collection, title: ['col3']) }
+ let(:collection4) { build(:collection, title: ['col4']) }
+ let(:collection5) { build(:collection, title: ['col5']) }
+
+ before do
+ presenter.parent_collections = parent_collections
+ end
+
+ context('when parent_collections is nil') do
+ let(:parent_collections) { nil }
+
+ it { is_expected.to eq [] }
+ end
+
+ context('when parent_collections has less than or equal to show limit') do
+ let(:parent_collections) { [collection1, collection2, collection3] }
+
+ it { is_expected.to eq [] }
+ end
+
+ context('when parent_collections has more than show limit') do
+ let(:parent_collections) { [collection1, collection2, collection3, collection4, collection5] }
+
+ it { is_expected.to include(collection4, collection5) }
+ end
+ end
+
describe "#user_can_nest_collection?" do
before do
allow(ability).to receive(:can?).with(:deposit, solr_doc).and_return(true)
diff --git a/spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb b/spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb
index 497c3040e5..11294e63b9 100644
--- a/spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb
+++ b/spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb
@@ -1,36 +1,68 @@
RSpec.describe 'hyrax/collections/_show_parent_collections.html.erb', type: :view do
- let(:collection) { build(:named_collection, id: '123') }
+ let(:collection_doc) do
+ {
+ id: '999',
+ "has_model_ssim" => ["Collection"],
+ "title_tesim" => ["Title 1"],
+ 'date_created_tesim' => '2000-01-01'
+ }
+ end
+ let(:ability) { double }
+ let(:solr_document) { SolrDocument.new(collection_doc) }
+ let(:presenter) { Hyrax::CollectionPresenter.new(solr_document, ability) }
+ let(:collection1) { build(:collection, id: 'col1', title: ['col1']) }
+ let(:collection2) { build(:collection, id: 'col2', title: ['col2']) }
+ let(:collection3) { build(:collection, id: 'col3', title: ['col3']) }
+ let(:collection4) { build(:collection, id: 'col4', title: ['col4']) }
+ let(:collection5) { build(:collection, id: 'col5', title: ['col5']) }
- context 'when parent collection list is empty' do
- let(:parentcollection) { nil }
+ before do
+ assign(:presenter, presenter)
+ presenter.parent_collections = parent_collections
- before do
- assign(:parent_collections, parentcollection)
- end
+ allow(collection1).to receive(:persisted?).and_return true
+ allow(collection2).to receive(:persisted?).and_return true
+ allow(collection3).to receive(:persisted?).and_return true
+ allow(collection4).to receive(:persisted?).and_return true
+ allow(collection5).to receive(:persisted?).and_return true
+
+ render('show_parent_collections.html.erb', presenter: presenter)
+ end
+
+ context 'when parent collection list is empty' do
+ let(:parent_collections) { nil }
it "posts a warning message" do
- render('show_parent_collections.html.erb', collection: parentcollection)
expect(rendered).to have_text("There are no visible parent collections.")
end
end
context 'when parent collection list is not empty' do
- let(:parentcollection) { [collection] }
-
- before do
- assign(:parent_collections, parentcollection)
- assign(:document, collection)
- allow(collection).to receive(:title_or_label).and_return(collection.title)
- allow(collection).to receive(:persisted?).and_return true
- render('show_parent_collections.html.erb', collection: parentcollection)
- end
+ let(:parent_collections) { [collection1, collection2, collection3] }
it "posts the collection's title with a link to the collection" do
- expect(rendered).to have_link(collection.title.first)
+ expect(rendered).to have_link(collection1.title.first, visible: true)
+ expect(rendered).to have_link(collection2.title.first, visible: true)
+ expect(rendered).to have_link(collection3.title.first, visible: true)
+ expect(rendered).not_to have_button('show more...')
end
xit 'includes a count of the parent collections' do
# TODO: add test when actual count is added to page
end
end
+
+ context 'when parent collection list exceeds parents_to_show' do
+ let(:parent_collections) { [collection1, collection2, collection3, collection4, collection5] }
+
+ it "posts the collection's title with a link to the collection" do
+ expect(rendered).to have_link(collection1.title.first, visible: true)
+ expect(rendered).to have_link(collection2.title.first, visible: true)
+ expect(rendered).to have_link(collection3.title.first, visible: true)
+ expect(rendered).to have_link(collection4.title.first, visible: false)
+ expect(rendered).to have_link(collection5.title.first, visible: false)
+ expect(rendered).to have_button('show more...', visible: true)
+ expect(rendered).to have_button('...show less', visible: false)
+ end
+ end
end
diff --git a/spec/views/hyrax/dashboard/collections/_show_parent_collections.html.erb_spec.rb b/spec/views/hyrax/dashboard/collections/_show_parent_collections.html.erb_spec.rb
index 92fcecddcf..fd1b0598e8 100644
--- a/spec/views/hyrax/dashboard/collections/_show_parent_collections.html.erb_spec.rb
+++ b/spec/views/hyrax/dashboard/collections/_show_parent_collections.html.erb_spec.rb
@@ -1,36 +1,68 @@
RSpec.describe 'hyrax/dashboard/collections/_show_parent_collections.html.erb', type: :view do
- let(:collection) { build(:named_collection, id: '123') }
+ let(:collection_doc) do
+ {
+ id: '999',
+ "has_model_ssim" => ["Collection"],
+ "title_tesim" => ["Title 1"],
+ 'date_created_tesim' => '2000-01-01'
+ }
+ end
+ let(:ability) { double }
+ let(:solr_document) { SolrDocument.new(collection_doc) }
+ let(:presenter) { Hyrax::CollectionPresenter.new(solr_document, ability) }
+ let(:collection1) { build(:collection, id: 'col1', title: ['col1']) }
+ let(:collection2) { build(:collection, id: 'col2', title: ['col2']) }
+ let(:collection3) { build(:collection, id: 'col3', title: ['col3']) }
+ let(:collection4) { build(:collection, id: 'col4', title: ['col4']) }
+ let(:collection5) { build(:collection, id: 'col5', title: ['col5']) }
- context 'when parent collection list is empty' do
- let(:parentcollection) { nil }
+ before do
+ assign(:presenter, presenter)
+ presenter.parent_collections = parent_collections
- before do
- assign(:parent_collections, parentcollection)
- end
+ allow(collection1).to receive(:persisted?).and_return true
+ allow(collection2).to receive(:persisted?).and_return true
+ allow(collection3).to receive(:persisted?).and_return true
+ allow(collection4).to receive(:persisted?).and_return true
+ allow(collection5).to receive(:persisted?).and_return true
+
+ render('show_parent_collections.html.erb', presenter: presenter)
+ end
+
+ context 'when parent collection list is empty' do
+ let(:parent_collections) { nil }
it "posts a warning message" do
- render('show_parent_collections.html.erb', collection: parentcollection)
expect(rendered).to have_text("There are no visible parent collections.")
end
end
context 'when parent collection list is not empty' do
- let(:parentcollection) { [collection] }
-
- before do
- assign(:parent_collections, parentcollection)
- assign(:document, collection)
- allow(collection).to receive(:title_or_label).and_return(collection.title)
- allow(collection).to receive(:persisted?).and_return true
- render('show_parent_collections.html.erb', collection: parentcollection)
- end
+ let(:parent_collections) { [collection1, collection2, collection3] }
it "posts the collection's title with a link to the collection" do
- expect(rendered).to have_link(collection.title.first)
+ expect(rendered).to have_link(collection1.title.first, visible: true)
+ expect(rendered).to have_link(collection2.title.first, visible: true)
+ expect(rendered).to have_link(collection3.title.first, visible: true)
+ expect(rendered).not_to have_button('show more...')
end
xit 'includes a count of the parent collections' do
# TODO: add test when actual count is added to page
end
end
+
+ context 'when parent collection list exceeds parents_to_show' do
+ let(:parent_collections) { [collection1, collection2, collection3, collection4, collection5] }
+
+ it "posts the collection's title with a link to the collection" do
+ expect(rendered).to have_link(collection1.title.first, visible: true)
+ expect(rendered).to have_link(collection2.title.first, visible: true)
+ expect(rendered).to have_link(collection3.title.first, visible: true)
+ expect(rendered).to have_link(collection4.title.first, visible: false)
+ expect(rendered).to have_link(collection5.title.first, visible: false)
+ expect(rendered).to have_button('show more...', visible: true)
+ expect(rendered).to have_button('...show less', visible: false)
+ end
+ end
end