Skip to content

Commit

Permalink
test: fix failing clicks on hover-only elements
Browse files Browse the repository at this point in the history
  • Loading branch information
purfectliterature committed Oct 25, 2022
1 parent c1a7a74 commit 8c611ee
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
22 changes: 11 additions & 11 deletions spec/features/course/achievement_condition_management_spec.rb
Expand Up @@ -49,7 +49,7 @@
condition_row = find('tr', text: achievement_condition.title)
edit_button = condition_row.first('button', visible: false)

edit_button.click
hover_then_click edit_button
find_field('Achievement').click
find('li', text: achievement_to_change_to.title).click
click_button 'Update condition'
Expand All @@ -63,7 +63,7 @@
delete_button = condition_row.all('button', visible: false).last

expect do
delete_button.click
hover_then_click delete_button
expect_toastify('Condition was successfully deleted.')
end.to change { achievement.conditions.count }.by(-1)
end
Expand All @@ -88,23 +88,23 @@
condition_row = all('tr', text: 'Assessment').last
edit_button = condition_row.first('button', visible: false)

edit_button.click
hover_then_click edit_button
assessment_field = find_field('Assessment')
expect(assessment_field.value).to eq(valid_assessment_as_condition.title)
assessment_field.click
find('li', text: assessment_to_change_to.title).click
click_button 'Update condition'

expect_toastify('Your changes have been saved.')
condition_row.first('button', visible: false).click
hover_then_click condition_row.first('button', visible: false)
expect(find_field('Assessment').value).to eq(assessment_to_change_to.title)
click_button 'Cancel'

# Delete achievement condition
delete_button = condition_row.all('button', visible: false).last

expect do
delete_button.click
hover_then_click delete_button
expect_toastify('Condition was successfully deleted.')
end.to change { achievement.conditions.count }.by(-1)
end
Expand All @@ -128,21 +128,21 @@
condition_row = all('tr', text: 'Level').last
edit_button = condition_row.first('button', visible: false)

edit_button.click
hover_then_click edit_button
expect(find_field('minimumLevel').value).to eq(minimum_level)
fill_in 'minimumLevel', with: new_minimum_level
click_button 'Update condition'

expect_toastify('Your changes have been saved.')
condition_row.first('button', visible: false).click
hover_then_click condition_row.first('button', visible: false)
expect(find_field('minimumLevel').value).to eq(new_minimum_level)
click_button 'Cancel'

# Delete level condition
delete_button = condition_row.all('button', visible: false).last

expect do
delete_button.click
hover_then_click delete_button
expect_toastify('Condition was successfully deleted.')
end.to change { achievement.conditions.count }.by(-1)
end
Expand All @@ -167,23 +167,23 @@
condition_row = all('tr', text: 'Survey').last
edit_button = condition_row.first('button', visible: false)

edit_button.click
hover_then_click edit_button
survey_field = find_field('Survey')
expect(survey_field.value).to eq(valid_survey_as_condition.title)
survey_field.click
find('li', text: survey_to_change_to.title).click
click_button 'Update condition'

expect_toastify('Your changes have been saved.')
condition_row.first('button', visible: false).click
hover_then_click condition_row.first('button', visible: false)
expect(find_field('Survey').value).to eq(survey_to_change_to.title)
click_button 'Cancel'

# Delete survey condition
delete_button = condition_row.all('button', visible: false).last

expect do
delete_button.click
hover_then_click delete_button
expect_toastify('Condition was successfully deleted.')
end.to change { achievement.conditions.count }.by(-1)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/features/course/assessment_condition_management_spec.rb
Expand Up @@ -42,13 +42,13 @@
condition_row = find('tr', text: assessment_condition.title)
edit_button = condition_row.first('button', visible: false)

edit_button.click
hover_then_click edit_button
find_field('Assessment').click
find('li', text: assessment_to_change_to.title).click
click_button 'Update condition'

expect_toastify('Your changes have been saved.')
condition_row.first('button', visible: false).click
hover_then_click condition_row.first('button', visible: false)
expect(find_field('Assessment').value).to eq(assessment_to_change_to.title)
end

Expand All @@ -58,7 +58,7 @@
delete_button = condition_row.all('button', visible: false).last

expect do
delete_button.click
hover_then_click delete_button
expect_toastify('Condition was successfully deleted.')
end.to change { assessment.conditions.count }.by(-1)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/features/course/category_management_spec.rb
Expand Up @@ -29,7 +29,7 @@
rename_button = category_element.all('button', visible: false).first
previous_title = category.title

rename_button.click
hover_then_click rename_button
title_field = category_element.find('input')
title_field.set(category_edited[:title])
title_field.native.send_keys(:return)
Expand Down Expand Up @@ -67,7 +67,7 @@
category_element = find_rbd_category(category.id)
delete_button = category_element.all('button', visible: false)[1]

delete_button.click
hover_then_click delete_button

expect_toastify("#{category.title} was successfully deleted.")

Expand Down
4 changes: 2 additions & 2 deletions spec/features/course/tab_management_spec.rb
Expand Up @@ -33,7 +33,7 @@
rename_button = tab_element.all('button', visible: false).first
previous_title = tab.title

rename_button.click
hover_then_click rename_button
title_field = tab_element.find('input')
title_field.set(tab_edited[:title])
title_field.native.send_keys(:return)
Expand Down Expand Up @@ -71,7 +71,7 @@
tab_to_delete_element = find_rbd_tab(tab_to_delete.id)
delete_button = tab_to_delete_element.all('button', visible: false).last

delete_button.click
hover_then_click delete_button

expect_toastify("#{tab_to_delete.title} was successfully deleted.")
expect(page).not_to have_content(tab_to_delete.title)
Expand Down
5 changes: 5 additions & 0 deletions spec/support/capybara.rb
Expand Up @@ -125,6 +125,11 @@ def drag_rbd(source, destination)
release.
perform
end

def hover_then_click(element)
element.hover
element.click
end
end
end

Expand Down

0 comments on commit 8c611ee

Please sign in to comment.