From 4de9330c9a816036a8fbcee4848f8250d14fc3f4 Mon Sep 17 00:00:00 2001 From: Thomas Scherz Date: Tue, 23 Jul 2024 13:11:39 -0400 Subject: [PATCH] Refactors multi_value spec to test. --- .../software_records/multi_value_spec.rb | 80 ++++++++++++++++--- 1 file changed, 68 insertions(+), 12 deletions(-) diff --git a/spec/features/software_records/multi_value_spec.rb b/spec/features/software_records/multi_value_spec.rb index ba0bbf5..283ed91 100644 --- a/spec/features/software_records/multi_value_spec.rb +++ b/spec/features/software_records/multi_value_spec.rb @@ -18,9 +18,21 @@ within('#multiple_developers') do expect(page).to have_selector('.input-group', count: 1) find('a', text: '+ add more').click + find('a', text: '+ add more').click + + # Fill in fields with identifiable values + all('.input-group input').each_with_index do |input, index| + input.set("Developer #{index + 1}") + end + + expect(page).to have_selector('.input-group', count: 3) + + # Delete 'Developer 2' + all('.input-group-append')[1].click expect(page).to have_selector('.input-group', count: 2) - all('.input-group-append').last.click - expect(page).to have_selector('.input-group', count: 1) + expect(page).not_to have_field(with: 'Developer 2') + expect(page).to have_field(with: 'Developer 1') + expect(page).to have_field(with: 'Developer 3') end end @@ -28,9 +40,21 @@ within('#multiple_tech_leads') do expect(page).to have_selector('.input-group', count: 1) find('a', text: '+ add more').click + find('a', text: '+ add more').click + + # Fill in fields with identifiable values + all('.input-group input').each_with_index do |input, index| + input.set("Tech Lead #{index + 1}") + end + + expect(page).to have_selector('.input-group', count: 3) + + # Delete 'Tech Lead 2' + all('.input-group-append')[1].click expect(page).to have_selector('.input-group', count: 2) - all('.input-group-append').last.click - expect(page).to have_selector('.input-group', count: 1) + expect(page).not_to have_field(with: 'Tech Lead 2') + expect(page).to have_field(with: 'Tech Lead 1') + expect(page).to have_field(with: 'Tech Lead 3') end end @@ -38,9 +62,21 @@ within('#multiple_departments') do expect(page).to have_selector('.input-group', count: 1) find('a', text: '+ add more').click + find('a', text: '+ add more').click + + # Fill in fields with identifiable values + all('.input-group input').each_with_index do |input, index| + input.set("Department #{index + 1}") + end + + expect(page).to have_selector('.input-group', count: 3) + + # Delete 'Department 2' + all('.input-group-append')[1].click expect(page).to have_selector('.input-group', count: 2) - all('.input-group-append').last.click - expect(page).to have_selector('.input-group', count: 1) + expect(page).not_to have_field(with: 'Department 2') + expect(page).to have_field(with: 'Department 1') + expect(page).to have_field(with: 'Department 3') end end @@ -48,11 +84,21 @@ within('#multiple_product_owners') do expect(page).to have_selector('.input-group', count: 1) find('a', text: '+ add more').click + find('a', text: '+ add more').click - expect(page).to have_selector('.input-group', count: 2) + # Fill in fields with identifiable values + all('.input-group input').each_with_index do |input, index| + input.set("Product Owner #{index + 1}") + end - all('.input-group-append').last.click - expect(page).to have_selector('.input-group', count: 1) + expect(page).to have_selector('.input-group', count: 3) + + # Delete 'Product Owner 2' + all('.input-group-append')[1].click + expect(page).to have_selector('.input-group', count: 2) + expect(page).not_to have_field(with: 'Product Owner 2') + expect(page).to have_field(with: 'Product Owner 1') + expect(page).to have_field(with: 'Product Owner 3') end end @@ -60,11 +106,21 @@ within('#multiple_admin_users') do expect(page).to have_selector('.input-group', count: 1) find('a', text: '+ add more').click + find('a', text: '+ add more').click - expect(page).to have_selector('.input-group', count: 2) + # Fill in fields with identifiable values + all('.input-group input').each_with_index do |input, index| + input.set("Admin User #{index + 1}") + end - all('.input-group-append').last.click - expect(page).to have_selector('.input-group', count: 1) + expect(page).to have_selector('.input-group', count: 3) + + # Delete 'Admin User 2' + all('.input-group-append')[1].click + expect(page).to have_selector('.input-group', count: 2) + expect(page).not_to have_field(with: 'Admin User 2') + expect(page).to have_field(with: 'Admin User 1') + expect(page).to have_field(with: 'Admin User 3') end end end