From 3c2b0d93f33e78e2c84af26ab1eea74e7d6538dc Mon Sep 17 00:00:00 2001 From: Janell-Huyck Date: Thu, 7 Mar 2024 15:18:53 -0500 Subject: [PATCH 1/7] Enhance Test Stability with Improved Wait Mechanisms --- .ruby-gemset | 2 +- .../author_management/adding_authors_spec.rb | 4 +++- .../author_vs_artist_labels_spec.rb | 14 ++++++++++++++ .../author_management/updating_authors_spec.rb | 5 ++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.ruby-gemset b/.ruby-gemset index 971b5415..8d6c54aa 100644 --- a/.ruby-gemset +++ b/.ruby-gemset @@ -1 +1 @@ -aaec +aaec \ No newline at end of file diff --git a/spec/features/author_management/adding_authors_spec.rb b/spec/features/author_management/adding_authors_spec.rb index e89a4993..02707af0 100644 --- a/spec/features/author_management/adding_authors_spec.rb +++ b/spec/features/author_management/adding_authors_spec.rb @@ -25,7 +25,7 @@ # Click "Add Author" and verify new and old fields click_on 'Add Author' - + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) @@ -38,6 +38,7 @@ # Click "Add Author" again click_on 'Add Author' + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) check_field_values_by_index(0, 'First0', 'Last0') @@ -50,6 +51,7 @@ # Click "Add Author" again click_on 'Add Author' + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) check_field_values_by_index(0, 'First0', 'Last0') diff --git a/spec/features/author_management/author_vs_artist_labels_spec.rb b/spec/features/author_management/author_vs_artist_labels_spec.rb index e341c50e..49cd4960 100644 --- a/spec/features/author_management/author_vs_artist_labels_spec.rb +++ b/spec/features/author_management/author_vs_artist_labels_spec.rb @@ -15,16 +15,23 @@ it 'uses the title of Author for new books' do visit new_book_path + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_book_path) + expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) expect(page).to have_content('Add Author') expect(page).not_to have_content('Add Artist') first_name_fields.last.set('First0') last_name_fields.last.set('Last0') + click_on 'Add Author' + expect(page).to have_selector("input[name='book[author_first_name][]']", count: 2) first_name_fields.last.set('First1') last_name_fields.last.set('Last1') + click_on 'Add Author' + expect(page).to have_selector("input[name='book[author_first_name][]']", count: 3) expect(page).to have_selector('button', text: 'Remove Author', count: 2) expect(page).not_to have_selector('button', text: 'Remove Artist') + first('button', text: 'Remove Author').click expect(page).to have_selector('button', text: 'Remove Author', count: 1) expect(page).not_to have_content('Artist') @@ -32,16 +39,23 @@ it 'has the title of Artist for new artworks' do visit new_artwork_path + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_artwork_path) + expect(page).to have_selector("input[name='artwork[author_first_name][]']", visible: true) expect(page).to have_content('Add Artist') expect(page).not_to have_content('Add Author') first_name_fields.last.set('First0') last_name_fields.last.set('Last0') + click_on 'Add Artist' + expect(page).to have_selector("input[name='artwork[author_first_name][]']", count: 2) first_name_fields.last.set('First1') last_name_fields.last.set('Last1') + click_on 'Add Artist' + expect(page).to have_selector("input[name='artwork[author_first_name][]']", count: 3) expect(page).to have_selector('button', text: 'Remove Artist', count: 2) expect(page).not_to have_selector('button', text: 'Remove Author') + first('button', text: 'Remove Artist').click expect(page).to have_selector('button', text: 'Remove Artist', count: 1) expect(page).not_to have_content('Author') diff --git a/spec/features/author_management/updating_authors_spec.rb b/spec/features/author_management/updating_authors_spec.rb index 7037e7d2..deb24e43 100644 --- a/spec/features/author_management/updating_authors_spec.rb +++ b/spec/features/author_management/updating_authors_spec.rb @@ -40,6 +40,7 @@ create_other_publication add_three_more_authors_to_publication(OtherPublication.last) visit edit_other_publication_path(OtherPublication.last) + expect(page).to have_current_path(edit_other_publication_path(OtherPublication.last)) expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) check_field_values_by_index(0, 'First0', 'Last0') @@ -94,6 +95,7 @@ create_other_publication add_three_more_authors_to_publication(OtherPublication.last) visit edit_other_publication_path(OtherPublication.last) + expect(page).to have_current_path(edit_other_publication_path(OtherPublication.last)) expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) check_field_values_by_index(0, 'First0', 'Last0') @@ -112,7 +114,8 @@ last_name_fields.last.set('Last3modified') click_on 'Submit' - page.driver.browser.navigate.refresh + visit current_path + expect(page).to have_current_path(other_publication_path(OtherPublication.last)) expect(page).to have_text('First0modified Last0modified, First1modified Last1modified, First2modified Last2modified, First3modified Last3modified') end end From b65fa62675005e1e7158e4949041995a09254974 Mon Sep 17 00:00:00 2001 From: Janell-Huyck Date: Thu, 7 Mar 2024 16:24:10 -0500 Subject: [PATCH 2/7] Look for selector after clicking edit --- spec/features/author_management/adding_authors_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/features/author_management/adding_authors_spec.rb b/spec/features/author_management/adding_authors_spec.rb index 02707af0..a9047252 100644 --- a/spec/features/author_management/adding_authors_spec.rb +++ b/spec/features/author_management/adding_authors_spec.rb @@ -101,6 +101,7 @@ # Click on "Edit" and verify that we are redirected to the edit page # and that the author names are correct click_on 'Edit' + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) expect(page).to have_current_path(Rails.application.routes.url_helpers.edit_other_publication_path(OtherPublication.last.id)) check_field_values_by_index(0, 'First0', 'Last0') From d5ffaaea760fd0c6a2cc4274c72d6e2f862d6d1e Mon Sep 17 00:00:00 2001 From: Janell-Huyck Date: Thu, 7 Mar 2024 16:52:02 -0500 Subject: [PATCH 3/7] Add more wait selectors for author vs artist labels spec --- .../author_management/author_vs_artist_labels_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/features/author_management/author_vs_artist_labels_spec.rb b/spec/features/author_management/author_vs_artist_labels_spec.rb index 49cd4960..430ce417 100644 --- a/spec/features/author_management/author_vs_artist_labels_spec.rb +++ b/spec/features/author_management/author_vs_artist_labels_spec.rb @@ -15,6 +15,7 @@ it 'uses the title of Author for new books' do visit new_book_path + expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) expect(page).to have_current_path(Rails.application.routes.url_helpers.new_book_path) expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) expect(page).to have_content('Add Author') @@ -24,6 +25,7 @@ click_on 'Add Author' expect(page).to have_selector("input[name='book[author_first_name][]']", count: 2) + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_book_path) first_name_fields.last.set('First1') last_name_fields.last.set('Last1') @@ -39,8 +41,8 @@ it 'has the title of Artist for new artworks' do visit new_artwork_path - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_artwork_path) expect(page).to have_selector("input[name='artwork[author_first_name][]']", visible: true) + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_artwork_path) expect(page).to have_content('Add Artist') expect(page).not_to have_content('Add Author') first_name_fields.last.set('First0') From f9f3944069269aa1bbd5999d62d1381f5ab6bb25 Mon Sep 17 00:00:00 2001 From: Janell-Huyck Date: Thu, 7 Mar 2024 17:14:53 -0500 Subject: [PATCH 4/7] Use a 10-second wait on tests --- .../author_management/adding_authors_spec.rb | 230 +++++++++--------- .../author_vs_artist_labels_spec.rb | 80 +++--- .../removing_authors_spec.rb | 82 ++++--- .../updating_authors_spec.rb | 188 +++++++------- 4 files changed, 301 insertions(+), 279 deletions(-) diff --git a/spec/features/author_management/adding_authors_spec.rb b/spec/features/author_management/adding_authors_spec.rb index a9047252..edc04a8e 100644 --- a/spec/features/author_management/adding_authors_spec.rb +++ b/spec/features/author_management/adding_authors_spec.rb @@ -10,121 +10,125 @@ end it 'adds authors to a new publication' do - visit new_other_publication_path - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) - - # Verify blank input fields for author's first name and last name - # to be present on page load - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) - check_field_values_by_index(0, '', '') - - # Fill out the fields with the first author's name - first_name_fields.last.set('First0') - last_name_fields.last.set('Last0') - - # Click "Add Author" and verify new and old fields - click_on 'Add Author' - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) - - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, '', '') - - # Fill in second author's name - first_name_fields.last.set('First1') - last_name_fields.last.set('Last1') - - # Click "Add Author" again - click_on 'Add Author' - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, '', '') - - # Fill in third author's name - first_name_fields.last.set('First2') - last_name_fields.last.set('Last2') - - # Click "Add Author" again - click_on 'Add Author' - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - check_field_values_by_index(3, '', '') - - # Fill in fourth author's name - first_name_fields.last.set('First3') - last_name_fields.last.set('Last3') - - # Fill in the rest of the fields - fill_in 'other_publication[work_title]', with: 'Title' - fill_in 'other_publication[other_title]', with: 'Subtitle' - fill_in 'other_publication[uc_department]', with: 'Department' - fill_in 'other_publication[publication_date]', with: 'Date' - fill_in 'other_publication[url]', with: 'URL' - fill_in 'other_publication[doi]', with: 'DOI' - - # Click "Submit" and verify that we are redirected to the index page - # and that a success message is displayed - click_on 'Submit' - expect(page).to have_current_path(Rails.application.routes.url_helpers.publications_path) - expect(page).to have_text 'Other Publication was successfully created.' - - # Click on the hyperlink on the id of the newly created publication - # and verify that the author names are correct - click_on OtherPublication.last.work_title.to_s - expect(page).to have_current_path(Rails.application.routes.url_helpers.other_publication_path(OtherPublication.last.id)) - expect(page).to have_text 'First0 Last0' - expect(page).to have_text 'First1 Last1' - expect(page).to have_text 'First2 Last2' - expect(page).to have_text 'First3 Last3' + using_wait_time(10) do + visit new_other_publication_path + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) + + # Verify blank input fields for author's first name and last name + # to be present on page load + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) + check_field_values_by_index(0, '', '') + + # Fill out the fields with the first author's name + first_name_fields.last.set('First0') + last_name_fields.last.set('Last0') + + # Click "Add Author" and verify new and old fields + click_on 'Add Author' + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) + + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, '', '') + + # Fill in second author's name + first_name_fields.last.set('First1') + last_name_fields.last.set('Last1') + + # Click "Add Author" again + click_on 'Add Author' + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, '', '') + + # Fill in third author's name + first_name_fields.last.set('First2') + last_name_fields.last.set('Last2') + + # Click "Add Author" again + click_on 'Add Author' + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + check_field_values_by_index(3, '', '') + + # Fill in fourth author's name + first_name_fields.last.set('First3') + last_name_fields.last.set('Last3') + + # Fill in the rest of the fields + fill_in 'other_publication[work_title]', with: 'Title' + fill_in 'other_publication[other_title]', with: 'Subtitle' + fill_in 'other_publication[uc_department]', with: 'Department' + fill_in 'other_publication[publication_date]', with: 'Date' + fill_in 'other_publication[url]', with: 'URL' + fill_in 'other_publication[doi]', with: 'DOI' + + # Click "Submit" and verify that we are redirected to the index page + # and that a success message is displayed + click_on 'Submit' + expect(page).to have_current_path(Rails.application.routes.url_helpers.publications_path) + expect(page).to have_text 'Other Publication was successfully created.' + + # Click on the hyperlink on the id of the newly created publication + # and verify that the author names are correct + click_on OtherPublication.last.work_title.to_s + expect(page).to have_current_path(Rails.application.routes.url_helpers.other_publication_path(OtherPublication.last.id)) + expect(page).to have_text 'First0 Last0' + expect(page).to have_text 'First1 Last1' + expect(page).to have_text 'First2 Last2' + expect(page).to have_text 'First3 Last3' + end end it 'adds authors to an existing publication' do - # Create a new publication. Adding author functionality for a new publication - # is tested in the previous test. - create_other_publication # Defined in spec/support/helpers/feature_spec_helpers/author_management.rb - - # Click on the hyperlink on the id of the newly created publication - # and verify that the author names are correct - click_on OtherPublication.last.work_title.to_s - expect(page).to have_current_path(Rails.application.routes.url_helpers.other_publication_path(OtherPublication.last.id)) - expect(page).to have_selector('td', text: 'First0 Last0') # Information is in table format on the show page - - # Click on "Edit" and verify that we are redirected to the edit page - # and that the author names are correct - click_on 'Edit' - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) - expect(page).to have_current_path(Rails.application.routes.url_helpers.edit_other_publication_path(OtherPublication.last.id)) - check_field_values_by_index(0, 'First0', 'Last0') - - # Add another author and verify that the author names are correct - click_on 'Add Author' - first_name_fields.last.set('First1') - last_name_fields.last.set('Last1') - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - - # Add a third author and verify that the author names are correct - click_on 'Add Author' - first_name_fields.last.set('First2') - last_name_fields.last.set('Last2') - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - - # Save the changes and verify that we are redirected to the show page - # and that the author names are correct - click_on 'Submit' - expect(page).to have_current_path(Rails.application.routes.url_helpers.other_publication_path(OtherPublication.last.id)) - expect(page).to have_text 'Other Publication was successfully updated.' - expect(page).to have_selector('td', text: 'First0 Last0, First1 Last1, First2 Last2') # Information is in table format on the show page + using_wait_time(10) do + # Create a new publication. Adding author functionality for a new publication + # is tested in the previous test. + create_other_publication # Defined in spec/support/helpers/feature_spec_helpers/author_management.rb + + # Click on the hyperlink on the id of the newly created publication + # and verify that the author names are correct + click_on OtherPublication.last.work_title.to_s + expect(page).to have_current_path(Rails.application.routes.url_helpers.other_publication_path(OtherPublication.last.id)) + expect(page).to have_selector('td', text: 'First0 Last0') # Information is in table format on the show page + + # Click on "Edit" and verify that we are redirected to the edit page + # and that the author names are correct + click_on 'Edit' + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) + expect(page).to have_current_path(Rails.application.routes.url_helpers.edit_other_publication_path(OtherPublication.last.id)) + check_field_values_by_index(0, 'First0', 'Last0') + + # Add another author and verify that the author names are correct + click_on 'Add Author' + first_name_fields.last.set('First1') + last_name_fields.last.set('Last1') + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + + # Add a third author and verify that the author names are correct + click_on 'Add Author' + first_name_fields.last.set('First2') + last_name_fields.last.set('Last2') + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + + # Save the changes and verify that we are redirected to the show page + # and that the author names are correct + click_on 'Submit' + expect(page).to have_current_path(Rails.application.routes.url_helpers.other_publication_path(OtherPublication.last.id)) + expect(page).to have_text 'Other Publication was successfully updated.' + expect(page).to have_selector('td', text: 'First0 Last0, First1 Last1, First2 Last2') # Information is in table format on the show page + end end end diff --git a/spec/features/author_management/author_vs_artist_labels_spec.rb b/spec/features/author_management/author_vs_artist_labels_spec.rb index 430ce417..abe49177 100644 --- a/spec/features/author_management/author_vs_artist_labels_spec.rb +++ b/spec/features/author_management/author_vs_artist_labels_spec.rb @@ -14,52 +14,56 @@ end it 'uses the title of Author for new books' do - visit new_book_path - expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_book_path) - expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) - expect(page).to have_content('Add Author') - expect(page).not_to have_content('Add Artist') - first_name_fields.last.set('First0') - last_name_fields.last.set('Last0') + using_wait_time(10) do + visit new_book_path + expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_book_path) + expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) + expect(page).to have_content('Add Author') + expect(page).not_to have_content('Add Artist') + first_name_fields.last.set('First0') + last_name_fields.last.set('Last0') - click_on 'Add Author' - expect(page).to have_selector("input[name='book[author_first_name][]']", count: 2) - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_book_path) - first_name_fields.last.set('First1') - last_name_fields.last.set('Last1') + click_on 'Add Author' + expect(page).to have_selector("input[name='book[author_first_name][]']", count: 2) + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_book_path) + first_name_fields.last.set('First1') + last_name_fields.last.set('Last1') - click_on 'Add Author' - expect(page).to have_selector("input[name='book[author_first_name][]']", count: 3) - expect(page).to have_selector('button', text: 'Remove Author', count: 2) - expect(page).not_to have_selector('button', text: 'Remove Artist') + click_on 'Add Author' + expect(page).to have_selector("input[name='book[author_first_name][]']", count: 3) + expect(page).to have_selector('button', text: 'Remove Author', count: 2) + expect(page).not_to have_selector('button', text: 'Remove Artist') - first('button', text: 'Remove Author').click - expect(page).to have_selector('button', text: 'Remove Author', count: 1) - expect(page).not_to have_content('Artist') + first('button', text: 'Remove Author').click + expect(page).to have_selector('button', text: 'Remove Author', count: 1) + expect(page).not_to have_content('Artist') + end end it 'has the title of Artist for new artworks' do - visit new_artwork_path - expect(page).to have_selector("input[name='artwork[author_first_name][]']", visible: true) - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_artwork_path) - expect(page).to have_content('Add Artist') - expect(page).not_to have_content('Add Author') - first_name_fields.last.set('First0') - last_name_fields.last.set('Last0') + using_wait_time(10) do + visit new_artwork_path + expect(page).to have_selector("input[name='artwork[author_first_name][]']", visible: true) + expect(page).to have_current_path(Rails.application.routes.url_helpers.new_artwork_path) + expect(page).to have_content('Add Artist') + expect(page).not_to have_content('Add Author') + first_name_fields.last.set('First0') + last_name_fields.last.set('Last0') - click_on 'Add Artist' - expect(page).to have_selector("input[name='artwork[author_first_name][]']", count: 2) - first_name_fields.last.set('First1') - last_name_fields.last.set('Last1') + click_on 'Add Artist' + expect(page).to have_selector("input[name='artwork[author_first_name][]']", count: 2) + first_name_fields.last.set('First1') + last_name_fields.last.set('Last1') - click_on 'Add Artist' - expect(page).to have_selector("input[name='artwork[author_first_name][]']", count: 3) - expect(page).to have_selector('button', text: 'Remove Artist', count: 2) - expect(page).not_to have_selector('button', text: 'Remove Author') + click_on 'Add Artist' + expect(page).to have_selector("input[name='artwork[author_first_name][]']", count: 3) + expect(page).to have_selector('button', text: 'Remove Artist', count: 2) + expect(page).not_to have_selector('button', text: 'Remove Author') - first('button', text: 'Remove Artist').click - expect(page).to have_selector('button', text: 'Remove Artist', count: 1) - expect(page).not_to have_content('Author') + first('button', text: 'Remove Artist').click + expect(page).to have_selector('button', text: 'Remove Artist', count: 1) + expect(page).not_to have_content('Author') + end end end diff --git a/spec/features/author_management/removing_authors_spec.rb b/spec/features/author_management/removing_authors_spec.rb index de4ec0de..974430b1 100644 --- a/spec/features/author_management/removing_authors_spec.rb +++ b/spec/features/author_management/removing_authors_spec.rb @@ -15,49 +15,55 @@ end it 'removes the second author from the publication' do - # Remove the second author - remove_author_at_index(1) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First2', 'Last2') - check_field_values_by_index(2, 'First3', 'Last3') - - # Remove the second author again (should be "First2") - remove_author_at_index(1) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First3', 'Last3') - - # Remove the second author again (should be "First3") - remove_author_at_index(1) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) - check_field_values_by_index(0, 'First0', 'Last0') + using_wait_time(10) do + # Remove the second author + remove_author_at_index(1) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First2', 'Last2') + check_field_values_by_index(2, 'First3', 'Last3') + + # Remove the second author again (should be "First2") + remove_author_at_index(1) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First3', 'Last3') + + # Remove the second author again (should be "First3") + remove_author_at_index(1) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) + check_field_values_by_index(0, 'First0', 'Last0') + end end it 'removes the last author from the publication' do - remove_author_at_index(3) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - - remove_author_at_index(2) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - - remove_author_at_index(1) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) - check_field_values_by_index(0, 'First0', 'Last0') + using_wait_time(10) do + remove_author_at_index(3) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + + remove_author_at_index(2) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + + remove_author_at_index(1) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) + check_field_values_by_index(0, 'First0', 'Last0') + end end it 'does not have a Remove Author button for the first author' do - expect(first_author_element).not_to have_selector('button', text: 'Remove Author') + using_wait_time(10) do + expect(first_author_element).not_to have_selector('button', text: 'Remove Author') + end end end diff --git a/spec/features/author_management/updating_authors_spec.rb b/spec/features/author_management/updating_authors_spec.rb index deb24e43..3ee0eaae 100644 --- a/spec/features/author_management/updating_authors_spec.rb +++ b/spec/features/author_management/updating_authors_spec.rb @@ -10,112 +10,120 @@ end it "allows the user to update the first author's information" do - create_other_publication - add_three_more_authors_to_publication(OtherPublication.last) - visit edit_other_publication_path(OtherPublication.last) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - check_field_values_by_index(3, 'First3', 'Last3') + using_wait_time(10) do + create_other_publication + add_three_more_authors_to_publication(OtherPublication.last) + visit edit_other_publication_path(OtherPublication.last) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + check_field_values_by_index(3, 'First3', 'Last3') - # Update the first author's name - first_name_fields.first.set('First0modified') - last_name_fields.first.set('Last0modified') - click_on 'Submit' + # Update the first author's name + first_name_fields.first.set('First0modified') + last_name_fields.first.set('Last0modified') + click_on 'Submit' - expect(page).to have_current_path(other_publication_path(OtherPublication.last)) - expect(page).to have_content('First0modified') - expect(page).to have_content('Last0modified') - expect(page).to have_content('First1') - expect(page).to have_content('Last1') - expect(page).to have_content('First2') - expect(page).to have_content('Last2') - expect(page).to have_content('First3') - expect(page).to have_content('Last3') + expect(page).to have_current_path(other_publication_path(OtherPublication.last)) + expect(page).to have_content('First0modified') + expect(page).to have_content('Last0modified') + expect(page).to have_content('First1') + expect(page).to have_content('Last1') + expect(page).to have_content('First2') + expect(page).to have_content('Last2') + expect(page).to have_content('First3') + expect(page).to have_content('Last3') + end end it "allows the user to update the second author's information" do - create_other_publication - add_three_more_authors_to_publication(OtherPublication.last) - visit edit_other_publication_path(OtherPublication.last) - expect(page).to have_current_path(edit_other_publication_path(OtherPublication.last)) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - check_field_values_by_index(3, 'First3', 'Last3') + using_wait_time(10) do + create_other_publication + add_three_more_authors_to_publication(OtherPublication.last) + visit edit_other_publication_path(OtherPublication.last) + expect(page).to have_current_path(edit_other_publication_path(OtherPublication.last)) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + check_field_values_by_index(3, 'First3', 'Last3') - # Update the second author's name - first_name_fields[1].set('First1modified') - last_name_fields[1].set('Last1modified') - click_on 'Submit' + # Update the second author's name + first_name_fields[1].set('First1modified') + last_name_fields[1].set('Last1modified') + click_on 'Submit' - expect(page).to have_current_path(other_publication_path(OtherPublication.last)) - expect(page).to have_content('First0') - expect(page).to have_content('Last0') - expect(page).to have_content('First1modified') - expect(page).to have_content('Last1modified') - expect(page).to have_content('First2') - expect(page).to have_content('Last2') - expect(page).to have_content('First3') - expect(page).to have_content('Last3') + expect(page).to have_current_path(other_publication_path(OtherPublication.last)) + expect(page).to have_content('First0') + expect(page).to have_content('Last0') + expect(page).to have_content('First1modified') + expect(page).to have_content('Last1modified') + expect(page).to have_content('First2') + expect(page).to have_content('Last2') + expect(page).to have_content('First3') + expect(page).to have_content('Last3') + end end it "allows the user to update the last author's information" do - create_other_publication - add_three_more_authors_to_publication(OtherPublication.last) - visit edit_other_publication_path(OtherPublication.last) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - check_field_values_by_index(3, 'First3', 'Last3') + using_wait_time(10) do + create_other_publication + add_three_more_authors_to_publication(OtherPublication.last) + visit edit_other_publication_path(OtherPublication.last) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + check_field_values_by_index(3, 'First3', 'Last3') - # Update the last author's name - first_name_fields.last.set('First3modified') - last_name_fields.last.set('Last3modified') - click_on 'Submit' + # Update the last author's name + first_name_fields.last.set('First3modified') + last_name_fields.last.set('Last3modified') + click_on 'Submit' - expect(page).to have_current_path(other_publication_path(OtherPublication.last)) - expect(page).to have_content('First0') - expect(page).to have_content('Last0') - expect(page).to have_content('First1') - expect(page).to have_content('Last1') - expect(page).to have_content('First2') - expect(page).to have_content('Last2') - expect(page).to have_content('First3modified') - expect(page).to have_content('Last3modified') + expect(page).to have_current_path(other_publication_path(OtherPublication.last)) + expect(page).to have_content('First0') + expect(page).to have_content('Last0') + expect(page).to have_content('First1') + expect(page).to have_content('Last1') + expect(page).to have_content('First2') + expect(page).to have_content('Last2') + expect(page).to have_content('First3modified') + expect(page).to have_content('Last3modified') + end end it 'persists the changes when refreshing the page' do - create_other_publication - add_three_more_authors_to_publication(OtherPublication.last) - visit edit_other_publication_path(OtherPublication.last) - expect(page).to have_current_path(edit_other_publication_path(OtherPublication.last)) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - check_field_values_by_index(3, 'First3', 'Last3') + using_wait_time(10) do + create_other_publication + add_three_more_authors_to_publication(OtherPublication.last) + visit edit_other_publication_path(OtherPublication.last) + expect(page).to have_current_path(edit_other_publication_path(OtherPublication.last)) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + check_field_values_by_index(3, 'First3', 'Last3') - # Update the first author's name - first_name_fields.first.set('First0modified') - last_name_fields.first.set('Last0modified') - first_name_fields[1].set('First1modified') - last_name_fields[1].set('Last1modified') - first_name_fields[2].set('First2modified') - last_name_fields[2].set('Last2modified') - first_name_fields.last.set('First3modified') - last_name_fields.last.set('Last3modified') - click_on 'Submit' + # Update the first author's name + first_name_fields.first.set('First0modified') + last_name_fields.first.set('Last0modified') + first_name_fields[1].set('First1modified') + last_name_fields[1].set('Last1modified') + first_name_fields[2].set('First2modified') + last_name_fields[2].set('Last2modified') + first_name_fields.last.set('First3modified') + last_name_fields.last.set('Last3modified') + click_on 'Submit' - visit current_path - expect(page).to have_current_path(other_publication_path(OtherPublication.last)) - expect(page).to have_text('First0modified Last0modified, First1modified Last1modified, First2modified Last2modified, First3modified Last3modified') + visit current_path + expect(page).to have_current_path(other_publication_path(OtherPublication.last)) + expect(page).to have_text('First0modified Last0modified, First1modified Last1modified, First2modified Last2modified, First3modified Last3modified') + end end end From 7f9824fd726ba57632c350ce3352c1e9e3f24014 Mon Sep 17 00:00:00 2001 From: Janell-Huyck Date: Thu, 7 Mar 2024 17:38:02 -0500 Subject: [PATCH 5/7] Add 10 second wait to support/helpers/feature_spec_helpers/author_management --- .../feature_spec_helpers/author_management.rb | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/spec/support/helpers/feature_spec_helpers/author_management.rb b/spec/support/helpers/feature_spec_helpers/author_management.rb index 64bb7d2b..35ff3506 100644 --- a/spec/support/helpers/feature_spec_helpers/author_management.rb +++ b/spec/support/helpers/feature_spec_helpers/author_management.rb @@ -99,17 +99,42 @@ def verify_field_value(fields:, index:, expected_value:, field_name:) expect(actual_value).to eq(expected_value), error_message end + # navigates to the new other publication page and fills out the form. + def create_other_publication + using_wait_time(10) do + visit new_other_publication_path + + # Fill out the fields with the first author's name + first_name_fields.last.set('First0') + last_name_fields.last.set('Last0') + + # Fill in the rest of the fields + fill_in 'other_publication[work_title]', with: 'Title' + fill_in 'other_publication[other_title]', with: 'Subtitle' + fill_in 'other_publication[uc_department]', with: 'Department' + fill_in 'other_publication[publication_date]', with: 'Date' + fill_in 'other_publication[url]', with: 'URL' + fill_in 'other_publication[doi]', with: 'DOI' + + click_on 'Submit' + expect(page).to have_current_path(Rails.application.routes.url_helpers.publications_path) + end + end + # Adds three more authors to a publication. Valid only within # the context of a feature test with an already created publication. def add_three_more_authors_to_publication(publication) - visit edit_other_publication_path(publication) - 3.times do - current_count = first_name_fields.size - click_on 'Add Author' - first_name_fields.last.set("First#{current_count}") - last_name_fields.last.set("Last#{current_count}") + using_wait_time(10) do + visit edit_other_publication_path(publication) + 3.times do + current_count = first_name_fields.size + click_on 'Add Author' + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: current_count + 1) + first_name_fields.last.set("First#{current_count}") + last_name_fields.last.set("Last#{current_count}") + end + click_on 'Submit' end - click_on 'Submit' end end end From cc38db8132b82ed430f3a0695b96103a6c7015cb Mon Sep 17 00:00:00 2001 From: Janell-Huyck Date: Tue, 12 Mar 2024 16:46:42 -0400 Subject: [PATCH 6/7] Rebase --- .../author_management/adding_authors_spec.rb | 204 ++++++++---------- .../author_vs_artist_labels_spec.rb | 122 ++++++----- .../removing_authors_spec.rb | 91 ++++---- .../updating_authors_spec.rb | 178 ++++++--------- spec/rails_helper.rb | 4 + .../access_authorization_for_feature_tests.rb | 1 + .../feature_spec_helpers/author_management.rb | 89 +++----- 7 files changed, 309 insertions(+), 380 deletions(-) diff --git a/spec/features/author_management/adding_authors_spec.rb b/spec/features/author_management/adding_authors_spec.rb index edc04a8e..4f29fe63 100644 --- a/spec/features/author_management/adding_authors_spec.rb +++ b/spec/features/author_management/adding_authors_spec.rb @@ -4,131 +4,101 @@ describe 'Adding Authors', :feature, js: true do let(:submitter) { FactoryBot.create(:submitter) } + let(:other_publication) { FactoryBot.create(:other_publication, author_first_name: ['First0'], author_last_name: ['Last0'], submitter_id: submitter.id) } + let(:pub_id) { other_publication.id } before do create_submitter(submitter) end it 'adds authors to a new publication' do - using_wait_time(10) do - visit new_other_publication_path - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) - - # Verify blank input fields for author's first name and last name - # to be present on page load - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) - check_field_values_by_index(0, '', '') - - # Fill out the fields with the first author's name - first_name_fields.last.set('First0') - last_name_fields.last.set('Last0') - - # Click "Add Author" and verify new and old fields - click_on 'Add Author' - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) - - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, '', '') - - # Fill in second author's name - first_name_fields.last.set('First1') - last_name_fields.last.set('Last1') - - # Click "Add Author" again - click_on 'Add Author' - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, '', '') - - # Fill in third author's name - first_name_fields.last.set('First2') - last_name_fields.last.set('Last2') - - # Click "Add Author" again - click_on 'Add Author' - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_other_publication_path) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - check_field_values_by_index(3, '', '') - - # Fill in fourth author's name - first_name_fields.last.set('First3') - last_name_fields.last.set('Last3') - - # Fill in the rest of the fields - fill_in 'other_publication[work_title]', with: 'Title' - fill_in 'other_publication[other_title]', with: 'Subtitle' - fill_in 'other_publication[uc_department]', with: 'Department' - fill_in 'other_publication[publication_date]', with: 'Date' - fill_in 'other_publication[url]', with: 'URL' - fill_in 'other_publication[doi]', with: 'DOI' - - # Click "Submit" and verify that we are redirected to the index page - # and that a success message is displayed - click_on 'Submit' - expect(page).to have_current_path(Rails.application.routes.url_helpers.publications_path) - expect(page).to have_text 'Other Publication was successfully created.' - - # Click on the hyperlink on the id of the newly created publication - # and verify that the author names are correct - click_on OtherPublication.last.work_title.to_s - expect(page).to have_current_path(Rails.application.routes.url_helpers.other_publication_path(OtherPublication.last.id)) - expect(page).to have_text 'First0 Last0' - expect(page).to have_text 'First1 Last1' - expect(page).to have_text 'First2 Last2' - expect(page).to have_text 'First3 Last3' - end + visit new_other_publication_path + + # Verify blank input fields for author's first name and last name + # to be present on page load + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) + check_field_values_by_index(0, '', '') + + first_name_fields.last.set('First0') + last_name_fields.last.set('Last0') + + add_author_or_artist_and_verify_field + + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, '', '') + + first_name_fields.last.set('First1') + last_name_fields.last.set('Last1') + + add_author_or_artist_and_verify_field + + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, '', '') + + first_name_fields.last.set('First2') + last_name_fields.last.set('Last2') + + add_author_or_artist_and_verify_field + + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + check_field_values_by_index(3, '', '') + + first_name_fields.last.set('First3') + last_name_fields.last.set('Last3') + + # Fill in the rest of the fields + fill_in 'other_publication[work_title]', with: 'Title' + fill_in 'other_publication[other_title]', with: 'Subtitle' + fill_in 'other_publication[uc_department]', with: 'Department' + fill_in 'other_publication[publication_date]', with: 'Date' + fill_in 'other_publication[url]', with: 'URL' + fill_in 'other_publication[doi]', with: 'DOI' + + # Click "Submit" and verify that we are redirected to the index page + # and that a success message is displayed + click_on 'Submit' + expect(page).to have_text 'Other Publication was successfully created.' + expect(page).to have_current_path(Rails.application.routes.url_helpers.publications_path) + + # Check the last other_publication and verify that the author names are correct + last_other_publication = OtherPublication.last + expect(last_other_publication.author_first_name).to eq %w[First0 First1 First2 First3] + expect(last_other_publication.author_last_name).to eq %w[Last0 Last1 Last2 Last3] end it 'adds authors to an existing publication' do - using_wait_time(10) do - # Create a new publication. Adding author functionality for a new publication - # is tested in the previous test. - create_other_publication # Defined in spec/support/helpers/feature_spec_helpers/author_management.rb - - # Click on the hyperlink on the id of the newly created publication - # and verify that the author names are correct - click_on OtherPublication.last.work_title.to_s - expect(page).to have_current_path(Rails.application.routes.url_helpers.other_publication_path(OtherPublication.last.id)) - expect(page).to have_selector('td', text: 'First0 Last0') # Information is in table format on the show page - - # Click on "Edit" and verify that we are redirected to the edit page - # and that the author names are correct - click_on 'Edit' - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) - expect(page).to have_current_path(Rails.application.routes.url_helpers.edit_other_publication_path(OtherPublication.last.id)) - check_field_values_by_index(0, 'First0', 'Last0') - - # Add another author and verify that the author names are correct - click_on 'Add Author' - first_name_fields.last.set('First1') - last_name_fields.last.set('Last1') - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - - # Add a third author and verify that the author names are correct - click_on 'Add Author' - first_name_fields.last.set('First2') - last_name_fields.last.set('Last2') - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - - # Save the changes and verify that we are redirected to the show page - # and that the author names are correct - click_on 'Submit' - expect(page).to have_current_path(Rails.application.routes.url_helpers.other_publication_path(OtherPublication.last.id)) - expect(page).to have_text 'Other Publication was successfully updated.' - expect(page).to have_selector('td', text: 'First0 Last0, First1 Last1, First2 Last2') # Information is in table format on the show page - end + login_as_admin + + visit edit_other_publication_path(pub_id) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) + + # Defined with the factory creation above + check_field_values_by_index(0, 'First0', 'Last0') + + add_author_or_artist_and_verify_field + + first_name_fields.last.set('First1') + last_name_fields.last.set('Last1') + + add_author_or_artist_and_verify_field + + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + + first_name_fields.last.set('First2') + last_name_fields.last.set('Last2') + + click_on 'Submit' + expect(page).to have_text 'Other Publication was successfully updated.' + + other_publication = OtherPublication.find(pub_id) + other_publication.reload + + expect(other_publication.author_first_name).to eq %w[First0 First1 First2] + expect(other_publication.author_last_name).to eq %w[Last0 Last1 Last2] end end diff --git a/spec/features/author_management/author_vs_artist_labels_spec.rb b/spec/features/author_management/author_vs_artist_labels_spec.rb index abe49177..47ff7081 100644 --- a/spec/features/author_management/author_vs_artist_labels_spec.rb +++ b/spec/features/author_management/author_vs_artist_labels_spec.rb @@ -8,62 +8,88 @@ # and deleting authors and artists. describe 'Author and Artist labels', :feature, js: true do let(:submitter) { FactoryBot.create(:submitter) } + let(:book) { FactoryBot.create(:book, author_first_name: ['First0'], author_last_name: ['Last0']) } + let(:book_id) { book.id } + let(:artwork) { FactoryBot.create(:artwork, author_first_name: ['First0'], author_last_name: ['Last0']) } + let(:artwork_id) { artwork.id } before do create_submitter(submitter) end it 'uses the title of Author for new books' do - using_wait_time(10) do - visit new_book_path - expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_book_path) - expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) - expect(page).to have_content('Add Author') - expect(page).not_to have_content('Add Artist') - first_name_fields.last.set('First0') - last_name_fields.last.set('Last0') - - click_on 'Add Author' - expect(page).to have_selector("input[name='book[author_first_name][]']", count: 2) - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_book_path) - first_name_fields.last.set('First1') - last_name_fields.last.set('Last1') - - click_on 'Add Author' - expect(page).to have_selector("input[name='book[author_first_name][]']", count: 3) - expect(page).to have_selector('button', text: 'Remove Author', count: 2) - expect(page).not_to have_selector('button', text: 'Remove Artist') - - first('button', text: 'Remove Author').click - expect(page).to have_selector('button', text: 'Remove Author', count: 1) - expect(page).not_to have_content('Artist') - end + visit new_book_path + expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) + + expect(page).to have_content('Add Author') + expect(page).not_to have_content('Add Artist') + + add_author_or_artist_and_verify_field + add_author_or_artist_and_verify_field + + expect(page).to have_selector('button', text: 'Remove Author', count: 2) + expect(page).not_to have_selector('button', text: 'Remove Artist') + + first('button', text: 'Remove Author').click + expect(page).to have_selector('button', text: 'Remove Author', count: 1) + expect(page).not_to have_content('Artist') end it 'has the title of Artist for new artworks' do - using_wait_time(10) do - visit new_artwork_path - expect(page).to have_selector("input[name='artwork[author_first_name][]']", visible: true) - expect(page).to have_current_path(Rails.application.routes.url_helpers.new_artwork_path) - expect(page).to have_content('Add Artist') - expect(page).not_to have_content('Add Author') - first_name_fields.last.set('First0') - last_name_fields.last.set('Last0') - - click_on 'Add Artist' - expect(page).to have_selector("input[name='artwork[author_first_name][]']", count: 2) - first_name_fields.last.set('First1') - last_name_fields.last.set('Last1') - - click_on 'Add Artist' - expect(page).to have_selector("input[name='artwork[author_first_name][]']", count: 3) - expect(page).to have_selector('button', text: 'Remove Artist', count: 2) - expect(page).not_to have_selector('button', text: 'Remove Author') - - first('button', text: 'Remove Artist').click - expect(page).to have_selector('button', text: 'Remove Artist', count: 1) - expect(page).not_to have_content('Author') - end + visit new_artwork_path + expect(page).to have_selector("input[name='artwork[author_first_name][]']", visible: true) + + expect(page).to have_content('Add Artist') + expect(page).not_to have_content('Add Author') + + add_author_or_artist_and_verify_field + add_author_or_artist_and_verify_field + + expect(page).to have_selector('button', text: 'Remove Artist', count: 2) + expect(page).not_to have_selector('button', text: 'Remove Author') + + first('button', text: 'Remove Artist').click + expect(page).to have_selector('button', text: 'Remove Artist', count: 1) + expect(page).not_to have_content('Author') + end + + it 'uses the title of Author for existing books' do + login_as_admin + + visit edit_book_path(book) + expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) + + expect(page).to have_content('Add Author') + expect(page).not_to have_content('Add Artist') + + add_author_or_artist_and_verify_field + add_author_or_artist_and_verify_field + + expect(page).to have_selector('button', text: 'Remove Author', count: 2) + expect(page).not_to have_selector('button', text: 'Remove Artist') + + first('button', text: 'Remove Author').click + expect(page).to have_selector('button', text: 'Remove Author', count: 1) + expect(page).not_to have_content('Artist') + end + + it 'has the title of Artist for existing artworks' do + login_as_admin + + visit edit_artwork_path(artwork) + expect(page).to have_selector("input[name='artwork[author_first_name][]']", visible: true) + + expect(page).to have_content('Add Artist') + expect(page).not_to have_content('Add Author') + + add_author_or_artist_and_verify_field + add_author_or_artist_and_verify_field + + expect(page).to have_selector('button', text: 'Remove Artist', count: 2) + expect(page).not_to have_selector('button', text: 'Remove Author') + + first('button', text: 'Remove Artist').click + expect(page).to have_selector('button', text: 'Remove Artist', count: 1) + expect(page).not_to have_content('Author') end end diff --git a/spec/features/author_management/removing_authors_spec.rb b/spec/features/author_management/removing_authors_spec.rb index 974430b1..f8248930 100644 --- a/spec/features/author_management/removing_authors_spec.rb +++ b/spec/features/author_management/removing_authors_spec.rb @@ -3,67 +3,58 @@ require 'rails_helper' describe 'Removing Authors', :feature, js: true do - let(:submitter) { FactoryBot.create(:submitter) } + let(:other_publication) { FactoryBot.create(:other_publication, author_first_name: %w[First0 First1 First2 First3], author_last_name: %w[Last0 Last1 Last2 Last3]) } + let(:pub_id) { other_publication.id } before do - create_submitter(submitter) - create_other_publication - add_three_more_authors_to_publication(OtherPublication.last) - visit edit_other_publication_path(OtherPublication.last) + login_as_admin + visit edit_other_publication_path(other_publication) expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) end it 'removes the second author from the publication' do - using_wait_time(10) do - # Remove the second author - remove_author_at_index(1) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First2', 'Last2') - check_field_values_by_index(2, 'First3', 'Last3') - - # Remove the second author again (should be "First2") - remove_author_at_index(1) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First3', 'Last3') - - # Remove the second author again (should be "First3") - remove_author_at_index(1) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) - check_field_values_by_index(0, 'First0', 'Last0') - end + remove_author_at_index(1) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First2', 'Last2') + check_field_values_by_index(2, 'First3', 'Last3') + + # Remove the second author again (should be "First2") + remove_author_at_index(1) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First3', 'Last3') + + # Remove the second author again (should be "First3") + remove_author_at_index(1) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) + check_field_values_by_index(0, 'First0', 'Last0') end it 'removes the last author from the publication' do - using_wait_time(10) do - remove_author_at_index(3) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - - remove_author_at_index(2) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - - remove_author_at_index(1) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) - check_field_values_by_index(0, 'First0', 'Last0') - end + remove_author_at_index(3) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 3) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 3) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + + remove_author_at_index(2) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 2) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 2) + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + + remove_author_at_index(1) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) + expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 1) + check_field_values_by_index(0, 'First0', 'Last0') end it 'does not have a Remove Author button for the first author' do - using_wait_time(10) do - expect(first_author_element).not_to have_selector('button', text: 'Remove Author') - end + expect(first_author_element).not_to have_selector('button', text: 'Remove Author') end end diff --git a/spec/features/author_management/updating_authors_spec.rb b/spec/features/author_management/updating_authors_spec.rb index 3ee0eaae..540380de 100644 --- a/spec/features/author_management/updating_authors_spec.rb +++ b/spec/features/author_management/updating_authors_spec.rb @@ -4,126 +4,90 @@ describe 'Adding Authors', :feature, js: true do let(:submitter) { FactoryBot.create(:submitter) } + let(:other_publication) { FactoryBot.create(:other_publication, author_first_name: %w[First0 First1 First2 First3], author_last_name: %w[Last0 Last1 Last2 Last3], submitter_id: submitter.id) } + let(:pub_id) { other_publication.id } before do - create_submitter(submitter) + login_as_admin + visit edit_other_publication_path(pub_id) + expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) end it "allows the user to update the first author's information" do - using_wait_time(10) do - create_other_publication - add_three_more_authors_to_publication(OtherPublication.last) - visit edit_other_publication_path(OtherPublication.last) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - check_field_values_by_index(3, 'First3', 'Last3') - - # Update the first author's name - first_name_fields.first.set('First0modified') - last_name_fields.first.set('Last0modified') - click_on 'Submit' - - expect(page).to have_current_path(other_publication_path(OtherPublication.last)) - expect(page).to have_content('First0modified') - expect(page).to have_content('Last0modified') - expect(page).to have_content('First1') - expect(page).to have_content('Last1') - expect(page).to have_content('First2') - expect(page).to have_content('Last2') - expect(page).to have_content('First3') - expect(page).to have_content('Last3') - end + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + check_field_values_by_index(3, 'First3', 'Last3') + + # Update the first author's name + first_name_fields.first.set('First0modified') + last_name_fields.first.set('Last0modified') + click_on 'Submit' + expect(page).to have_content('Show Other Publication') + + other_publication.reload + + expect(other_publication.author_first_name).to eq(%w[First0modified First1 First2 First3]) + expect(other_publication.author_last_name).to eq(%w[Last0modified Last1 Last2 Last3]) end it "allows the user to update the second author's information" do - using_wait_time(10) do - create_other_publication - add_three_more_authors_to_publication(OtherPublication.last) - visit edit_other_publication_path(OtherPublication.last) - expect(page).to have_current_path(edit_other_publication_path(OtherPublication.last)) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - check_field_values_by_index(3, 'First3', 'Last3') - - # Update the second author's name - first_name_fields[1].set('First1modified') - last_name_fields[1].set('Last1modified') - click_on 'Submit' - - expect(page).to have_current_path(other_publication_path(OtherPublication.last)) - expect(page).to have_content('First0') - expect(page).to have_content('Last0') - expect(page).to have_content('First1modified') - expect(page).to have_content('Last1modified') - expect(page).to have_content('First2') - expect(page).to have_content('Last2') - expect(page).to have_content('First3') - expect(page).to have_content('Last3') - end + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + check_field_values_by_index(3, 'First3', 'Last3') + + # Update the second author's name + first_name_fields[1].set('First1modified') + last_name_fields[1].set('Last1modified') + + click_on 'Submit' + expect(page).to have_content('Show Other Publication') + + other_publication.reload + + expect(other_publication.author_first_name).to eq(%w[First0 First1modified First2 First3]) end it "allows the user to update the last author's information" do - using_wait_time(10) do - create_other_publication - add_three_more_authors_to_publication(OtherPublication.last) - visit edit_other_publication_path(OtherPublication.last) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - check_field_values_by_index(3, 'First3', 'Last3') - - # Update the last author's name - first_name_fields.last.set('First3modified') - last_name_fields.last.set('Last3modified') - click_on 'Submit' - - expect(page).to have_current_path(other_publication_path(OtherPublication.last)) - expect(page).to have_content('First0') - expect(page).to have_content('Last0') - expect(page).to have_content('First1') - expect(page).to have_content('Last1') - expect(page).to have_content('First2') - expect(page).to have_content('Last2') - expect(page).to have_content('First3modified') - expect(page).to have_content('Last3modified') - end + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + check_field_values_by_index(3, 'First3', 'Last3') + + # Update the last author's name + first_name_fields.last.set('First3modified') + last_name_fields.last.set('Last3modified') + + click_on 'Submit' + expect(page).to have_content('Show Other Publication') + + other_publication.reload + + expect(other_publication.author_first_name).to eq(%w[First0 First1 First2 First3modified]) + expect(other_publication.author_last_name).to eq(%w[Last0 Last1 Last2 Last3modified]) end it 'persists the changes when refreshing the page' do - using_wait_time(10) do - create_other_publication - add_three_more_authors_to_publication(OtherPublication.last) - visit edit_other_publication_path(OtherPublication.last) - expect(page).to have_current_path(edit_other_publication_path(OtherPublication.last)) - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) - expect(page).to have_selector("input[name='other_publication[author_last_name][]']", count: 4) - check_field_values_by_index(0, 'First0', 'Last0') - check_field_values_by_index(1, 'First1', 'Last1') - check_field_values_by_index(2, 'First2', 'Last2') - check_field_values_by_index(3, 'First3', 'Last3') - - # Update the first author's name - first_name_fields.first.set('First0modified') - last_name_fields.first.set('Last0modified') - first_name_fields[1].set('First1modified') - last_name_fields[1].set('Last1modified') - first_name_fields[2].set('First2modified') - last_name_fields[2].set('Last2modified') - first_name_fields.last.set('First3modified') - last_name_fields.last.set('Last3modified') - click_on 'Submit' - - visit current_path - expect(page).to have_current_path(other_publication_path(OtherPublication.last)) - expect(page).to have_text('First0modified Last0modified, First1modified Last1modified, First2modified Last2modified, First3modified Last3modified') - end + check_field_values_by_index(0, 'First0', 'Last0') + check_field_values_by_index(1, 'First1', 'Last1') + check_field_values_by_index(2, 'First2', 'Last2') + check_field_values_by_index(3, 'First3', 'Last3') + + first_name_fields.first.set('First0modified') + last_name_fields.first.set('Last0modified') + first_name_fields[1].set('First1modified') + last_name_fields[1].set('Last1modified') + first_name_fields[2].set('First2modified') + last_name_fields[2].set('Last2modified') + first_name_fields.last.set('First3modified') + last_name_fields.last.set('Last3modified') + click_on 'Submit' + expect(page).to have_content('Show Other Publication') + + visit current_path + expect(page).to have_content('Show Other Publication') + + expect(page).to have_text('First0modified Last0modified, First1modified Last1modified, First2modified Last2modified, First3modified Last3modified') end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 418d45ae..ac94f5a3 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -75,6 +75,9 @@ # Include helpers for feature tests config.include FeatureSpecHelpers::AuthorManagement, type: :feature + + # Set Capybara's default wait time + Capybara.default_max_wait_time = 10 # seconds end def create_submitter(submitter) @@ -89,4 +92,5 @@ def create_submitter(submitter) fill_in('submitter[phone_number]', with: submitter.phone_number) fill_in('submitter[email_address]', with: submitter.email_address) click_on('Next') + expect(page).to have_content('Instructions') # Wait for the form to advance to the next page end diff --git a/spec/support/helpers/access_authorization_for_feature_tests.rb b/spec/support/helpers/access_authorization_for_feature_tests.rb index 1fd44114..4f5abbb3 100644 --- a/spec/support/helpers/access_authorization_for_feature_tests.rb +++ b/spec/support/helpers/access_authorization_for_feature_tests.rb @@ -5,6 +5,7 @@ def login_as_admin_feature_test fill_in('username', with: ENV.fetch('ADMIN_USERNAME', nil)) fill_in('password', with: ENV.fetch('ADMIN_PASSWORD', nil)) click_on('Submit') + expect(page).to have_content('Submitters') # Confirm that the admin is on the publications page end def visit_publications_page_as_submitter(submitter) diff --git a/spec/support/helpers/feature_spec_helpers/author_management.rb b/spec/support/helpers/feature_spec_helpers/author_management.rb index 35ff3506..2f0137ff 100644 --- a/spec/support/helpers/feature_spec_helpers/author_management.rb +++ b/spec/support/helpers/feature_spec_helpers/author_management.rb @@ -47,37 +47,48 @@ def first_author_element find('#author_group > :first-child') end - # navigates to the new other publication page and fills out the form. - def create_other_publication - visit new_other_publication_path - - # Fill out the fields with the first author's name - first_name_fields.last.set('First0') - last_name_fields.last.set('Last0') - - # Fill in the rest of the fields - fill_in 'other_publication[work_title]', with: 'Title' - fill_in 'other_publication[other_title]', with: 'Subtitle' - fill_in 'other_publication[uc_department]', with: 'Department' - fill_in 'other_publication[publication_date]', with: 'Date' - fill_in 'other_publication[url]', with: 'URL' - fill_in 'other_publication[doi]', with: 'DOI' - - click_on 'Submit' + def add_author_or_artist_and_verify_field + # Dynamically get the current count of fields before adding a new one + current_count = first_name_fields.size + + author_button_present = has_button?('Add Author', wait: false) + artist_button_present = has_button?('Add Artist', wait: false) + + raise_errors_for_incorrect_button_states(author_button_present, artist_button_present) + + # Trigger adding a new field based on which button is present + if author_button_present + click_on 'Add Author' + field_selector = "input[name$='[author_first_name][]']" + elsif artist_button_present + click_on 'Add Artist' + field_selector = "input[name$='[author_first_name][]']" # Artist first name field is still "author_first_name" + end + + # Wait for the next field to appear + expect(page).to have_selector(field_selector, count: current_count + 1) end - private + def raise_errors_for_incorrect_button_states(author_button_present, artist_button_present) + # Fail if both or none of the buttons are present + if author_button_present && artist_button_present + raise 'Both "Add Author" and "Add Artist" buttons are present, which is unexpected.' + elsif !author_button_present && !artist_button_present + raise 'Neither "Add Author" nor "Add Artist" button is present, cannot proceed.' + end + end # Returns the collection of author first name fields. # @return [Array] The collection of author first name fields. def first_name_fields - all("input[name$='[author_first_name][]']", wait: Capybara.default_max_wait_time) + expect(page).to have_selector("input[name$='[author_first_name][]']") + all("input[name$='[author_first_name][]']") end # Returns the collection of author last name fields. # @return [Array] The collection of author last name fields. def last_name_fields - all("input[name$='[author_last_name][]']", wait: Capybara.default_max_wait_time) + all("input[name$='[author_last_name][]']") end # Validates if the provided index is within the range of existing author fields. @@ -98,43 +109,5 @@ def verify_field_value(fields:, index:, expected_value:, field_name:) error_message = "#{field_name} at index #{index} does not match" expect(actual_value).to eq(expected_value), error_message end - - # navigates to the new other publication page and fills out the form. - def create_other_publication - using_wait_time(10) do - visit new_other_publication_path - - # Fill out the fields with the first author's name - first_name_fields.last.set('First0') - last_name_fields.last.set('Last0') - - # Fill in the rest of the fields - fill_in 'other_publication[work_title]', with: 'Title' - fill_in 'other_publication[other_title]', with: 'Subtitle' - fill_in 'other_publication[uc_department]', with: 'Department' - fill_in 'other_publication[publication_date]', with: 'Date' - fill_in 'other_publication[url]', with: 'URL' - fill_in 'other_publication[doi]', with: 'DOI' - - click_on 'Submit' - expect(page).to have_current_path(Rails.application.routes.url_helpers.publications_path) - end - end - - # Adds three more authors to a publication. Valid only within - # the context of a feature test with an already created publication. - def add_three_more_authors_to_publication(publication) - using_wait_time(10) do - visit edit_other_publication_path(publication) - 3.times do - current_count = first_name_fields.size - click_on 'Add Author' - expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: current_count + 1) - first_name_fields.last.set("First#{current_count}") - last_name_fields.last.set("Last#{current_count}") - end - click_on 'Submit' - end - end end end From da1de1a3932f262109e0e55dcf4f680951a75cf8 Mon Sep 17 00:00:00 2001 From: Janell-Huyck Date: Tue, 12 Mar 2024 16:58:37 -0400 Subject: [PATCH 7/7] Correct 'login_as_admin' to new method name --- spec/features/author_management/adding_authors_spec.rb | 2 +- .../author_management/author_vs_artist_labels_spec.rb | 4 ++-- spec/features/author_management/removing_authors_spec.rb | 2 +- spec/features/author_management/updating_authors_spec.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/features/author_management/adding_authors_spec.rb b/spec/features/author_management/adding_authors_spec.rb index 4f29fe63..e1f1dbef 100644 --- a/spec/features/author_management/adding_authors_spec.rb +++ b/spec/features/author_management/adding_authors_spec.rb @@ -71,7 +71,7 @@ end it 'adds authors to an existing publication' do - login_as_admin + login_as_admin_feature_test visit edit_other_publication_path(pub_id) expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 1) diff --git a/spec/features/author_management/author_vs_artist_labels_spec.rb b/spec/features/author_management/author_vs_artist_labels_spec.rb index 47ff7081..d2b0f35c 100644 --- a/spec/features/author_management/author_vs_artist_labels_spec.rb +++ b/spec/features/author_management/author_vs_artist_labels_spec.rb @@ -54,7 +54,7 @@ end it 'uses the title of Author for existing books' do - login_as_admin + login_as_admin_feature_test visit edit_book_path(book) expect(page).to have_selector("input[name='book[author_first_name][]']", visible: true) @@ -74,7 +74,7 @@ end it 'has the title of Artist for existing artworks' do - login_as_admin + login_as_admin_feature_test visit edit_artwork_path(artwork) expect(page).to have_selector("input[name='artwork[author_first_name][]']", visible: true) diff --git a/spec/features/author_management/removing_authors_spec.rb b/spec/features/author_management/removing_authors_spec.rb index f8248930..68cf8210 100644 --- a/spec/features/author_management/removing_authors_spec.rb +++ b/spec/features/author_management/removing_authors_spec.rb @@ -7,7 +7,7 @@ let(:pub_id) { other_publication.id } before do - login_as_admin + login_as_admin_feature_test visit edit_other_publication_path(other_publication) expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) end diff --git a/spec/features/author_management/updating_authors_spec.rb b/spec/features/author_management/updating_authors_spec.rb index 540380de..df8eef13 100644 --- a/spec/features/author_management/updating_authors_spec.rb +++ b/spec/features/author_management/updating_authors_spec.rb @@ -8,7 +8,7 @@ let(:pub_id) { other_publication.id } before do - login_as_admin + login_as_admin_feature_test visit edit_other_publication_path(pub_id) expect(page).to have_selector("input[name='other_publication[author_first_name][]']", count: 4) end