Skip to content

Commit

Permalink
Trim add_author tests to reduce wait times
Browse files Browse the repository at this point in the history
  • Loading branch information
Janell-Huyck committed Mar 8, 2024
1 parent 8636615 commit 71653bf
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 363 deletions.
204 changes: 87 additions & 117 deletions spec/features/author_management/adding_authors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
122 changes: 74 additions & 48 deletions spec/features/author_management/author_vs_artist_labels_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 71653bf

Please sign in to comment.