|
23 | 23 | end |
24 | 24 |
|
25 | 25 | 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 |
48 | 27 | # Verify that we can remove the selection |
49 | 28 | click_link 'Remove' |
50 | 29 | expect(page).not_to have_text(@model.description) |
|
55 | 34 | fill_in 'Title', with: 'Test Output' |
56 | 35 | select 'Audiovisual', from: 'research_output_output_type' |
57 | 36 |
|
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 |
67 | 38 |
|
68 | 39 | click_button 'Save' |
69 | 40 |
|
|
80 | 51 | expect(research_output.repositories).to include(@model) |
81 | 52 | expect(research_output.plan).to eq(@plan) |
82 | 53 | 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 |
83 | 81 | end |
0 commit comments