From b2bc4d19f5a9c8425b217dc91479110c34a66aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 29 Mar 2021 13:28:41 +0200 Subject: [PATCH] Use JavaScript in tests opening modal dialogs This way we reproduce the user experience in the tests, and we can make sure modal dialogs open when we expect it. --- spec/shared/system/admin_progressable.rb | 4 +- spec/shared/system/documentable.rb | 12 ++-- spec/system/admin/activity_spec.rb | 64 ++++++++++++------- spec/system/admin/admin_notifications_spec.rb | 4 +- spec/system/admin/administrators_spec.rb | 12 ++-- spec/system/admin/banners_spec.rb | 10 +-- spec/system/admin/budget_groups_spec.rb | 8 +-- spec/system/admin/budget_headings_spec.rb | 8 +-- spec/system/admin/emails/newsletters_spec.rb | 4 +- spec/system/admin/feature_flags_spec.rb | 26 +++++--- spec/system/admin/geozones_spec.rb | 8 +-- .../admin/hidden_budget_investments_spec.rb | 8 +-- spec/system/admin/hidden_comments_spec.rb | 16 +++-- spec/system/admin/hidden_debates_spec.rb | 8 +-- spec/system/admin/hidden_proposals_spec.rb | 8 +-- spec/system/admin/hidden_users_spec.rb | 8 +-- .../system/admin/local_census_records_spec.rb | 5 +- spec/system/admin/managers_spec.rb | 8 +-- spec/system/admin/milestone_statuses_spec.rb | 4 +- spec/system/admin/moderators_spec.rb | 8 +-- spec/system/admin/poll/officers_spec.rb | 4 +- spec/system/admin/poll/questions_spec.rb | 4 +- spec/system/admin/poll/shifts_spec.rb | 12 ++-- .../admin/proposal_notifications_spec.rb | 8 +-- .../site_customization/content_blocks_spec.rb | 4 +- spec/system/admin/tags_spec.rb | 14 ++-- spec/system/admin/valuator_groups_spec.rb | 4 +- spec/system/admin/valuators_spec.rb | 4 +- spec/system/budgets/investments_spec.rb | 5 +- spec/system/debates_spec.rb | 18 +++--- spec/system/emails_spec.rb | 6 +- .../moderation/budget_investments_spec.rb | 15 +++-- spec/system/moderation/comments_spec.rb | 15 +++-- spec/system/moderation/debates_spec.rb | 15 +++-- .../moderation/proposal_notifications_spec.rb | 13 ++-- spec/system/moderation/proposals_spec.rb | 15 +++-- spec/system/moderation/users_spec.rb | 4 +- .../valuation/budget_investments_spec.rb | 6 +- 38 files changed, 221 insertions(+), 178 deletions(-) diff --git a/spec/shared/system/admin_progressable.rb b/spec/shared/system/admin_progressable.rb index 9c973a5ab..10260dc38 100644 --- a/spec/shared/system/admin_progressable.rb +++ b/spec/shared/system/admin_progressable.rb @@ -108,11 +108,11 @@ shared_examples "admin_progressable" do |factory_name, path_name| end context "Delete" do - scenario "Remove progress bar" do + scenario "Remove progress bar", :js do bar = create(:progress_bar, progressable: progressable, percentage: 34) visit path - within("#progress_bar_#{bar.id}") { click_link "Delete" } + within("#progress_bar_#{bar.id}") { accept_confirm { click_link "Delete" } } expect(page).to have_content "Progress bar deleted successfully" expect(page).not_to have_content "34%" diff --git a/spec/shared/system/documentable.rb b/spec/shared/system/documentable.rb index 5a85e243a..d2901273b 100644 --- a/spec/shared/system/documentable.rb +++ b/spec/shared/system/documentable.rb @@ -95,37 +95,37 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, end context "Destroy" do - scenario "Should show success notice after successful document upload" do + scenario "Should show success notice after successful document upload", :js do login_as documentable.author visit send(documentable_path, arguments) within "#document_#{document.id}" do - click_on "Delete document" + accept_confirm { click_link "Delete document" } end expect(page).to have_content "Document was deleted successfully." end - scenario "Should hide documents tab if there is no documents" do + scenario "Should hide documents tab if there is no documents", :js do login_as documentable.author visit send(documentable_path, arguments) within "#document_#{document.id}" do - click_on "Delete document" + accept_confirm { click_link "Delete document" } end expect(page).not_to have_content "Documents (0)" end - scenario "Should redirect to documentable path after successful deletion" do + scenario "Should redirect to documentable path after successful deletion", :js do login_as documentable.author visit send(documentable_path, arguments) within "#document_#{document.id}" do - click_on "Delete document" + accept_confirm { click_link "Delete document" } end within "##{ActionView::RecordIdentifier.dom_id(documentable)}" do diff --git a/spec/system/admin/activity_spec.rb b/spec/system/admin/activity_spec.rb index 0accba34a..f1e117586 100644 --- a/spec/system/admin/activity_spec.rb +++ b/spec/system/admin/activity_spec.rb @@ -27,7 +27,7 @@ describe "Admin activity" do end end - scenario "Shows moderation activity from moderation screen" do + scenario "Shows moderation activity from moderation screen", :js do proposal1 = create(:proposal) proposal2 = create(:proposal) proposal3 = create(:proposal) @@ -42,7 +42,9 @@ describe "Admin activity" do check "proposal_#{proposal3.id}_check" end - click_on "Hide proposals" + accept_confirm { click_button "Hide proposals" } + + expect(page).not_to have_content(proposal1.title) visit admin_activity_path @@ -51,15 +53,17 @@ describe "Admin activity" do expect(page).to have_content(proposal3.title) end - scenario "Shows admin restores" do + scenario "Shows admin restores", :js do proposal = create(:proposal, :hidden) visit admin_hidden_proposals_path within("#proposal_#{proposal.id}") do - click_on "Restore" + accept_confirm { click_link "Restore" } end + expect(page).to have_content "There are no hidden proposals" + visit admin_activity_path within("#activity_#{Activity.last.id}") do @@ -90,7 +94,7 @@ describe "Admin activity" do end end - scenario "Shows moderation activity from moderation screen" do + scenario "Shows moderation activity from moderation screen", :js do debate1 = create(:debate) debate2 = create(:debate) debate3 = create(:debate) @@ -105,7 +109,9 @@ describe "Admin activity" do check "debate_#{debate3.id}_check" end - click_on "Hide debates" + accept_confirm { click_button "Hide debates" } + + expect(page).not_to have_content(debate1.title) visit admin_activity_path @@ -114,15 +120,17 @@ describe "Admin activity" do expect(page).to have_content(debate3.title) end - scenario "Shows admin restores" do + scenario "Shows admin restores", :js do debate = create(:debate, :hidden) visit admin_hidden_debates_path within("#debate_#{debate.id}") do - click_on "Restore" + accept_confirm { click_link "Restore" } end + expect(page).to have_content "There are no hidden debates" + visit admin_activity_path within("#activity_#{Activity.last.id}") do @@ -154,7 +162,7 @@ describe "Admin activity" do end end - scenario "Shows moderation activity from moderation screen" do + scenario "Shows moderation activity from moderation screen", :js do comment1 = create(:comment, body: "SPAM") comment2 = create(:comment) comment3 = create(:comment, body: "Offensive!") @@ -169,7 +177,9 @@ describe "Admin activity" do check "comment_#{comment3.id}_check" end - click_on "Hide comments" + accept_confirm { click_button "Hide comments" } + + expect(page).not_to have_content(comment1.body) visit admin_activity_path @@ -178,15 +188,17 @@ describe "Admin activity" do expect(page).to have_content(comment3.body) end - scenario "Shows admin restores" do + scenario "Shows admin restores", :js do comment = create(:comment, :hidden) visit admin_hidden_comments_path within("#comment_#{comment.id}") do - click_on "Restore" + accept_confirm { click_link "Restore" } end + expect(page).to have_content "There are no hidden comments" + visit admin_activity_path within("#activity_#{Activity.last.id}") do @@ -198,13 +210,13 @@ describe "Admin activity" do end context "User" do - scenario "Shows moderation activity on users" do + scenario "Shows moderation activity on users", :js do proposal = create(:proposal) visit proposal_path(proposal) within("#proposal_#{proposal.id}") do - click_link "Hide author" + accept_confirm { click_link "Hide author" } expect(page).to have_current_path(debates_path) end @@ -238,7 +250,7 @@ describe "Admin activity" do end end - scenario "Shows moderation activity from proposals moderation screen" do + scenario "Shows moderation activity from proposals moderation screen", :js do proposal1 = create(:proposal) proposal2 = create(:proposal) proposal3 = create(:proposal) @@ -253,7 +265,9 @@ describe "Admin activity" do check "proposal_#{proposal3.id}_check" end - click_on "Block authors" + accept_confirm { click_button "Block authors" } + + expect(page).not_to have_content(proposal1.author.username) visit admin_activity_path @@ -264,7 +278,7 @@ describe "Admin activity" do expect(page).not_to have_content(proposal2.author.username) end - scenario "Shows moderation activity from debates moderation screen" do + scenario "Shows moderation activity from debates moderation screen", :js do debate1 = create(:debate) debate2 = create(:debate) debate3 = create(:debate) @@ -279,7 +293,9 @@ describe "Admin activity" do check "debate_#{debate3.id}_check" end - click_on "Block authors" + accept_confirm { click_button "Block authors" } + + expect(page).not_to have_content(debate1.author.username) visit admin_activity_path @@ -290,7 +306,7 @@ describe "Admin activity" do expect(page).not_to have_content(debate2.author.username) end - scenario "Shows moderation activity from comments moderation screen" do + scenario "Shows moderation activity from comments moderation screen", :js do comment1 = create(:comment, body: "SPAM") comment2 = create(:comment) comment3 = create(:comment, body: "Offensive!") @@ -305,7 +321,9 @@ describe "Admin activity" do check "comment_#{comment3.id}_check" end - click_on "Block authors" + accept_confirm { click_button "Block authors" } + + expect(page).not_to have_content comment1.author.username visit admin_activity_path @@ -316,15 +334,17 @@ describe "Admin activity" do expect(page).not_to have_content(comment2.author.username) end - scenario "Shows admin restores" do + scenario "Shows admin restores", :js do user = create(:user, :hidden) visit admin_hidden_users_path within("#user_#{user.id}") do - click_on "Restore" + accept_confirm { click_link "Restore" } end + expect(page).to have_content "There are no hidden users" + visit admin_activity_path within("#activity_#{Activity.last.id}") do diff --git a/spec/system/admin/admin_notifications_spec.rb b/spec/system/admin/admin_notifications_spec.rb index 4932d5796..63199d1d0 100644 --- a/spec/system/admin/admin_notifications_spec.rb +++ b/spec/system/admin/admin_notifications_spec.rb @@ -113,12 +113,12 @@ describe "Admin Notifications", :admin do end context "Destroy" do - scenario "A draft notification can be destroyed" do + scenario "A draft notification can be destroyed", :js do notification = create(:admin_notification) visit admin_admin_notifications_path within("#admin_notification_#{notification.id}") do - click_link "Delete" + accept_confirm { click_link "Delete" } end expect(page).to have_content "Notification deleted successfully" diff --git a/spec/system/admin/administrators_spec.rb b/spec/system/admin/administrators_spec.rb index c8da6fc80..f64c99e3e 100644 --- a/spec/system/admin/administrators_spec.rb +++ b/spec/system/admin/administrators_spec.rb @@ -29,9 +29,9 @@ describe "Admin administrators" do end end - scenario "Delete Administrator" do + scenario "Delete Administrator", :js do within "#administrator_#{user_administrator.id}" do - click_on "Delete" + accept_confirm { click_link "Delete" } end within("#administrators") do @@ -39,9 +39,9 @@ describe "Admin administrators" do end end - scenario "Delete Administrator when its the current user" do + scenario "Delete Administrator when its the current user", :js do within "#administrator_#{admin.id}" do - click_on "Delete" + accept_confirm { click_link "Delete" } end within("#error") do @@ -101,11 +101,11 @@ describe "Admin administrators" do expect(page).not_to have_content(administrator1.email) end - scenario "Delete after searching" do + scenario "Delete after searching", :js do fill_in "Search user by name or email", with: administrator2.email click_button "Search" - click_link "Delete" + accept_confirm { click_link "Delete" } expect(page).to have_content(administrator1.email) expect(page).not_to have_content(administrator2.email) diff --git a/spec/system/admin/banners_spec.rb b/spec/system/admin/banners_spec.rb index 7ad63ee61..3a977cbde 100644 --- a/spec/system/admin/banners_spec.rb +++ b/spec/system/admin/banners_spec.rb @@ -167,7 +167,7 @@ describe "Admin banners magement", :admin do expect(page).not_to have_content "Wrong text" end - scenario "Delete a banner" do + scenario "Delete a banner", :js do create(:banner, title: "Ugly banner", description: "Bad text", target_url: "http://www.url.com", @@ -176,15 +176,11 @@ describe "Admin banners magement", :admin do background_color: "#FF0000", font_color: "#FFFFFF") - visit admin_root_path - - within("#side_menu") do - click_link "Manage banners" - end + visit admin_banners_path expect(page).to have_content "Ugly banner" - click_link "Delete banner" + accept_confirm { click_link "Delete banner" } visit admin_root_path expect(page).not_to have_content "Ugly banner" diff --git a/spec/system/admin/budget_groups_spec.rb b/spec/system/admin/budget_groups_spec.rb index f5754a09d..b7ef5f9b5 100644 --- a/spec/system/admin/budget_groups_spec.rb +++ b/spec/system/admin/budget_groups_spec.rb @@ -55,22 +55,22 @@ describe "Admin budget groups", :admin do end end - scenario "Delete a group without headings" do + scenario "Delete a group without headings", :js do group = create(:budget_group, budget: budget) visit admin_budget_groups_path(budget) - within("#budget_group_#{group.id}") { click_link "Delete" } + within("#budget_group_#{group.id}") { accept_confirm { click_link "Delete" } } expect(page).to have_content "Group deleted successfully" expect(page).not_to have_selector "#budget_group_#{group.id}" end - scenario "Try to delete a group with headings" do + scenario "Try to delete a group with headings", :js do group = create(:budget_group, budget: budget) create(:budget_heading, group: group) visit admin_budget_groups_path(budget) - within("#budget_group_#{group.id}") { click_link "Delete" } + within("#budget_group_#{group.id}") { accept_confirm { click_link "Delete" } } expect(page).to have_content "You cannot delete a Group that has associated headings" expect(page).to have_selector "#budget_group_#{group.id}" diff --git a/spec/system/admin/budget_headings_spec.rb b/spec/system/admin/budget_headings_spec.rb index b2bea77ac..dec38f663 100644 --- a/spec/system/admin/budget_headings_spec.rb +++ b/spec/system/admin/budget_headings_spec.rb @@ -60,22 +60,22 @@ describe "Admin budget headings", :admin do end end - scenario "Delete a heading without investments" do + scenario "Delete a heading without investments", :js do heading = create(:budget_heading, group: group) visit admin_budget_group_headings_path(budget, group) - within("#budget_heading_#{heading.id}") { click_link "Delete" } + within("#budget_heading_#{heading.id}") { accept_confirm { click_link "Delete" } } expect(page).to have_content "Heading deleted successfully" expect(page).not_to have_selector "#budget_heading_#{heading.id}" end - scenario "Try to delete a heading with investments" do + scenario "Try to delete a heading with investments", :js do heading = create(:budget_heading, group: group, name: "Atlantis") create(:budget_investment, heading: heading) visit admin_budget_group_headings_path(budget, group) - within(".heading", text: "Atlantis") { click_link "Delete" } + within(".heading", text: "Atlantis") { accept_confirm { click_link "Delete" } } expect(page).to have_content "You cannot delete a Heading that has associated investments" expect(page).to have_content "Atlantis" diff --git a/spec/system/admin/emails/newsletters_spec.rb b/spec/system/admin/emails/newsletters_spec.rb index 7847293d7..8f3f0e315 100644 --- a/spec/system/admin/emails/newsletters_spec.rb +++ b/spec/system/admin/emails/newsletters_spec.rb @@ -98,12 +98,12 @@ describe "Admin newsletter emails", :admin do expect(page).to have_content "This is a body" end - scenario "Destroy" do + scenario "Destroy", :js do newsletter = create(:newsletter) visit admin_newsletters_path within("#newsletter_#{newsletter.id}") do - click_link "Delete" + accept_confirm { click_link "Delete" } end expect(page).to have_content "Newsletter deleted successfully" diff --git a/spec/system/admin/feature_flags_spec.rb b/spec/system/admin/feature_flags_spec.rb index 68ae8502c..f17e567c4 100644 --- a/spec/system/admin/feature_flags_spec.rb +++ b/spec/system/admin/feature_flags_spec.rb @@ -14,7 +14,7 @@ describe "Admin feature flags", :admin do end end - scenario "Disable a participatory process", :show_exceptions do + scenario "Disable a participatory process", :show_exceptions, :js do setting = Setting.find_by(key: "process.budgets") budget = create(:budget) @@ -24,10 +24,11 @@ describe "Admin feature flags", :admin do within("#edit_setting_#{setting.id}") do expect(page).to have_button "Disable" expect(page).not_to have_button "Enable" - click_button "Disable" + + accept_confirm { click_button "Disable" } end - visit admin_root_path + expect(page).to have_content "Value updated" within("#side_menu") do expect(page).not_to have_link "Participatory budgets" @@ -43,7 +44,7 @@ describe "Admin feature flags", :admin do expect(page).to have_content "Internal server error" end - scenario "Enable a disabled participatory process" do + scenario "Enable a disabled participatory process", :js do Setting["process.budgets"] = nil setting = Setting.find_by(key: "process.budgets") @@ -59,25 +60,28 @@ describe "Admin feature flags", :admin do within("#edit_setting_#{setting.id}") do expect(page).to have_button "Enable" expect(page).not_to have_button "Disable" - click_button "Enable" + + accept_confirm { click_button "Enable" } end - visit admin_root_path + expect(page).to have_content "Value updated" within("#side_menu") do expect(page).to have_link "Participatory budgets" end end - scenario "Disable a feature" do + scenario "Disable a feature", :js do setting = Setting.find_by(key: "feature.twitter_login") visit admin_settings_path + click_link "Features" within("#edit_setting_#{setting.id}") do expect(page).to have_button "Disable" expect(page).not_to have_button "Enable" - click_button "Disable" + + accept_confirm { click_button "Disable" } end expect(page).to have_content "Value updated" @@ -88,15 +92,17 @@ describe "Admin feature flags", :admin do end end - scenario "Enable a disabled feature" do + scenario "Enable a disabled feature", :js do setting = Setting.find_by(key: "feature.map") visit admin_settings_path + click_link "Features" within("#edit_setting_#{setting.id}") do expect(page).to have_button "Enable" expect(page).not_to have_button "Disable" - click_button "Enable" + + accept_confirm { click_button "Enable" } end expect(page).to have_content "Value updated" diff --git a/spec/system/admin/geozones_spec.rb b/spec/system/admin/geozones_spec.rb index 0db7cacfa..c74c89642 100644 --- a/spec/system/admin/geozones_spec.rb +++ b/spec/system/admin/geozones_spec.rb @@ -66,25 +66,25 @@ describe "Admin geozones", :admin do end end - scenario "Delete geozone with no associated elements" do + scenario "Delete geozone with no associated elements", :js do geozone = create(:geozone, name: "Delete me!") visit admin_geozones_path - within("#geozone_#{geozone.id}") { click_link "Delete" } + within("#geozone_#{geozone.id}") { accept_confirm { click_link "Delete" } } expect(page).to have_content "Geozone successfully deleted" expect(page).not_to have_content("Delete me!") expect(Geozone.where(id: geozone.id)).to be_empty end - scenario "Delete geozone with associated element" do + scenario "Delete geozone with associated element", :js do geozone = create(:geozone, name: "Delete me!") create(:proposal, geozone: geozone) visit admin_geozones_path - within("#geozone_#{geozone.id}") { click_link "Delete" } + within("#geozone_#{geozone.id}") { accept_confirm { click_link "Delete" } } expect(page).to have_content "This geozone can't be deleted since there are elements attached to it" diff --git a/spec/system/admin/hidden_budget_investments_spec.rb b/spec/system/admin/hidden_budget_investments_spec.rb index 0653914b2..0c4b6664d 100644 --- a/spec/system/admin/hidden_budget_investments_spec.rb +++ b/spec/system/admin/hidden_budget_investments_spec.rb @@ -13,12 +13,12 @@ describe "Admin hidden budget investments", :admin do expect(page).to have_content(investment.description) end - scenario "Restore" do + scenario "Restore", :js do investment = create(:budget_investment, :hidden, heading: heading) visit admin_hidden_budget_investments_path - click_link "Restore" + accept_confirm { click_link "Restore" } expect(page).not_to have_content(investment.title) @@ -78,13 +78,13 @@ describe "Admin hidden budget investments", :admin do expect(page).to have_content("Confirmed investment") end - scenario "Action links remember the pagination setting and the filter" do + scenario "Action links remember the pagination setting and the filter", :js do allow(Budget::Investment).to receive(:default_per_page).and_return(2) 4.times { create(:budget_investment, :hidden, :with_confirmed_hide, heading: heading) } visit admin_hidden_budget_investments_path(filter: "with_confirmed_hide", page: 2) - click_on("Restore", match: :first, exact: true) + accept_confirm { click_link "Restore", match: :first, exact: true } expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) diff --git a/spec/system/admin/hidden_comments_spec.rb b/spec/system/admin/hidden_comments_spec.rb index 1d916437b..4c7f114c8 100644 --- a/spec/system/admin/hidden_comments_spec.rb +++ b/spec/system/admin/hidden_comments_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" describe "Admin hidden comments", :admin do - scenario "Do not show comments from blocked users" do + scenario "Do not show comments from blocked users", :js do comment = create(:comment, :hidden, body: "SPAM from SPAMMER") proposal = create(:proposal, author: comment.author) create(:comment, commentable: proposal, user: comment.author, body: "Good Proposal!") @@ -11,11 +11,15 @@ describe "Admin hidden comments", :admin do expect(page).not_to have_content("Good Proposal!") visit proposal_path(proposal) + within("#proposal_#{proposal.id}") do - click_link "Hide author" + accept_confirm { click_link "Hide author" } end + expect(page).to have_current_path debates_path + visit admin_hidden_comments_path + expect(page).not_to have_content("SPAM from SPAMMER") expect(page).not_to have_content("Good Proposal!") end @@ -59,11 +63,11 @@ describe "Admin hidden comments", :admin do expect(page).not_to have_link("This is SPAM comment on proposal") end - scenario "Restore" do + scenario "Restore", :js do comment = create(:comment, :hidden, body: "Not really SPAM") visit admin_hidden_comments_path - click_link "Restore" + accept_confirm { click_link "Restore" } expect(page).not_to have_content(comment.body) @@ -119,13 +123,13 @@ describe "Admin hidden comments", :admin do expect(page).to have_content("Confirmed comment") end - scenario "Action links remember the pagination setting and the filter" do + scenario "Action links remember the pagination setting and the filter", :js do allow(Comment).to receive(:default_per_page).and_return(2) 4.times { create(:comment, :hidden, :with_confirmed_hide) } visit admin_hidden_comments_path(filter: "with_confirmed_hide", page: 2) - click_on("Restore", match: :first, exact: true) + accept_confirm { click_link "Restore", match: :first, exact: true } expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) diff --git a/spec/system/admin/hidden_debates_spec.rb b/spec/system/admin/hidden_debates_spec.rb index ddf882241..a7ef9f327 100644 --- a/spec/system/admin/hidden_debates_spec.rb +++ b/spec/system/admin/hidden_debates_spec.rb @@ -1,11 +1,11 @@ require "rails_helper" -describe "Admin hidden debates", :admin do +describe "Admin hidden debates", :admin, :js do scenario "Restore" do debate = create(:debate, :hidden) visit admin_hidden_debates_path - click_link "Restore" + accept_confirm { click_link "Restore" } expect(page).not_to have_content(debate.title) @@ -65,13 +65,13 @@ describe "Admin hidden debates", :admin do expect(page).to have_content("Confirmed debate") end - scenario "Action links remember the pagination setting and the filter" do + scenario "Action links remember the pagination setting and the filter", :js do allow(Debate).to receive(:default_per_page).and_return(2) 4.times { create(:debate, :hidden, :with_confirmed_hide) } visit admin_hidden_debates_path(filter: "with_confirmed_hide", page: 2) - click_on("Restore", match: :first, exact: true) + accept_confirm { click_link "Restore", match: :first, exact: true } expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) diff --git a/spec/system/admin/hidden_proposals_spec.rb b/spec/system/admin/hidden_proposals_spec.rb index 07b2f4af4..9de570b45 100644 --- a/spec/system/admin/hidden_proposals_spec.rb +++ b/spec/system/admin/hidden_proposals_spec.rb @@ -11,11 +11,11 @@ describe "Admin hidden proposals", :admin do expect(page).to have_content(proposal.video_url) end - scenario "Restore" do + scenario "Restore", :js do proposal = create(:proposal, :hidden) visit admin_hidden_proposals_path - click_link "Restore" + accept_confirm { click_link "Restore" } expect(page).not_to have_content(proposal.title) @@ -75,13 +75,13 @@ describe "Admin hidden proposals", :admin do expect(page).to have_content("Confirmed proposal") end - scenario "Action links remember the pagination setting and the filter" do + scenario "Action links remember the pagination setting and the filter", :js do allow(Proposal).to receive(:default_per_page).and_return(2) 4.times { create(:proposal, :hidden, :with_confirmed_hide) } visit admin_hidden_proposals_path(filter: "with_confirmed_hide", page: 2) - click_on("Restore", match: :first, exact: true) + accept_confirm { click_link "Restore", match: :first, exact: true } expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) diff --git a/spec/system/admin/hidden_users_spec.rb b/spec/system/admin/hidden_users_spec.rb index 3bfe0c7b0..8e51edaca 100644 --- a/spec/system/admin/hidden_users_spec.rb +++ b/spec/system/admin/hidden_users_spec.rb @@ -17,11 +17,11 @@ describe "Admin hidden users", :admin do expect(page).to have_content(comment2.body) end - scenario "Restore" do + scenario "Restore", :js do user = create(:user, :hidden) visit admin_hidden_users_path - click_link "Restore" + accept_confirm { click_link "Restore" } expect(page).not_to have_content(user.username) @@ -76,13 +76,13 @@ describe "Admin hidden users", :admin do expect(page).to have_content("Confirmed user") end - scenario "Action links remember the pagination setting and the filter" do + scenario "Action links remember the pagination setting and the filter", :js do allow(User).to receive(:default_per_page).and_return(2) 4.times { create(:user, :hidden, :with_confirmed_hide) } visit admin_hidden_users_path(filter: "with_confirmed_hide", page: 2) - click_on("Restore", match: :first, exact: true) + accept_confirm { click_link "Restore", match: :first, exact: true } expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) diff --git a/spec/system/admin/local_census_records_spec.rb b/spec/system/admin/local_census_records_spec.rb index a35f875fc..3699b7477 100644 --- a/spec/system/admin/local_census_records_spec.rb +++ b/spec/system/admin/local_census_records_spec.rb @@ -134,11 +134,12 @@ describe "Admin local census records", :admin do let!(:local_census_record) { create(:local_census_record) } let!(:deleted_document_number) { local_census_record.document_number } - scenario "Should show successful destroy notice" do + scenario "Should show successful destroy notice", :js do visit admin_local_census_records_path expect(page).to have_content deleted_document_number - click_on "Delete" + + accept_confirm { click_on "Delete" } expect(page).to have_content "Local census record removed successfully!" expect(page).not_to have_content deleted_document_number diff --git a/spec/system/admin/managers_spec.rb b/spec/system/admin/managers_spec.rb index 6b46fa15e..56c902cdb 100644 --- a/spec/system/admin/managers_spec.rb +++ b/spec/system/admin/managers_spec.rb @@ -25,8 +25,8 @@ describe "Admin managers", :admin do end end - scenario "Delete Manager" do - click_link "Delete" + scenario "Delete Manager", :js do + accept_confirm { click_link "Delete" } within("#managers") do expect(page).not_to have_content manager.name @@ -82,11 +82,11 @@ describe "Admin managers", :admin do expect(page).not_to have_content(manager1.email) end - scenario "Delete after searching" do + scenario "Delete after searching", :js do fill_in "Search user by name or email", with: manager2.email click_button "Search" - click_link "Delete" + accept_confirm { click_link "Delete" } expect(page).to have_content(manager1.email) expect(page).not_to have_content(manager2.email) diff --git a/spec/system/admin/milestone_statuses_spec.rb b/spec/system/admin/milestone_statuses_spec.rb index 10d1b109e..9436b57bd 100644 --- a/spec/system/admin/milestone_statuses_spec.rb +++ b/spec/system/admin/milestone_statuses_spec.rb @@ -72,13 +72,13 @@ describe "Admin milestone statuses", :admin do end context "Delete" do - scenario "Hides status" do + scenario "Hides status", :js do status = create(:milestone_status) visit admin_milestone_statuses_path within("#milestone_status_#{status.id}") do - click_link "Delete" + accept_confirm { click_link "Delete" } end expect(page).not_to have_content status.name diff --git a/spec/system/admin/moderators_spec.rb b/spec/system/admin/moderators_spec.rb index df1af19b4..70ad342ae 100644 --- a/spec/system/admin/moderators_spec.rb +++ b/spec/system/admin/moderators_spec.rb @@ -25,8 +25,8 @@ describe "Admin moderators", :admin do end end - scenario "Delete Moderator" do - click_link "Delete" + scenario "Delete Moderator", :js do + accept_confirm { click_link "Delete" } within("#moderators") do expect(page).not_to have_content moderator.name @@ -82,11 +82,11 @@ describe "Admin moderators", :admin do expect(page).not_to have_content(moderator1.email) end - scenario "Delete after searching" do + scenario "Delete after searching", :js do fill_in "Search user by name or email", with: moderator2.email click_button "Search" - click_link "Delete" + accept_confirm { click_link "Delete" } expect(page).to have_content(moderator1.email) expect(page).not_to have_content(moderator2.email) diff --git a/spec/system/admin/poll/officers_spec.rb b/spec/system/admin/poll/officers_spec.rb index cf08b95a0..18773655b 100644 --- a/spec/system/admin/poll/officers_spec.rb +++ b/spec/system/admin/poll/officers_spec.rb @@ -25,8 +25,8 @@ describe "Admin poll officers", :admin do end end - scenario "Delete" do - click_link "Delete position" + scenario "Delete", :js do + accept_confirm { click_link "Delete position" } expect(page).not_to have_css "#officers" end diff --git a/spec/system/admin/poll/questions_spec.rb b/spec/system/admin/poll/questions_spec.rb index 3432f221f..09dfd7e75 100644 --- a/spec/system/admin/poll/questions_spec.rb +++ b/spec/system/admin/poll/questions_spec.rb @@ -134,7 +134,7 @@ describe "Admin poll questions", :admin do expect(page).not_to have_content(old_title) end - scenario "Destroy" do + scenario "Destroy", :js do poll = create(:poll) question1 = create(:poll_question, poll: poll) question2 = create(:poll_question, poll: poll) @@ -142,7 +142,7 @@ describe "Admin poll questions", :admin do visit admin_poll_path(poll) within("#poll_question_#{question1.id}") do - click_link "Delete" + accept_confirm { click_link "Delete" } end expect(page).not_to have_content(question1.title) diff --git a/spec/system/admin/poll/shifts_spec.rb b/spec/system/admin/poll/shifts_spec.rb index 0aef037d1..11e3d41e1 100644 --- a/spec/system/admin/poll/shifts_spec.rb +++ b/spec/system/admin/poll/shifts_spec.rb @@ -159,7 +159,7 @@ describe "Admin shifts", :admin do expect(page).to have_content "A date must be selected" end - scenario "Destroy" do + scenario "Destroy", :js do poll = create(:poll, :current) booth = create(:poll_booth, polls: [poll]) officer = create(:poll_officer) @@ -174,14 +174,14 @@ describe "Admin shifts", :admin do expect(page).to have_css(".shift", count: 1) within("#shift_#{shift.id}") do - click_link "Remove" + accept_confirm { click_link "Remove" } end expect(page).to have_content "Shift removed" expect(page).to have_css(".shift", count: 0) end - scenario "Try to destroy with associated recount" do + scenario "Try to destroy with associated recount", :js do assignment = create(:poll_booth_assignment) officer_assignment = create(:poll_officer_assignment, booth_assignment: assignment) create(:poll_recount, booth_assignment: assignment, officer_assignment: officer_assignment) @@ -198,7 +198,7 @@ describe "Admin shifts", :admin do expect(page).to have_css(".shift", count: 1) within("#shift_#{shift.id}") do - click_link "Remove" + accept_confirm { click_link "Remove" } end expect(page).not_to have_content "Shift removed" @@ -206,7 +206,7 @@ describe "Admin shifts", :admin do expect(page).to have_css(".shift", count: 1) end - scenario "try to destroy with associated partial results" do + scenario "try to destroy with associated partial results", :js do assignment = create(:poll_booth_assignment) officer_assignment = create(:poll_officer_assignment, booth_assignment: assignment) create(:poll_partial_result, @@ -225,7 +225,7 @@ describe "Admin shifts", :admin do expect(page).to have_css(".shift", count: 1) within("#shift_#{shift.id}") do - click_link "Remove" + accept_confirm { click_link "Remove" } end expect(page).not_to have_content "Shift removed" diff --git a/spec/system/admin/proposal_notifications_spec.rb b/spec/system/admin/proposal_notifications_spec.rb index 1563ed874..b90025c3c 100644 --- a/spec/system/admin/proposal_notifications_spec.rb +++ b/spec/system/admin/proposal_notifications_spec.rb @@ -9,11 +9,11 @@ describe "Admin proposal notifications", :admin do expect(page).to have_content(proposal_notification.body) end - scenario "Restore" do + scenario "Restore", :js do proposal_notification = create(:proposal_notification, :hidden, created_at: Date.current - 5.days) visit admin_hidden_proposal_notifications_path - click_link "Restore" + accept_confirm { click_link "Restore" } expect(page).not_to have_content(proposal_notification.title) @@ -74,13 +74,13 @@ describe "Admin proposal notifications", :admin do expect(page).to have_content("Confirmed notification") end - scenario "Action links remember the pagination setting and the filter" do + scenario "Action links remember the pagination setting and the filter", :js do allow(ProposalNotification).to receive(:default_per_page).and_return(2) 4.times { create(:proposal_notification, :hidden, :with_confirmed_hide) } visit admin_hidden_proposal_notifications_path(filter: "with_confirmed_hide", page: 2) - click_on("Restore", match: :first, exact: true) + accept_confirm { click_link "Restore", match: :first, exact: true } expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) diff --git a/spec/system/admin/site_customization/content_blocks_spec.rb b/spec/system/admin/site_customization/content_blocks_spec.rb index 5cd02b76b..84f6894b6 100644 --- a/spec/system/admin/site_customization/content_blocks_spec.rb +++ b/spec/system/admin/site_customization/content_blocks_spec.rb @@ -81,14 +81,14 @@ describe "Admin custom content blocks", :admin do end context "Delete" do - scenario "From index page" do + scenario "From index page", :js do block = create(:site_customization_content_block) visit admin_site_customization_content_blocks_path expect(page).to have_content("#{block.name} (#{block.locale})") expect(page).to have_content(block.body) - click_link "Delete block" + accept_confirm { click_link "Delete block" } expect(page).not_to have_content("#{block.name} (#{block.locale})") expect(page).not_to have_content(block.body) diff --git a/spec/system/admin/tags_spec.rb b/spec/system/admin/tags_spec.rb index 28bcec539..6c4b3bea1 100644 --- a/spec/system/admin/tags_spec.rb +++ b/spec/system/admin/tags_spec.rb @@ -29,7 +29,7 @@ describe "Admin tags", :admin do expect(page).to have_content "important issues" end - scenario "Delete" do + scenario "Delete", :js do tag2 = create(:tag, :category, name: "bad tag") create(:debate, tag_list: "bad tag") @@ -39,15 +39,14 @@ describe "Admin tags", :admin do expect(page).to have_content "bad tag" within("#tag_#{tag2.id}") do - click_link "Delete topic" + accept_confirm { click_link "Delete topic" } end - visit admin_tags_path - expect(page).to have_content "Existence" expect(page).not_to have_content "bad tag" + expect(page).to have_content "Existence" end - scenario "Delete tag with hidden taggables" do + scenario "Delete tag with hidden taggables", :js do tag2 = create(:tag, :category, name: "bad tag") debate = create(:debate, tag_list: "bad tag") debate.hide @@ -58,12 +57,11 @@ describe "Admin tags", :admin do expect(page).to have_content "bad tag" within("#tag_#{tag2.id}") do - click_link "Delete topic" + accept_confirm { click_link "Delete topic" } end - visit admin_tags_path - expect(page).to have_content "Existence" expect(page).not_to have_content "bad tag" + expect(page).to have_content "Existence" end context "Manage only tags of kind category" do diff --git a/spec/system/admin/valuator_groups_spec.rb b/spec/system/admin/valuator_groups_spec.rb index 53b48b323..ab5ac5f25 100644 --- a/spec/system/admin/valuator_groups_spec.rb +++ b/spec/system/admin/valuator_groups_spec.rb @@ -63,11 +63,11 @@ describe "Valuator groups", :admin do expect(page).to have_content "Health and Sports" end - scenario "Delete" do + scenario "Delete", :js do create(:valuator_group) visit admin_valuator_groups_path - click_link "Delete" + accept_confirm { click_link "Delete" } expect(page).to have_content "Valuator group deleted successfully" expect(page).to have_content "There are no valuator groups" diff --git a/spec/system/admin/valuators_spec.rb b/spec/system/admin/valuators_spec.rb index f5108dd63..38d4a3009 100644 --- a/spec/system/admin/valuators_spec.rb +++ b/spec/system/admin/valuators_spec.rb @@ -50,8 +50,8 @@ describe "Admin valuators", :admin do expect(page).not_to have_content "Can edit dossier" end - scenario "Destroy" do - click_link "Delete" + scenario "Destroy", :js do + accept_confirm { click_link "Delete" } within("#valuators") do expect(page).not_to have_content(valuator.name) diff --git a/spec/system/budgets/investments_spec.rb b/spec/system/budgets/investments_spec.rb index 86776909d..1acbd660b 100644 --- a/spec/system/budgets/investments_spec.rb +++ b/spec/system/budgets/investments_spec.rb @@ -997,7 +997,7 @@ describe "Budget Investments" do end end - scenario "Author can destroy while on the accepting phase" do + scenario "Author can destroy while on the accepting phase", :js do user = create(:user, :level_two) investment1 = create(:budget_investment, heading: heading, price: 10000, author: user) @@ -1006,7 +1006,8 @@ describe "Budget Investments" do within("#budget_investment_#{investment1.id}") do expect(page).to have_content(investment1.title) - click_link("Delete") + + accept_confirm { click_link("Delete") } end visit user_path(user, tab: :budget_investments) diff --git a/spec/system/debates_spec.rb b/spec/system/debates_spec.rb index 5ef6e98c2..b32dc4c84 100644 --- a/spec/system/debates_spec.rb +++ b/spec/system/debates_spec.rb @@ -772,33 +772,31 @@ describe "Debates" do end end - scenario "Mark/Unmark a debate as featured", :admin do + scenario "Mark/Unmark a debate as featured", :admin, :js do debate = create(:debate) visit debates_path within("#debates") do - expect(page).not_to have_content "Featured" + expect(page).not_to have_content "FEATURED" end click_link debate.title - - click_link "Featured" - - visit debates_path + accept_confirm { click_link "Featured" } within("#debates") do - expect(page).to have_content "Featured" + expect(page).to have_content "FEATURED" end within("#featured-debates") do expect(page).to have_content debate.title + + click_link debate.title end - visit debate_path(debate) - click_link "Unmark featured" + accept_confirm { click_link "Unmark featured" } within("#debates") do - expect(page).not_to have_content "Featured" + expect(page).not_to have_content "FEATURED" end end diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index 537e4b6d0..83705376b 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -365,7 +365,7 @@ describe "Emails" do expect(email).to have_body_text(budget_path(budget)) end - scenario "Unfeasible investment" do + scenario "Unfeasible investment", :js do budget.update!(phase: "valuating") valuator = create(:valuator) investment = create(:budget_investment, author: author, budget: budget, valuators: [valuator]) @@ -375,7 +375,7 @@ describe "Emails" do within_fieldset("Feasibility") { choose "Unfeasible" } fill_in "Feasibility explanation", with: "This is not legal as stated in Article 34.9" - check "Valuation finished" + accept_confirm { check "Valuation finished" } click_button "Save changes" expect(page).to have_content "Dossier updated" @@ -478,6 +478,8 @@ describe "Emails" do click_link "Send" + expect(page).to have_content "Newsletter sent successfully" + expect(unread_emails_for(user_with_newsletter_in_segment_1.email).count).to eq 1 expect(unread_emails_for(user_with_newsletter_in_segment_2.email).count).to eq 1 expect(unread_emails_for(user_with_newsletter_not_in_segment.email).count).to eq 0 diff --git a/spec/system/moderation/budget_investments_spec.rb b/spec/system/moderation/budget_investments_spec.rb index f917a8e8f..b8c71bdf3 100644 --- a/spec/system/moderation/budget_investments_spec.rb +++ b/spec/system/moderation/budget_investments_spec.rb @@ -50,7 +50,7 @@ describe "Moderate budget investments" do end describe "moderate in bulk" do - describe "When an investment has been selected for moderation" do + describe "When an investment has been selected for moderation", :js do before do visit moderation_budget_investments_path @@ -66,7 +66,8 @@ describe "Moderate budget investments" do end scenario "Hide the investment" do - click_button "Hide budget investments" + accept_confirm { click_button "Hide budget investments" } + expect(page).not_to have_css("investment_#{investment.id}") investment.reload @@ -75,7 +76,8 @@ describe "Moderate budget investments" do end scenario "Block the author" do - click_button "Block authors" + accept_confirm { click_button "Block authors" } + expect(page).not_to have_css("investment_#{investment.id}") investment.reload @@ -84,7 +86,8 @@ describe "Moderate budget investments" do end scenario "Ignore the investment" do - click_button "Mark as viewed" + accept_confirm { click_button "Mark as viewed" } + expect(page).not_to have_css("investment_#{investment.id}") investment.reload @@ -111,13 +114,13 @@ describe "Moderate budget investments" do end end - scenario "remembering page, filter and order" do + scenario "remembering page, filter and order", :js do stub_const("#{ModerateActions}::PER_PAGE", 2) create_list(:budget_investment, 4, heading: heading, author: create(:user)) visit moderation_budget_investments_path(filter: "all", page: "2", order: "created_at") - click_button "Mark as viewed" + accept_confirm { click_button "Mark as viewed" } expect(page).to have_selector(".js-order-selector[data-order='created_at']") diff --git a/spec/system/moderation/comments_spec.rb b/spec/system/moderation/comments_spec.rb index 75fb2232c..7ec81c848 100644 --- a/spec/system/moderation/comments_spec.rb +++ b/spec/system/moderation/comments_spec.rb @@ -69,7 +69,7 @@ describe "Moderate comments" do end describe "moderate in bulk" do - describe "When a comment has been selected for moderation" do + describe "When a comment has been selected for moderation", :js do let!(:comment) { create(:comment) } before do @@ -86,21 +86,24 @@ describe "Moderate comments" do end scenario "Hide the comment" do - click_on "Hide comments" + accept_confirm { click_button "Hide comments" } + expect(page).not_to have_css("comment_#{comment.id}") expect(comment.reload).to be_hidden expect(comment.user).not_to be_hidden end scenario "Block the user" do - click_on "Block authors" + accept_confirm { click_button "Block authors" } + expect(page).not_to have_css("comment_#{comment.id}") expect(comment.reload).to be_hidden expect(comment.user).to be_hidden end scenario "Ignore the comment" do - click_on "Mark as viewed" + accept_confirm { click_button "Mark as viewed" } + expect(page).not_to have_css("comment_#{comment.id}") expect(comment.reload).to be_ignored_flag expect(comment.reload).not_to be_hidden @@ -124,13 +127,13 @@ describe "Moderate comments" do end end - scenario "remembering page, filter and order" do + scenario "remembering page, filter and order", :js do stub_const("#{ModerateActions}::PER_PAGE", 2) create_list(:comment, 4) visit moderation_comments_path(filter: "all", page: "2", order: "newest") - click_on "Mark as viewed" + accept_confirm { click_button "Mark as viewed" } expect(page).to have_selector(".js-order-selector[data-order='newest']") diff --git a/spec/system/moderation/debates_spec.rb b/spec/system/moderation/debates_spec.rb index eabf8eaef..a4c83e3c9 100644 --- a/spec/system/moderation/debates_spec.rb +++ b/spec/system/moderation/debates_spec.rb @@ -42,7 +42,7 @@ describe "Moderate debates" do end describe "moderate in bulk" do - describe "When a debate has been selected for moderation" do + describe "When a debate has been selected for moderation", :js do let!(:debate) { create(:debate) } before do @@ -59,21 +59,24 @@ describe "Moderate debates" do end scenario "Hide the debate" do - click_on "Hide debates" + accept_confirm { click_button "Hide debates" } + expect(page).not_to have_css("debate_#{debate.id}") expect(debate.reload).to be_hidden expect(debate.author).not_to be_hidden end scenario "Block the author" do - click_on "Block authors" + accept_confirm { click_button "Block authors" } + expect(page).not_to have_css("debate_#{debate.id}") expect(debate.reload).to be_hidden expect(debate.author).to be_hidden end scenario "Ignore the debate" do - click_on "Mark as viewed" + accept_confirm { click_button "Mark as viewed" } + expect(page).not_to have_css("debate_#{debate.id}") expect(debate.reload).to be_ignored_flag expect(debate.reload).not_to be_hidden @@ -97,13 +100,13 @@ describe "Moderate debates" do end end - scenario "remembering page, filter and order" do + scenario "remembering page, filter and order", :js do stub_const("#{ModerateActions}::PER_PAGE", 2) create_list(:debate, 4) visit moderation_debates_path(filter: "all", page: "2", order: "created_at") - click_on "Mark as viewed" + accept_confirm { click_button "Mark as viewed" } expect(page).to have_selector(".js-order-selector[data-order='created_at']") diff --git a/spec/system/moderation/proposal_notifications_spec.rb b/spec/system/moderation/proposal_notifications_spec.rb index 924a2b5d9..630c167ba 100644 --- a/spec/system/moderation/proposal_notifications_spec.rb +++ b/spec/system/moderation/proposal_notifications_spec.rb @@ -45,7 +45,7 @@ describe "Moderate proposal notifications" do end describe "moderate in bulk" do - describe "When a proposal has been selected for moderation" do + describe "When a proposal has been selected for moderation", :js do let!(:proposal_notification) { create(:proposal_notification, created_at: Date.current - 4.days) } before do @@ -60,7 +60,8 @@ describe "Moderate proposal notifications" do end scenario "Hide the proposal" do - click_on "Hide proposals" + accept_confirm { click_button "Hide proposals" } + expect(page).not_to have_css("#proposal_notification_#{proposal_notification.id}") expect(proposal_notification.reload).to be_hidden expect(proposal_notification.author).not_to be_hidden @@ -69,7 +70,9 @@ describe "Moderate proposal notifications" do scenario "Block the author" do author = create(:user) proposal_notification.update!(author: author) - click_on "Block authors" + + accept_confirm { click_button "Block authors" } + expect(page).not_to have_css("#proposal_notification_#{proposal_notification.id}") expect(proposal_notification.reload).to be_hidden expect(author.reload).to be_hidden @@ -100,13 +103,13 @@ describe "Moderate proposal notifications" do end end - scenario "remembering page, filter and order" do + scenario "remembering page, filter and order", :js do stub_const("#{ModerateActions}::PER_PAGE", 2) create_list(:proposal, 4) visit moderation_proposal_notifications_path(filter: "all", page: "2", order: "created_at") - click_button "Mark as viewed" + accept_confirm { click_button "Mark as viewed" } expect(page).to have_selector(".js-order-selector[data-order='created_at']") diff --git a/spec/system/moderation/proposals_spec.rb b/spec/system/moderation/proposals_spec.rb index 2a9d8452b..0deee7c80 100644 --- a/spec/system/moderation/proposals_spec.rb +++ b/spec/system/moderation/proposals_spec.rb @@ -43,7 +43,7 @@ describe "Moderate proposals" do describe "moderate in bulk" do let!(:proposal) { create(:proposal) } - describe "When a proposal has been selected for moderation" do + describe "When a proposal has been selected for moderation", :js do before do visit moderation_proposals_path within(".menu.simple") do @@ -58,21 +58,24 @@ describe "Moderate proposals" do end scenario "Hide the proposal" do - click_on "Hide proposals" + accept_confirm { click_button "Hide proposals" } + expect(page).not_to have_css("proposal_#{proposal.id}") expect(proposal.reload).to be_hidden expect(proposal.author).not_to be_hidden end scenario "Block the author" do - click_on "Block authors" + accept_confirm { click_button "Block authors" } + expect(page).not_to have_css("proposal_#{proposal.id}") expect(proposal.reload).to be_hidden expect(proposal.author).to be_hidden end scenario "Ignore the proposal" do - click_button "Mark as viewed" + accept_confirm { click_button "Mark as viewed" } + expect(page).not_to have_css("proposal_#{proposal.id}") expect(proposal.reload).to be_ignored_flag expect(proposal.reload).not_to be_hidden @@ -96,13 +99,13 @@ describe "Moderate proposals" do end end - scenario "remembering page, filter and order" do + scenario "remembering page, filter and order", :js do stub_const("#{ModerateActions}::PER_PAGE", 2) create_list(:proposal, 4) visit moderation_proposals_path(filter: "all", page: "2", order: "created_at") - click_button "Mark as viewed" + accept_confirm { click_button "Mark as viewed" } expect(page).to have_selector(".js-order-selector[data-order='created_at']") diff --git a/spec/system/moderation/users_spec.rb b/spec/system/moderation/users_spec.rb index 62a72d59a..e616da25b 100644 --- a/spec/system/moderation/users_spec.rb +++ b/spec/system/moderation/users_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" describe "Moderate users" do - scenario "Hide" do + scenario "Hide", :js do citizen = create(:user) moderator = create(:moderator) @@ -24,7 +24,7 @@ describe "Moderate users" do visit debate_path(debate1) within("#debate_#{debate1.id}") do - click_link "Hide author" + accept_confirm { click_link "Hide author" } end expect(page).to have_current_path(debates_path) diff --git a/spec/system/valuation/budget_investments_spec.rb b/spec/system/valuation/budget_investments_spec.rb index 4f8a3ad28..6ff9532ac 100644 --- a/spec/system/valuation/budget_investments_spec.rb +++ b/spec/system/valuation/budget_investments_spec.rb @@ -379,15 +379,17 @@ describe "Valuation budget investments" do end end - scenario "Finish valuation" do + scenario "Finish valuation", :js do investment.update!(visible_to_valuators: true) visit valuation_budget_budget_investment_path(budget, investment) click_link "Edit dossier" - find_field("budget_investment[valuation_finished]").click + accept_confirm { find_field("budget_investment[valuation_finished]").click } click_button "Save changes" + expect(page).to have_content "Dossier updated" + visit valuation_budget_budget_investments_path(budget) expect(page).not_to have_content investment.title click_link "Valuation finished"