-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test form views with ChangeSet style form objects--create
recent work has extended the ChangeSet style `Hyrax::ResourceForm` to support most of the view behavior for work create forms. this adds tests of the relevant form partials with the new form object. the partial that handles collection membership is stubbed, since its behavior is more complex and reproducing it in the new form should be considered separately. likewise, tests for these partials as an edit form (for existing objects) are left out; mainly because versions/optimistic locking becomes an issue in this case. there's more groundwork to lay there. to support this, a registration step is added to the new model generator. this sets up the routes when we bulid the test app.
- Loading branch information
tom johnson
committed
May 12, 2020
1 parent
3d5984c
commit 75466ce
Showing
3 changed files
with
124 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
15 | ||
16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,127 @@ | ||
RSpec.describe 'hyrax/base/_form.html.erb', type: :view do | ||
let(:work) do | ||
stub_model(GenericWork, id: '456') | ||
end | ||
let(:ability) { double } | ||
|
||
let(:form) do | ||
Hyrax::GenericWorkForm.new(work, ability, controller) | ||
end | ||
let(:controller_action) { 'new' } | ||
let(:controller_class) { Hyrax::MonographsController } | ||
let(:options_presenter) { double(select_options: []) } | ||
|
||
before do | ||
# mock the admin set options presenter to avoid hitting Solr | ||
allow(Hyrax::AdminSetOptionsPresenter).to receive(:new).and_return(options_presenter) | ||
stub_template('hyrax/base/_form_progress.html.erb' => 'Progress') | ||
# TODO: stub_model is not stubbing new_record? correctly on ActiveFedora models. | ||
allow(work).to receive(:new_record?).and_return(true) | ||
allow(work).to receive(:member_ids).and_return([1, 2]) | ||
allow(view).to receive(:curation_concern).and_return(work) | ||
allow(controller).to receive(:current_user).and_return(stub_model(User)) | ||
assign(:form, form) | ||
allow(controller).to receive(:controller_name).and_return('batch_uploads') | ||
allow(controller).to receive(:action_name).and_return('new') | ||
allow(controller).to receive(:repository).and_return(Hyrax::GenericWorksController.new.repository) | ||
allow(controller).to receive(:blacklight_config).and_return(Hyrax::GenericWorksController.new.blacklight_config) | ||
|
||
allow(form).to receive(:permissions).and_return([]) | ||
allow(form).to receive(:visibility).and_return('public') | ||
stub_template 'hyrax/base/_form_files.html.erb' => 'files' | ||
allow(controller).to receive(:action_name).and_return(controller_action) | ||
allow(controller).to receive(:repository).and_return(controller_class.new.repository) | ||
allow(controller).to receive(:blacklight_config).and_return(controller_class.new.blacklight_config) | ||
end | ||
|
||
context "for a new object" do | ||
let(:work) { GenericWork.new } | ||
context 'with a change_set style form' do | ||
let(:form) { Hyrax::Forms::ResourceForm.for(work) } | ||
let(:work) { build(:monograph, title: 'comet in moominland') } | ||
|
||
context 'with batch_upload on' do | ||
before do | ||
allow(Flipflop).to receive(:batch_upload?).and_return(true) | ||
before do | ||
# TODO: unstub these when they are supported by the form | ||
stub_template('hyrax/base/_form_member_of_collections.html.erb' => 'collection membership') | ||
end | ||
|
||
context 'for a new object' do | ||
it 'renders a form' do | ||
render | ||
|
||
expect(rendered).to have_selector("form[action='/concern/monographs']") | ||
end | ||
it 'shows batch uploads' do | ||
expect(rendered).to have_link('Batch upload', href: hyrax.new_batch_upload_path(payload_concern: 'GenericWork')) | ||
expect(rendered).to have_selector("form[action='/concern/generic_works'][data-param-key='generic_work']") | ||
# Draws the "Share" tab, with data for the javascript. | ||
expect(rendered).to have_selector('#share[data-param-key="generic_work"]') | ||
|
||
context 'with batch_upload off' do | ||
before do | ||
allow(Flipflop).to receive(:batch_upload?).and_return(false) | ||
end | ||
|
||
it 'hides batch uploads' do | ||
render | ||
expect(rendered).not_to have_link('Batch upload', href: hyrax.new_batch_upload_path(payload_concern: 'GenericWork')) | ||
end | ||
end | ||
end | ||
|
||
context 'with batch_upload off' do | ||
before do | ||
allow(Flipflop).to receive(:batch_upload?).and_return(false) | ||
context 'with an existing object' do | ||
let(:work) { FactoryBot.valkyrie_create(:monograph) } | ||
|
||
xit 'renders a form' do | ||
render | ||
end | ||
it 'hides batch uploads' do | ||
expect(rendered).not_to have_link('Batch upload', href: hyrax.new_batch_upload_path(payload_concern: 'GenericWork')) | ||
|
||
expect(rendered).to have_selector("form[action='/concern/monographs/#{work.id}']") | ||
end | ||
end | ||
end | ||
|
||
context "for a persisted object" do | ||
let(:work) { stub_model(GenericWork, id: '456') } | ||
context 'with a legacy GenericWork' do | ||
let(:work) do | ||
stub_model(GenericWork, id: '456') | ||
end | ||
let(:ability) { double } | ||
|
||
let(:form) do | ||
Hyrax::GenericWorkForm.new(work, ability, controller) | ||
end | ||
|
||
before do | ||
# Add an error to the work | ||
work.errors.add :base, 'broken' | ||
work.errors.add :visibility, 'visibility_error' | ||
allow(form).to receive(:select_files).and_return([]) | ||
render | ||
stub_template('hyrax/base/_form_progress.html.erb' => 'Progress') | ||
# TODO: stub_model is not stubbing new_record? correctly on ActiveFedora models. | ||
allow(work).to receive(:new_record?).and_return(true) | ||
allow(work).to receive(:member_ids).and_return([1, 2]) | ||
allow(view).to receive(:curation_concern).and_return(work) | ||
allow(controller).to receive(:controller_name).and_return('batch_uploads') | ||
allow(form).to receive(:permissions).and_return([]) | ||
allow(form).to receive(:visibility).and_return('public') | ||
stub_template 'hyrax/base/_form_files.html.erb' => 'files' | ||
end | ||
|
||
context "for a new object" do | ||
let(:work) { GenericWork.new } | ||
|
||
context 'with batch_upload on' do | ||
before do | ||
allow(Flipflop).to receive(:batch_upload?).and_return(true) | ||
render | ||
end | ||
it 'shows batch uploads' do | ||
expect(rendered).to have_link('Batch upload', href: hyrax.new_batch_upload_path(payload_concern: 'GenericWork')) | ||
expect(rendered).to have_selector("form[action='/concern/generic_works'][data-param-key='generic_work']") | ||
# Draws the "Share" tab, with data for the javascript. | ||
expect(rendered).to have_selector('#share[data-param-key="generic_work"]') | ||
end | ||
end | ||
|
||
context 'with batch_upload off' do | ||
before do | ||
allow(Flipflop).to receive(:batch_upload?).and_return(false) | ||
render | ||
end | ||
it 'hides batch uploads' do | ||
expect(rendered).not_to have_link('Batch upload', href: hyrax.new_batch_upload_path(payload_concern: 'GenericWork')) | ||
end | ||
end | ||
end | ||
|
||
it "draws the page" do | ||
expect(rendered).to have_selector("form[action='/concern/generic_works/456']") | ||
expect(rendered).to have_selector("select#generic_work_resource_type", count: 1) | ||
expect(rendered).to have_selector("select#generic_work_thumbnail_id", count: 1) | ||
expect(rendered).to have_selector("select#generic_work_representative_id", count: 1) | ||
context "for a persisted object" do | ||
let(:work) { stub_model(GenericWork, id: '456') } | ||
|
||
# It diplays form errors | ||
expect(rendered).to have_content("broken") | ||
expect(rendered).to have_content("visibility_error") | ||
before do | ||
# Add an error to the work | ||
work.errors.add :base, 'broken' | ||
work.errors.add :visibility, 'visibility_error' | ||
allow(form).to receive(:select_files).and_return([]) | ||
render | ||
end | ||
|
||
it "draws the page" do | ||
expect(rendered).to have_selector("form[action='/concern/generic_works/456']") | ||
expect(rendered).to have_selector("select#generic_work_resource_type", count: 1) | ||
expect(rendered).to have_selector("select#generic_work_thumbnail_id", count: 1) | ||
expect(rendered).to have_selector("select#generic_work_representative_id", count: 1) | ||
|
||
# It diplays form errors | ||
expect(rendered).to have_content("broken") | ||
expect(rendered).to have_content("visibility_error") | ||
end | ||
end | ||
end | ||
end |