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

Fix collection view specs for koppie #6348

Merged
merged 1 commit into from
Oct 10, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe 'collections/edit_fields/_based_near.html.erb', type: :view do
let(:collection) { Collection.new }
let(:form) { Hyrax::Forms::CollectionForm.new(collection, nil, controller) }
let(:collection) { build :collection_resource }
let(:form) { Hyrax::Forms::ResourceForm.for(collection) }
let(:form_template) do
%(
<%= simple_form_for @form, url: [hyrax, :dashboard, @form] do |f| %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@
let(:user) { create(:user) }

let(:work) do
mock_model(GenericWork, label: 'One Hundred Years of Solitude', date_uploaded: '1999',
collection?: true, visibility: 'open',
title: ['One Hundred Years of Solitude'],
depositor: user,
edit_groups: [],
creator: ["ggm"])
build(:monograph,
label: 'One Hundred Years of Solitude',
date_uploaded: '1999',
visibility_setting: 'open',
title: 'One Hundred Years of Solitude',
depositor: user.user_key,
edit_groups: [],
creator: ["ggm"])
end

let(:collection) { mock_model(Collection, title: 'My awesome collection', members: [work]) }
let(:solr_doc) { ::SolrDocument.new(Hyrax::ValkyrieIndexer.for(resource: work).to_solr) }

let(:collection) { build(:hyrax_collection, title: 'My awesome collection', members: [work]) }

context 'when not logged in' do
before do
view.blacklight_config = Blacklight::Configuration.new
assign(:presenter, collection)
allow(view).to receive(:current_user).and_return(nil)
allow(work).to receive(:title_or_label).and_return("One Hundred Years of Solitude")
allow(work).to receive(:edit_people).and_return([])
allow(view).to receive(:render_other_collection_links).and_return([])
end

it "renders collections links" do
render('hyrax/collections/show_document_list_row.html.erb', document: work)
render('hyrax/collections/show_document_list_row.html.erb', document: solr_doc)
expect(rendered).not_to have_content 'My awesome collection'
end

it "renders works" do
render('hyrax/collections/show_document_list_row.html.erb', document: work)
render('hyrax/collections/show_document_list_row.html.erb', document: solr_doc)
expect(rendered).to have_content 'One Hundred Years of Solitude'
expect(rendered).not_to have_content('Edit Access:')
end
Expand Down
4 changes: 2 additions & 2 deletions spec/views/hyrax/dashboard/collections/_form.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe 'hyrax/dashboard/collections/_form.html.erb', type: :view do
let(:collection) { Collection.new }
let(:collection_form) { Hyrax::Forms::CollectionForm.new(collection, double, double) }
let(:collection) { build :collection_resource }
let(:collection_form) { Hyrax::Forms::ResourceForm.for(collection) }
let(:banner_info) { { file: "banner.gif", alttext: "Banner alt text" } }
let(:logo_info) { [{ file: "logo.gif", alttext: "Logo alt text", linkurl: "http://abc.com" }] }

Expand Down
35 changes: 19 additions & 16 deletions spec/views/hyrax/dashboard/collections/_form_discovery.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true
RSpec.describe 'hyrax/dashboard/collections/_form_discovery.html.erb', type: :view do
let(:collection) { Collection.new }
let(:form) { Hyrax::Forms::CollectionForm.new(collection, double, double) }
let(:f) do
view.simple_form_for(form, url: '/update') do |fs_form|
return fs_form
Expand All @@ -14,27 +12,32 @@
render
end

context "collection has open access" do
let(:visibility) { 'open' }
context 'with AF Collection', :active_fedora do
let(:collection) { Collection.new }
let(:form) { Hyrax::Forms::CollectionForm.new(collection, double, double) }

it "check open access is set" do
expect(rendered).to have_selector('input[type=radio][name="collection[visibility]"][value=open][checked]')
context "collection has open access" do
let(:visibility) { 'open' }

it "check open access is set" do
expect(rendered).to have_selector('input[type=radio][name="collection[visibility]"][value=open][checked]')
end
end
end

context "collection has authenticated access" do
let(:visibility) { 'authenticated' }
context "collection has authenticated access" do
let(:visibility) { 'authenticated' }

it "check authenticated access is set" do
expect(rendered).to have_selector('input[type=radio][name="collection[visibility]"][value=authenticated][checked]')
it "check authenticated access is set" do
expect(rendered).to have_selector('input[type=radio][name="collection[visibility]"][value=authenticated][checked]')
end
end
end

context "collection has restricted access" do
let(:visibility) { 'restricted' }
context "collection has restricted access" do
let(:visibility) { 'restricted' }

it "restricted access is set" do
expect(rendered).to have_selector('input[type=radio][name="collection[visibility]"][value=restricted][checked]')
it "restricted access is set" do
expect(rendered).to have_selector('input[type=radio][name="collection[visibility]"][value=restricted][checked]')
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
allow(view)
.to receive(:available_parent_collections_data)
.with(collection: presenter)
.and_return([mock_model(Collection)])
.and_return([build(:hyrax_collection)])

stub_template 'hyrax/my/_collection_action_menu.html.erb' => 'actions'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@
let(:user) { create(:user) }

let(:work) do
mock_model(GenericWork, label: 'One Hundred Years of Solitude', date_uploaded: '1999',
collection?: true, visibility: 'open',
title: ['One Hundred Years of Solitude'],
depositor: user,
edit_groups: [],
creator: ["ggm"])
build(:monograph,
label: 'One Hundred Years of Solitude',
date_uploaded: '1999',
visibility_setting: 'open',
title: 'One Hundred Years of Solitude',
depositor: user.user_key,
edit_groups: [],
creator: ["ggm"])
end

let(:collection) { mock_model(Collection, title: 'My awesome collection', members: [work]) }
let(:solr_doc) { ::SolrDocument.new(Hyrax::ValkyrieIndexer.for(resource: work).to_solr) }

let(:collection) { build(:hyrax_collection, title: 'My awesome collection', members: [work]) }

context 'when not logged in' do
before do
view.blacklight_config = Blacklight::Configuration.new
assign(:presenter, collection)
allow(view).to receive(:current_user).and_return(nil)
allow(work).to receive(:title_or_label).and_return("One Hundred Years of Solitude")
allow(work).to receive(:edit_people).and_return([])
allow(view).to receive(:render_other_collection_links).and_return([])
end

it "renders collections links" do
render('show_document_list_row', document: work)
render('show_document_list_row', document: solr_doc)
expect(rendered).not_to have_content 'My awesome collection'
end

it "renders works" do
render('show_document_list_row', document: work)
render('show_document_list_row', document: solr_doc)
expect(rendered).to have_content 'One Hundred Years of Solitude'
expect(rendered).to have_content('Edit Access:')
end
Expand Down
4 changes: 2 additions & 2 deletions spec/views/hyrax/dashboard/collections/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true
RSpec.describe 'hyrax/dashboard/collections/edit.html.erb', type: :view do
let(:collection_type) { stub_model(Hyrax::CollectionType) }
let(:collection) { stub_model(Collection, id: 'xyz123z4', title: ["Make Collections Great Again"]) }
let(:form) { Hyrax::Forms::CollectionForm.new(collection, double, double) }
let(:collection) { build :hyrax_collection }
let(:form) { Hyrax::Forms::ResourceForm.for(collection) }

before do
assign(:collection, collection)
Expand Down