Skip to content

Commit fb2d871

Browse files
committed
Refactor spec/features/modal_search_spec.rb
This change refactors `spec/features/modal_search_spec.rb` by adding a method which contains the modal logic shared between both of the tests within the file.
1 parent 748a94f commit fb2d871

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

spec/features/modal_search_spec.rb

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,7 @@
2323
end
2424

2525
it 'Modal search opens and closes and allows user to search, select and remove items', :js do
26-
# Open the modal
27-
click_button 'Add a repository'
28-
expect(page).to have_text('Repository search')
29-
30-
within('#modal-search-repositories') do
31-
# Search for the Repository
32-
fill_in 'research_output_search_term', with: @model.name
33-
click_button 'Apply filter(s)'
34-
expect(page).to have_text(@model.description)
35-
# Select the repository and make sure it no longer appears in the search results
36-
click_link 'Select'
37-
expect(page).not_to have_text(@model.description)
38-
39-
# Using JS to click on button, as click_button '.modal-header button.btn-close' did not work.
40-
modal_close_button = find('.modal-header button.btn-close')
41-
# Close the modal
42-
execute_script('arguments[0].click();', modal_close_button)
43-
end
44-
45-
# Verify that the selection was added to the main page's dom
46-
expect(page).not_to have_text('Repository search')
47-
expect(page).to have_text(@model.description)
26+
perform_modal_actions
4827
# Verify that we can remove the selection
4928
click_link 'Remove'
5029
expect(page).not_to have_text(@model.description)
@@ -55,15 +34,7 @@
5534
fill_in 'Title', with: 'Test Output'
5635
select 'Audiovisual', from: 'research_output_output_type'
5736

58-
# Open the modal and select repository
59-
click_button 'Add a repository'
60-
within('#modal-search-repositories') do
61-
fill_in 'research_output_search_term', with: @model.name
62-
click_button 'Apply filter(s)'
63-
click_link 'Select'
64-
# (execute_script('arguments[0].click();', modal_close_button) works locally here, but not as GitHub Action)
65-
find('[data-bs-dismiss="modal"]').click
66-
end
37+
perform_modal_actions
6738

6839
click_button 'Save'
6940

@@ -80,4 +51,31 @@
8051
expect(research_output.repositories).to include(@model)
8152
expect(research_output.plan).to eq(@plan)
8253
end
54+
55+
private
56+
57+
# handles opening + closing of the modal, as well as the actions performed within the modal
58+
def perform_modal_actions
59+
# Open the modal
60+
click_button 'Add a repository'
61+
expect(page).to have_text('Repository search')
62+
63+
within('#modal-search-repositories') do
64+
# Search for the Repository
65+
fill_in 'research_output_search_term', with: @model.name
66+
click_button 'Apply filter(s)'
67+
expect(page).to have_text(@model.description)
68+
# Select the repository and make sure it no longer appears in the search results
69+
click_link 'Select'
70+
expect(page).not_to have_text(@model.description)
71+
72+
# Using JS to click on button, as click_button '.modal-header button.btn-close' did not work.
73+
modal_close_button = find('.modal-header button.btn-close')
74+
# Close the modal
75+
execute_script('arguments[0].click();', modal_close_button)
76+
end
77+
# Verify that the selection was added to the main page's dom
78+
expect(page).not_to have_text('Repository search')
79+
expect(page).to have_text(@model.description)
80+
end
8381
end

0 commit comments

Comments
 (0)