Skip to content

Commit

Permalink
Merge pull request #6344 from samvera/valk_base_view_specs
Browse files Browse the repository at this point in the history
Fix Valkyrie base view specs
  • Loading branch information
dlpierce authored Oct 10, 2023
2 parents 8cfe295 + ebdaea2 commit ef530d7
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 44 deletions.
3 changes: 2 additions & 1 deletion app/views/hyrax/base/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
@curation_concern = ::Wings::ActiveFedoraConverter.convert(resource: @curation_concern) if
@curation_concern.is_a?(Hyrax::Resource) && Object.const_defined?("Wings")

json.extract! @curation_concern, *[:id] + @curation_concern.class.fields.reject { |f| [:has_model].include? f }
json.extract! @curation_concern, *@curation_concern.class.fields.reject { |f| [:has_model].include? f }
json.id @curation_concern.id.to_s
json.version @curation_concern.try(:etag)
4 changes: 4 additions & 0 deletions lib/hyrax/resource_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ def initialize(klass, namespace = nil, name = nil)
@route_key = legacy_model.model_name.route_key
@singular_route_key = legacy_model.model_name.singular_route_key
end

def human
super.titleize
end
end
end
10 changes: 9 additions & 1 deletion spec/hyrax/resource_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
expect(name.singular_route_key).to start_with 'hyrax_'
end

context 'when a legacy resource is registered with Wings' do
it 'has a titleized human name' do
expect(name.human).to eq name.human.titleize
end

context 'when a legacy resource is registered with Wings', :active_fedora do
let(:work_class) { Hyrax::Test::BookResource }

it 'uses the legacy route key' do
Expand All @@ -22,5 +26,9 @@
it 'uses the legacy singular route key' do
expect(name.singular_route_key).to eq 'test_book'
end

it 'has a titleized human name' do
expect(name.human).to eq name.human.titleize
end
end
end
42 changes: 22 additions & 20 deletions spec/views/hyrax/base/_currently_shared.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@
RSpec.describe 'hyrax/base/_currently_shared.html.erb', type: :view do
let(:user) { stub_model(User) }

let(:work) do
stub_model(GenericWork, id: '456')
before do
allow(controller).to receive(:current_user).and_return(user)
allow(work).to receive(:depositor).and_return(user)
end

let(:file_set) do
stub_model(FileSet, id: '123',
depositor: 'bob',
resource_type: ['Dataset'], in_works: [work])
end
context 'with ActiveFedora', :active_fedora do
let(:work) do
stub_model(GenericWork, id: '456')
end

let(:file_set_form) do
view.simple_form_for(file_set, url: '/update') do |fs_form|
return fs_form
let(:file_set) do
stub_model(FileSet, id: '123',
depositor: 'bob',
resource_type: ['Dataset'], in_works: [work])
end
end

before do
allow(controller).to receive(:current_user).and_return(user)
allow(work).to receive(:depositor).and_return(user)
end
let(:file_set_form) do
view.simple_form_for(file_set, url: '/update') do |fs_form|
return fs_form
end
end

it "draws the permissions form without error" do
render partial: 'hyrax/base/currently_shared', locals: { f: file_set_form }
it "draws the permissions form without error" do
render partial: 'hyrax/base/currently_shared', locals: { f: file_set_form }

# actual testing of who gets what permission access is done in
# the EditPermissionsService (is it?!)
expect(rendered).to have_content("Depositor")
# actual testing of who gets what permission access is done in
# the EditPermissionsService (is it?!)
expect(rendered).to have_content("Depositor")
end
end

context "with ResourceForm", valkyrie_adapter: :test_adapter do
Expand Down
2 changes: 1 addition & 1 deletion spec/views/hyrax/base/_form_files.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/base/_form_files.html.erb', type: :view do
let(:model) { stub_model(GenericWork) }
let(:form) { Hyrax::GenericWorkForm.new(model, double, controller) }
let(:form) { Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(model) : Hyrax::GenericWorkForm.new(model, double, controller) }
let(:f) { double(object: form) }

before do
Expand Down
4 changes: 1 addition & 3 deletions spec/views/hyrax/base/_form_metadata.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
end
let(:ability) { double }
let(:work) { GenericWork.new }
let(:form) do
Hyrax::GenericWorkForm.new(work, ability, controller)
end
let(:form) { Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(work) : Hyrax::GenericWorkForm.new(work, ability, controller) }

let(:form_template) do
%(
Expand Down
10 changes: 7 additions & 3 deletions spec/views/hyrax/base/_form_progress.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let(:ability) { double }
let(:user) { stub_model(User) }
let(:form) do
Hyrax::GenericWorkForm.new(work, ability, controller)
Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(work).prepopulate! : Hyrax::GenericWorkForm.new(work, ability, controller)
end
let(:page) do
view.simple_form_for form do |f|
Expand Down Expand Up @@ -116,16 +116,20 @@
context "when the work has been saved before" do
before do
# TODO: stub_model is not stubbing new_record? correctly on ActiveFedora models.
allow(work).to receive(:new_record?).and_return(false)
allow(work).to receive_messages(new_record?: false, new_record: false)
assign(:form, form)
allow(Hyrax.config).to receive(:active_deposit_agreement_acceptance)
.and_return(true)
end

let(:work) { stub_model(GenericWork, id: '456', etag: '123456') }

it "renders the deposit agreement already checked and the version" do
it "renders the deposit agreement already checked" do
expect(page).to have_selector("#agreement[checked]")
end

# Not applicable without wings; see Hyrax::Forms::ResourceForm::LockKeyPrepopulator
it 'renders the version', :active_fedora do
expect(page).to have_selector("input#generic_work_version[value=\"123456\"]", visible: false)
end
end
Expand Down
4 changes: 1 addition & 3 deletions spec/views/hyrax/base/_form_rendering.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
RSpec.describe 'hyrax/base/_form_rendering.html.erb', type: :view do
let(:ability) { double }
let(:work) { stub_model(GenericWork, new_record?: false) }
let(:form) do
Hyrax::GenericWorkForm.new(work, ability, controller)
end
let(:form) { Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(work) : Hyrax::GenericWorkForm.new(work, ability, controller) }

let(:page) do
view.simple_form_for form do |f|
Expand Down
4 changes: 1 addition & 3 deletions spec/views/hyrax/base/_form_share.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
let(:ability) { instance_double(Ability, admin?: false, user_groups: [], current_user: user) }
let(:user) { stub_model(User) }
let(:work) { GenericWork.new }
let(:form) do
Hyrax::GenericWorkForm.new(work, ability, controller)
end
let(:form) { Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(work) : Hyrax::GenericWorkForm.new(work, ability, controller) }
let(:form_template) do
%(
<%= simple_form_for [main_app, @form] do |f| %>
Expand Down
9 changes: 3 additions & 6 deletions spec/views/hyrax/base/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
let(:work) { stub_model(GenericWork, id: '456', title: ["A nice work"]) }
let(:ability) { double }
let(:controller_class) { Hyrax::GenericWorksController }

let(:form) do
Hyrax::GenericWorkForm.new(work, ability, controller)
end
let(:form) { Hyrax.config.disable_wings ? Hyrax::Forms::ResourceForm.for(work) : Hyrax::GenericWorkForm.new(work, ability, controller) }

before do
allow(view).to receive(:curation_concern).and_return(work)
Expand All @@ -19,7 +16,7 @@
end

it "sets a header and draws the form" do
expect(view).to receive(:provide).with(:page_title, 'A nice work // Generic Work [456] // Hyrax')
expect(view).to receive(:provide).with(:page_title, "A nice work // Generic Work [456] // #{I18n.t('hyrax.product_name')}")
expect(view).to receive(:provide).with(:page_header).and_yield
render
expect(rendered).to eq " <h1><span class=\"fa fa-edit\" aria-hidden=\"true\"></span>Edit Work</h1>\n\na form\n"
Expand All @@ -31,7 +28,7 @@
let(:controller_class) { Hyrax::MonographsController }

it "sets a header and draws the form" do
expect(view).to receive(:provide).with(:page_title, "comet in moominland // Simple work [#{work.id}] // Hyrax")
expect(view).to receive(:provide).with(:page_title, "comet in moominland // Simple Work [#{work.id}] // #{I18n.t('hyrax.product_name')}")
expect(view).to receive(:provide).with(:page_header).and_yield
render
expect(rendered).to eq " <h1><span class=\"fa fa-edit\" aria-hidden=\"true\"></span>Edit Work</h1>\n\na form\n"
Expand Down
4 changes: 2 additions & 2 deletions spec/views/hyrax/base/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
describe 'head tag page title' do
it 'appears in head tags' do
head_tag = Nokogiri::HTML(rendered).xpath("//head/title")
expect(head_tag.text).to eq("Work | My Title | ID: 999 | Hyrax")
expect(head_tag.text).to eq("Work | My Title | ID: 999 | #{I18n.t('hyrax.product_name')}")
end
end

Expand Down Expand Up @@ -193,7 +193,7 @@
expect(tag.attribute('content').value).to eq('@bot4lib')

tag = Nokogiri::HTML(rendered).xpath("//meta[@property='og:site_name']")
expect(tag.attribute('content').value).to eq('Hyrax')
expect(tag.attribute('content').value).to eq(I18n.t('hyrax.product_name'))

tag = Nokogiri::HTML(rendered).xpath("//meta[@property='og:type']")
expect(tag.attribute('content').value).to eq('object')
Expand Down
2 changes: 1 addition & 1 deletion spec/views/hyrax/base/show.json.jbuilder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

it "renders json of the curation_concern" do
json = JSON.parse(rendered)
expect(json['id']).to eq curation_concern.id
expect(json['id']).to eq curation_concern.id.to_s
expect(json['title']).to match_array curation_concern.title
expected_fields = curation_concern.class.fields.reject { |f| [:has_model, :create_date].include? f }
expected_fields << :date_created
Expand Down

0 comments on commit ef530d7

Please sign in to comment.