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.
This commit is contained in:
Javi Martín
2021-03-29 13:28:41 +02:00
parent fbc78984dc
commit b2bc4d19f5
38 changed files with 221 additions and 178 deletions

View File

@@ -108,11 +108,11 @@ shared_examples "admin_progressable" do |factory_name, path_name|
end end
context "Delete" do context "Delete" do
scenario "Remove progress bar" do scenario "Remove progress bar", :js do
bar = create(:progress_bar, progressable: progressable, percentage: 34) bar = create(:progress_bar, progressable: progressable, percentage: 34)
visit path 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).to have_content "Progress bar deleted successfully"
expect(page).not_to have_content "34%" expect(page).not_to have_content "34%"

View File

@@ -95,37 +95,37 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
end end
context "Destroy" do 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 login_as documentable.author
visit send(documentable_path, arguments) visit send(documentable_path, arguments)
within "#document_#{document.id}" do within "#document_#{document.id}" do
click_on "Delete document" accept_confirm { click_link "Delete document" }
end end
expect(page).to have_content "Document was deleted successfully." expect(page).to have_content "Document was deleted successfully."
end 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 login_as documentable.author
visit send(documentable_path, arguments) visit send(documentable_path, arguments)
within "#document_#{document.id}" do within "#document_#{document.id}" do
click_on "Delete document" accept_confirm { click_link "Delete document" }
end end
expect(page).not_to have_content "Documents (0)" expect(page).not_to have_content "Documents (0)"
end 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 login_as documentable.author
visit send(documentable_path, arguments) visit send(documentable_path, arguments)
within "#document_#{document.id}" do within "#document_#{document.id}" do
click_on "Delete document" accept_confirm { click_link "Delete document" }
end end
within "##{ActionView::RecordIdentifier.dom_id(documentable)}" do within "##{ActionView::RecordIdentifier.dom_id(documentable)}" do

View File

@@ -27,7 +27,7 @@ describe "Admin activity" do
end end
end end
scenario "Shows moderation activity from moderation screen" do scenario "Shows moderation activity from moderation screen", :js do
proposal1 = create(:proposal) proposal1 = create(:proposal)
proposal2 = create(:proposal) proposal2 = create(:proposal)
proposal3 = create(:proposal) proposal3 = create(:proposal)
@@ -42,7 +42,9 @@ describe "Admin activity" do
check "proposal_#{proposal3.id}_check" check "proposal_#{proposal3.id}_check"
end end
click_on "Hide proposals" accept_confirm { click_button "Hide proposals" }
expect(page).not_to have_content(proposal1.title)
visit admin_activity_path visit admin_activity_path
@@ -51,15 +53,17 @@ describe "Admin activity" do
expect(page).to have_content(proposal3.title) expect(page).to have_content(proposal3.title)
end end
scenario "Shows admin restores" do scenario "Shows admin restores", :js do
proposal = create(:proposal, :hidden) proposal = create(:proposal, :hidden)
visit admin_hidden_proposals_path visit admin_hidden_proposals_path
within("#proposal_#{proposal.id}") do within("#proposal_#{proposal.id}") do
click_on "Restore" accept_confirm { click_link "Restore" }
end end
expect(page).to have_content "There are no hidden proposals"
visit admin_activity_path visit admin_activity_path
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
@@ -90,7 +94,7 @@ describe "Admin activity" do
end end
end end
scenario "Shows moderation activity from moderation screen" do scenario "Shows moderation activity from moderation screen", :js do
debate1 = create(:debate) debate1 = create(:debate)
debate2 = create(:debate) debate2 = create(:debate)
debate3 = create(:debate) debate3 = create(:debate)
@@ -105,7 +109,9 @@ describe "Admin activity" do
check "debate_#{debate3.id}_check" check "debate_#{debate3.id}_check"
end end
click_on "Hide debates" accept_confirm { click_button "Hide debates" }
expect(page).not_to have_content(debate1.title)
visit admin_activity_path visit admin_activity_path
@@ -114,15 +120,17 @@ describe "Admin activity" do
expect(page).to have_content(debate3.title) expect(page).to have_content(debate3.title)
end end
scenario "Shows admin restores" do scenario "Shows admin restores", :js do
debate = create(:debate, :hidden) debate = create(:debate, :hidden)
visit admin_hidden_debates_path visit admin_hidden_debates_path
within("#debate_#{debate.id}") do within("#debate_#{debate.id}") do
click_on "Restore" accept_confirm { click_link "Restore" }
end end
expect(page).to have_content "There are no hidden debates"
visit admin_activity_path visit admin_activity_path
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
@@ -154,7 +162,7 @@ describe "Admin activity" do
end end
end end
scenario "Shows moderation activity from moderation screen" do scenario "Shows moderation activity from moderation screen", :js do
comment1 = create(:comment, body: "SPAM") comment1 = create(:comment, body: "SPAM")
comment2 = create(:comment) comment2 = create(:comment)
comment3 = create(:comment, body: "Offensive!") comment3 = create(:comment, body: "Offensive!")
@@ -169,7 +177,9 @@ describe "Admin activity" do
check "comment_#{comment3.id}_check" check "comment_#{comment3.id}_check"
end end
click_on "Hide comments" accept_confirm { click_button "Hide comments" }
expect(page).not_to have_content(comment1.body)
visit admin_activity_path visit admin_activity_path
@@ -178,15 +188,17 @@ describe "Admin activity" do
expect(page).to have_content(comment3.body) expect(page).to have_content(comment3.body)
end end
scenario "Shows admin restores" do scenario "Shows admin restores", :js do
comment = create(:comment, :hidden) comment = create(:comment, :hidden)
visit admin_hidden_comments_path visit admin_hidden_comments_path
within("#comment_#{comment.id}") do within("#comment_#{comment.id}") do
click_on "Restore" accept_confirm { click_link "Restore" }
end end
expect(page).to have_content "There are no hidden comments"
visit admin_activity_path visit admin_activity_path
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do
@@ -198,13 +210,13 @@ describe "Admin activity" do
end end
context "User" do context "User" do
scenario "Shows moderation activity on users" do scenario "Shows moderation activity on users", :js do
proposal = create(:proposal) proposal = create(:proposal)
visit proposal_path(proposal) visit proposal_path(proposal)
within("#proposal_#{proposal.id}") do within("#proposal_#{proposal.id}") do
click_link "Hide author" accept_confirm { click_link "Hide author" }
expect(page).to have_current_path(debates_path) expect(page).to have_current_path(debates_path)
end end
@@ -238,7 +250,7 @@ describe "Admin activity" do
end end
end end
scenario "Shows moderation activity from proposals moderation screen" do scenario "Shows moderation activity from proposals moderation screen", :js do
proposal1 = create(:proposal) proposal1 = create(:proposal)
proposal2 = create(:proposal) proposal2 = create(:proposal)
proposal3 = create(:proposal) proposal3 = create(:proposal)
@@ -253,7 +265,9 @@ describe "Admin activity" do
check "proposal_#{proposal3.id}_check" check "proposal_#{proposal3.id}_check"
end end
click_on "Block authors" accept_confirm { click_button "Block authors" }
expect(page).not_to have_content(proposal1.author.username)
visit admin_activity_path visit admin_activity_path
@@ -264,7 +278,7 @@ describe "Admin activity" do
expect(page).not_to have_content(proposal2.author.username) expect(page).not_to have_content(proposal2.author.username)
end end
scenario "Shows moderation activity from debates moderation screen" do scenario "Shows moderation activity from debates moderation screen", :js do
debate1 = create(:debate) debate1 = create(:debate)
debate2 = create(:debate) debate2 = create(:debate)
debate3 = create(:debate) debate3 = create(:debate)
@@ -279,7 +293,9 @@ describe "Admin activity" do
check "debate_#{debate3.id}_check" check "debate_#{debate3.id}_check"
end end
click_on "Block authors" accept_confirm { click_button "Block authors" }
expect(page).not_to have_content(debate1.author.username)
visit admin_activity_path visit admin_activity_path
@@ -290,7 +306,7 @@ describe "Admin activity" do
expect(page).not_to have_content(debate2.author.username) expect(page).not_to have_content(debate2.author.username)
end 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") comment1 = create(:comment, body: "SPAM")
comment2 = create(:comment) comment2 = create(:comment)
comment3 = create(:comment, body: "Offensive!") comment3 = create(:comment, body: "Offensive!")
@@ -305,7 +321,9 @@ describe "Admin activity" do
check "comment_#{comment3.id}_check" check "comment_#{comment3.id}_check"
end end
click_on "Block authors" accept_confirm { click_button "Block authors" }
expect(page).not_to have_content comment1.author.username
visit admin_activity_path visit admin_activity_path
@@ -316,15 +334,17 @@ describe "Admin activity" do
expect(page).not_to have_content(comment2.author.username) expect(page).not_to have_content(comment2.author.username)
end end
scenario "Shows admin restores" do scenario "Shows admin restores", :js do
user = create(:user, :hidden) user = create(:user, :hidden)
visit admin_hidden_users_path visit admin_hidden_users_path
within("#user_#{user.id}") do within("#user_#{user.id}") do
click_on "Restore" accept_confirm { click_link "Restore" }
end end
expect(page).to have_content "There are no hidden users"
visit admin_activity_path visit admin_activity_path
within("#activity_#{Activity.last.id}") do within("#activity_#{Activity.last.id}") do

View File

@@ -113,12 +113,12 @@ describe "Admin Notifications", :admin do
end end
context "Destroy" do context "Destroy" do
scenario "A draft notification can be destroyed" do scenario "A draft notification can be destroyed", :js do
notification = create(:admin_notification) notification = create(:admin_notification)
visit admin_admin_notifications_path visit admin_admin_notifications_path
within("#admin_notification_#{notification.id}") do within("#admin_notification_#{notification.id}") do
click_link "Delete" accept_confirm { click_link "Delete" }
end end
expect(page).to have_content "Notification deleted successfully" expect(page).to have_content "Notification deleted successfully"

View File

@@ -29,9 +29,9 @@ describe "Admin administrators" do
end end
end end
scenario "Delete Administrator" do scenario "Delete Administrator", :js do
within "#administrator_#{user_administrator.id}" do within "#administrator_#{user_administrator.id}" do
click_on "Delete" accept_confirm { click_link "Delete" }
end end
within("#administrators") do within("#administrators") do
@@ -39,9 +39,9 @@ describe "Admin administrators" do
end end
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 within "#administrator_#{admin.id}" do
click_on "Delete" accept_confirm { click_link "Delete" }
end end
within("#error") do within("#error") do
@@ -101,11 +101,11 @@ describe "Admin administrators" do
expect(page).not_to have_content(administrator1.email) expect(page).not_to have_content(administrator1.email)
end end
scenario "Delete after searching" do scenario "Delete after searching", :js do
fill_in "Search user by name or email", with: administrator2.email fill_in "Search user by name or email", with: administrator2.email
click_button "Search" click_button "Search"
click_link "Delete" accept_confirm { click_link "Delete" }
expect(page).to have_content(administrator1.email) expect(page).to have_content(administrator1.email)
expect(page).not_to have_content(administrator2.email) expect(page).not_to have_content(administrator2.email)

View File

@@ -167,7 +167,7 @@ describe "Admin banners magement", :admin do
expect(page).not_to have_content "Wrong text" expect(page).not_to have_content "Wrong text"
end end
scenario "Delete a banner" do scenario "Delete a banner", :js do
create(:banner, title: "Ugly banner", create(:banner, title: "Ugly banner",
description: "Bad text", description: "Bad text",
target_url: "http://www.url.com", target_url: "http://www.url.com",
@@ -176,15 +176,11 @@ describe "Admin banners magement", :admin do
background_color: "#FF0000", background_color: "#FF0000",
font_color: "#FFFFFF") font_color: "#FFFFFF")
visit admin_root_path visit admin_banners_path
within("#side_menu") do
click_link "Manage banners"
end
expect(page).to have_content "Ugly banner" expect(page).to have_content "Ugly banner"
click_link "Delete banner" accept_confirm { click_link "Delete banner" }
visit admin_root_path visit admin_root_path
expect(page).not_to have_content "Ugly banner" expect(page).not_to have_content "Ugly banner"

View File

@@ -55,22 +55,22 @@ describe "Admin budget groups", :admin do
end end
end end
scenario "Delete a group without headings" do scenario "Delete a group without headings", :js do
group = create(:budget_group, budget: budget) group = create(:budget_group, budget: budget)
visit admin_budget_groups_path(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).to have_content "Group deleted successfully"
expect(page).not_to have_selector "#budget_group_#{group.id}" expect(page).not_to have_selector "#budget_group_#{group.id}"
end 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) group = create(:budget_group, budget: budget)
create(:budget_heading, group: group) create(:budget_heading, group: group)
visit admin_budget_groups_path(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 "You cannot delete a Group that has associated headings" expect(page).to have_content "You cannot delete a Group that has associated headings"
expect(page).to have_selector "#budget_group_#{group.id}" expect(page).to have_selector "#budget_group_#{group.id}"

View File

@@ -60,22 +60,22 @@ describe "Admin budget headings", :admin do
end end
end end
scenario "Delete a heading without investments" do scenario "Delete a heading without investments", :js do
heading = create(:budget_heading, group: group) heading = create(:budget_heading, group: group)
visit admin_budget_group_headings_path(budget, 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).to have_content "Heading deleted successfully"
expect(page).not_to have_selector "#budget_heading_#{heading.id}" expect(page).not_to have_selector "#budget_heading_#{heading.id}"
end 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") heading = create(:budget_heading, group: group, name: "Atlantis")
create(:budget_investment, heading: heading) create(:budget_investment, heading: heading)
visit admin_budget_group_headings_path(budget, group) 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 "You cannot delete a Heading that has associated investments"
expect(page).to have_content "Atlantis" expect(page).to have_content "Atlantis"

View File

@@ -98,12 +98,12 @@ describe "Admin newsletter emails", :admin do
expect(page).to have_content "This is a body" expect(page).to have_content "This is a body"
end end
scenario "Destroy" do scenario "Destroy", :js do
newsletter = create(:newsletter) newsletter = create(:newsletter)
visit admin_newsletters_path visit admin_newsletters_path
within("#newsletter_#{newsletter.id}") do within("#newsletter_#{newsletter.id}") do
click_link "Delete" accept_confirm { click_link "Delete" }
end end
expect(page).to have_content "Newsletter deleted successfully" expect(page).to have_content "Newsletter deleted successfully"

View File

@@ -14,7 +14,7 @@ describe "Admin feature flags", :admin do
end end
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") setting = Setting.find_by(key: "process.budgets")
budget = create(:budget) budget = create(:budget)
@@ -24,10 +24,11 @@ describe "Admin feature flags", :admin do
within("#edit_setting_#{setting.id}") do within("#edit_setting_#{setting.id}") do
expect(page).to have_button "Disable" expect(page).to have_button "Disable"
expect(page).not_to have_button "Enable" expect(page).not_to have_button "Enable"
click_button "Disable"
accept_confirm { click_button "Disable" }
end end
visit admin_root_path expect(page).to have_content "Value updated"
within("#side_menu") do within("#side_menu") do
expect(page).not_to have_link "Participatory budgets" 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" expect(page).to have_content "Internal server error"
end end
scenario "Enable a disabled participatory process" do scenario "Enable a disabled participatory process", :js do
Setting["process.budgets"] = nil Setting["process.budgets"] = nil
setting = Setting.find_by(key: "process.budgets") setting = Setting.find_by(key: "process.budgets")
@@ -59,25 +60,28 @@ describe "Admin feature flags", :admin do
within("#edit_setting_#{setting.id}") do within("#edit_setting_#{setting.id}") do
expect(page).to have_button "Enable" expect(page).to have_button "Enable"
expect(page).not_to have_button "Disable" expect(page).not_to have_button "Disable"
click_button "Enable"
accept_confirm { click_button "Enable" }
end end
visit admin_root_path expect(page).to have_content "Value updated"
within("#side_menu") do within("#side_menu") do
expect(page).to have_link "Participatory budgets" expect(page).to have_link "Participatory budgets"
end end
end end
scenario "Disable a feature" do scenario "Disable a feature", :js do
setting = Setting.find_by(key: "feature.twitter_login") setting = Setting.find_by(key: "feature.twitter_login")
visit admin_settings_path visit admin_settings_path
click_link "Features"
within("#edit_setting_#{setting.id}") do within("#edit_setting_#{setting.id}") do
expect(page).to have_button "Disable" expect(page).to have_button "Disable"
expect(page).not_to have_button "Enable" expect(page).not_to have_button "Enable"
click_button "Disable"
accept_confirm { click_button "Disable" }
end end
expect(page).to have_content "Value updated" expect(page).to have_content "Value updated"
@@ -88,15 +92,17 @@ describe "Admin feature flags", :admin do
end end
end end
scenario "Enable a disabled feature" do scenario "Enable a disabled feature", :js do
setting = Setting.find_by(key: "feature.map") setting = Setting.find_by(key: "feature.map")
visit admin_settings_path visit admin_settings_path
click_link "Features"
within("#edit_setting_#{setting.id}") do within("#edit_setting_#{setting.id}") do
expect(page).to have_button "Enable" expect(page).to have_button "Enable"
expect(page).not_to have_button "Disable" expect(page).not_to have_button "Disable"
click_button "Enable"
accept_confirm { click_button "Enable" }
end end
expect(page).to have_content "Value updated" expect(page).to have_content "Value updated"

View File

@@ -66,25 +66,25 @@ describe "Admin geozones", :admin do
end end
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!") geozone = create(:geozone, name: "Delete me!")
visit admin_geozones_path 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).to have_content "Geozone successfully deleted"
expect(page).not_to have_content("Delete me!") expect(page).not_to have_content("Delete me!")
expect(Geozone.where(id: geozone.id)).to be_empty expect(Geozone.where(id: geozone.id)).to be_empty
end end
scenario "Delete geozone with associated element" do scenario "Delete geozone with associated element", :js do
geozone = create(:geozone, name: "Delete me!") geozone = create(:geozone, name: "Delete me!")
create(:proposal, geozone: geozone) create(:proposal, geozone: geozone)
visit admin_geozones_path 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" expect(page).to have_content "This geozone can't be deleted since there are elements attached to it"

View File

@@ -13,12 +13,12 @@ describe "Admin hidden budget investments", :admin do
expect(page).to have_content(investment.description) expect(page).to have_content(investment.description)
end end
scenario "Restore" do scenario "Restore", :js do
investment = create(:budget_investment, :hidden, heading: heading) investment = create(:budget_investment, :hidden, heading: heading)
visit admin_hidden_budget_investments_path visit admin_hidden_budget_investments_path
click_link "Restore" accept_confirm { click_link "Restore" }
expect(page).not_to have_content(investment.title) 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") expect(page).to have_content("Confirmed investment")
end 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) allow(Budget::Investment).to receive(:default_per_page).and_return(2)
4.times { create(:budget_investment, :hidden, :with_confirmed_hide, heading: heading) } 4.times { create(:budget_investment, :hidden, :with_confirmed_hide, heading: heading) }
visit admin_hidden_budget_investments_path(filter: "with_confirmed_hide", page: 2) 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(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/) expect(page).to have_current_path(/page=2/)

View File

@@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
describe "Admin hidden comments", :admin do 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") comment = create(:comment, :hidden, body: "SPAM from SPAMMER")
proposal = create(:proposal, author: comment.author) proposal = create(:proposal, author: comment.author)
create(:comment, commentable: proposal, user: comment.author, body: "Good Proposal!") 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!") expect(page).not_to have_content("Good Proposal!")
visit proposal_path(proposal) visit proposal_path(proposal)
within("#proposal_#{proposal.id}") do within("#proposal_#{proposal.id}") do
click_link "Hide author" accept_confirm { click_link "Hide author" }
end end
expect(page).to have_current_path debates_path
visit admin_hidden_comments_path visit admin_hidden_comments_path
expect(page).not_to have_content("SPAM from SPAMMER") expect(page).not_to have_content("SPAM from SPAMMER")
expect(page).not_to have_content("Good Proposal!") expect(page).not_to have_content("Good Proposal!")
end end
@@ -59,11 +63,11 @@ describe "Admin hidden comments", :admin do
expect(page).not_to have_link("This is SPAM comment on proposal") expect(page).not_to have_link("This is SPAM comment on proposal")
end end
scenario "Restore" do scenario "Restore", :js do
comment = create(:comment, :hidden, body: "Not really SPAM") comment = create(:comment, :hidden, body: "Not really SPAM")
visit admin_hidden_comments_path visit admin_hidden_comments_path
click_link "Restore" accept_confirm { click_link "Restore" }
expect(page).not_to have_content(comment.body) 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") expect(page).to have_content("Confirmed comment")
end 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) allow(Comment).to receive(:default_per_page).and_return(2)
4.times { create(:comment, :hidden, :with_confirmed_hide) } 4.times { create(:comment, :hidden, :with_confirmed_hide) }
visit admin_hidden_comments_path(filter: "with_confirmed_hide", page: 2) 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(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/) expect(page).to have_current_path(/page=2/)

View File

@@ -1,11 +1,11 @@
require "rails_helper" require "rails_helper"
describe "Admin hidden debates", :admin do describe "Admin hidden debates", :admin, :js do
scenario "Restore" do scenario "Restore" do
debate = create(:debate, :hidden) debate = create(:debate, :hidden)
visit admin_hidden_debates_path visit admin_hidden_debates_path
click_link "Restore" accept_confirm { click_link "Restore" }
expect(page).not_to have_content(debate.title) 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") expect(page).to have_content("Confirmed debate")
end 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) allow(Debate).to receive(:default_per_page).and_return(2)
4.times { create(:debate, :hidden, :with_confirmed_hide) } 4.times { create(:debate, :hidden, :with_confirmed_hide) }
visit admin_hidden_debates_path(filter: "with_confirmed_hide", page: 2) 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(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/) expect(page).to have_current_path(/page=2/)

View File

@@ -11,11 +11,11 @@ describe "Admin hidden proposals", :admin do
expect(page).to have_content(proposal.video_url) expect(page).to have_content(proposal.video_url)
end end
scenario "Restore" do scenario "Restore", :js do
proposal = create(:proposal, :hidden) proposal = create(:proposal, :hidden)
visit admin_hidden_proposals_path visit admin_hidden_proposals_path
click_link "Restore" accept_confirm { click_link "Restore" }
expect(page).not_to have_content(proposal.title) 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") expect(page).to have_content("Confirmed proposal")
end 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) allow(Proposal).to receive(:default_per_page).and_return(2)
4.times { create(:proposal, :hidden, :with_confirmed_hide) } 4.times { create(:proposal, :hidden, :with_confirmed_hide) }
visit admin_hidden_proposals_path(filter: "with_confirmed_hide", page: 2) 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(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/) expect(page).to have_current_path(/page=2/)

View File

@@ -17,11 +17,11 @@ describe "Admin hidden users", :admin do
expect(page).to have_content(comment2.body) expect(page).to have_content(comment2.body)
end end
scenario "Restore" do scenario "Restore", :js do
user = create(:user, :hidden) user = create(:user, :hidden)
visit admin_hidden_users_path visit admin_hidden_users_path
click_link "Restore" accept_confirm { click_link "Restore" }
expect(page).not_to have_content(user.username) 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") expect(page).to have_content("Confirmed user")
end 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) allow(User).to receive(:default_per_page).and_return(2)
4.times { create(:user, :hidden, :with_confirmed_hide) } 4.times { create(:user, :hidden, :with_confirmed_hide) }
visit admin_hidden_users_path(filter: "with_confirmed_hide", page: 2) 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(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/) expect(page).to have_current_path(/page=2/)

View File

@@ -134,11 +134,12 @@ describe "Admin local census records", :admin do
let!(:local_census_record) { create(:local_census_record) } let!(:local_census_record) { create(:local_census_record) }
let!(:deleted_document_number) { local_census_record.document_number } 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 visit admin_local_census_records_path
expect(page).to have_content deleted_document_number 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).to have_content "Local census record removed successfully!"
expect(page).not_to have_content deleted_document_number expect(page).not_to have_content deleted_document_number

View File

@@ -25,8 +25,8 @@ describe "Admin managers", :admin do
end end
end end
scenario "Delete Manager" do scenario "Delete Manager", :js do
click_link "Delete" accept_confirm { click_link "Delete" }
within("#managers") do within("#managers") do
expect(page).not_to have_content manager.name 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) expect(page).not_to have_content(manager1.email)
end end
scenario "Delete after searching" do scenario "Delete after searching", :js do
fill_in "Search user by name or email", with: manager2.email fill_in "Search user by name or email", with: manager2.email
click_button "Search" click_button "Search"
click_link "Delete" accept_confirm { click_link "Delete" }
expect(page).to have_content(manager1.email) expect(page).to have_content(manager1.email)
expect(page).not_to have_content(manager2.email) expect(page).not_to have_content(manager2.email)

View File

@@ -72,13 +72,13 @@ describe "Admin milestone statuses", :admin do
end end
context "Delete" do context "Delete" do
scenario "Hides status" do scenario "Hides status", :js do
status = create(:milestone_status) status = create(:milestone_status)
visit admin_milestone_statuses_path visit admin_milestone_statuses_path
within("#milestone_status_#{status.id}") do within("#milestone_status_#{status.id}") do
click_link "Delete" accept_confirm { click_link "Delete" }
end end
expect(page).not_to have_content status.name expect(page).not_to have_content status.name

View File

@@ -25,8 +25,8 @@ describe "Admin moderators", :admin do
end end
end end
scenario "Delete Moderator" do scenario "Delete Moderator", :js do
click_link "Delete" accept_confirm { click_link "Delete" }
within("#moderators") do within("#moderators") do
expect(page).not_to have_content moderator.name 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) expect(page).not_to have_content(moderator1.email)
end end
scenario "Delete after searching" do scenario "Delete after searching", :js do
fill_in "Search user by name or email", with: moderator2.email fill_in "Search user by name or email", with: moderator2.email
click_button "Search" click_button "Search"
click_link "Delete" accept_confirm { click_link "Delete" }
expect(page).to have_content(moderator1.email) expect(page).to have_content(moderator1.email)
expect(page).not_to have_content(moderator2.email) expect(page).not_to have_content(moderator2.email)

View File

@@ -25,8 +25,8 @@ describe "Admin poll officers", :admin do
end end
end end
scenario "Delete" do scenario "Delete", :js do
click_link "Delete position" accept_confirm { click_link "Delete position" }
expect(page).not_to have_css "#officers" expect(page).not_to have_css "#officers"
end end

View File

@@ -134,7 +134,7 @@ describe "Admin poll questions", :admin do
expect(page).not_to have_content(old_title) expect(page).not_to have_content(old_title)
end end
scenario "Destroy" do scenario "Destroy", :js do
poll = create(:poll) poll = create(:poll)
question1 = create(:poll_question, poll: poll) question1 = create(:poll_question, poll: poll)
question2 = 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) visit admin_poll_path(poll)
within("#poll_question_#{question1.id}") do within("#poll_question_#{question1.id}") do
click_link "Delete" accept_confirm { click_link "Delete" }
end end
expect(page).not_to have_content(question1.title) expect(page).not_to have_content(question1.title)

View File

@@ -159,7 +159,7 @@ describe "Admin shifts", :admin do
expect(page).to have_content "A date must be selected" expect(page).to have_content "A date must be selected"
end end
scenario "Destroy" do scenario "Destroy", :js do
poll = create(:poll, :current) poll = create(:poll, :current)
booth = create(:poll_booth, polls: [poll]) booth = create(:poll_booth, polls: [poll])
officer = create(:poll_officer) officer = create(:poll_officer)
@@ -174,14 +174,14 @@ describe "Admin shifts", :admin do
expect(page).to have_css(".shift", count: 1) expect(page).to have_css(".shift", count: 1)
within("#shift_#{shift.id}") do within("#shift_#{shift.id}") do
click_link "Remove" accept_confirm { click_link "Remove" }
end end
expect(page).to have_content "Shift removed" expect(page).to have_content "Shift removed"
expect(page).to have_css(".shift", count: 0) expect(page).to have_css(".shift", count: 0)
end end
scenario "Try to destroy with associated recount" do scenario "Try to destroy with associated recount", :js do
assignment = create(:poll_booth_assignment) assignment = create(:poll_booth_assignment)
officer_assignment = create(:poll_officer_assignment, booth_assignment: assignment) officer_assignment = create(:poll_officer_assignment, booth_assignment: assignment)
create(:poll_recount, booth_assignment: assignment, officer_assignment: officer_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) expect(page).to have_css(".shift", count: 1)
within("#shift_#{shift.id}") do within("#shift_#{shift.id}") do
click_link "Remove" accept_confirm { click_link "Remove" }
end end
expect(page).not_to have_content "Shift removed" 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) expect(page).to have_css(".shift", count: 1)
end 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) assignment = create(:poll_booth_assignment)
officer_assignment = create(:poll_officer_assignment, booth_assignment: assignment) officer_assignment = create(:poll_officer_assignment, booth_assignment: assignment)
create(:poll_partial_result, create(:poll_partial_result,
@@ -225,7 +225,7 @@ describe "Admin shifts", :admin do
expect(page).to have_css(".shift", count: 1) expect(page).to have_css(".shift", count: 1)
within("#shift_#{shift.id}") do within("#shift_#{shift.id}") do
click_link "Remove" accept_confirm { click_link "Remove" }
end end
expect(page).not_to have_content "Shift removed" expect(page).not_to have_content "Shift removed"

View File

@@ -9,11 +9,11 @@ describe "Admin proposal notifications", :admin do
expect(page).to have_content(proposal_notification.body) expect(page).to have_content(proposal_notification.body)
end end
scenario "Restore" do scenario "Restore", :js do
proposal_notification = create(:proposal_notification, :hidden, created_at: Date.current - 5.days) proposal_notification = create(:proposal_notification, :hidden, created_at: Date.current - 5.days)
visit admin_hidden_proposal_notifications_path visit admin_hidden_proposal_notifications_path
click_link "Restore" accept_confirm { click_link "Restore" }
expect(page).not_to have_content(proposal_notification.title) 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") expect(page).to have_content("Confirmed notification")
end 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) allow(ProposalNotification).to receive(:default_per_page).and_return(2)
4.times { create(:proposal_notification, :hidden, :with_confirmed_hide) } 4.times { create(:proposal_notification, :hidden, :with_confirmed_hide) }
visit admin_hidden_proposal_notifications_path(filter: "with_confirmed_hide", page: 2) 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(/filter=with_confirmed_hide/)
expect(page).to have_current_path(/page=2/) expect(page).to have_current_path(/page=2/)

View File

@@ -81,14 +81,14 @@ describe "Admin custom content blocks", :admin do
end end
context "Delete" do context "Delete" do
scenario "From index page" do scenario "From index page", :js do
block = create(:site_customization_content_block) block = create(:site_customization_content_block)
visit admin_site_customization_content_blocks_path visit admin_site_customization_content_blocks_path
expect(page).to have_content("#{block.name} (#{block.locale})") expect(page).to have_content("#{block.name} (#{block.locale})")
expect(page).to have_content(block.body) 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.name} (#{block.locale})")
expect(page).not_to have_content(block.body) expect(page).not_to have_content(block.body)

View File

@@ -29,7 +29,7 @@ describe "Admin tags", :admin do
expect(page).to have_content "important issues" expect(page).to have_content "important issues"
end end
scenario "Delete" do scenario "Delete", :js do
tag2 = create(:tag, :category, name: "bad tag") tag2 = create(:tag, :category, name: "bad tag")
create(:debate, tag_list: "bad tag") create(:debate, tag_list: "bad tag")
@@ -39,15 +39,14 @@ describe "Admin tags", :admin do
expect(page).to have_content "bad tag" expect(page).to have_content "bad tag"
within("#tag_#{tag2.id}") do within("#tag_#{tag2.id}") do
click_link "Delete topic" accept_confirm { click_link "Delete topic" }
end end
visit admin_tags_path
expect(page).to have_content "Existence"
expect(page).not_to have_content "bad tag" expect(page).not_to have_content "bad tag"
expect(page).to have_content "Existence"
end end
scenario "Delete tag with hidden taggables" do scenario "Delete tag with hidden taggables", :js do
tag2 = create(:tag, :category, name: "bad tag") tag2 = create(:tag, :category, name: "bad tag")
debate = create(:debate, tag_list: "bad tag") debate = create(:debate, tag_list: "bad tag")
debate.hide debate.hide
@@ -58,12 +57,11 @@ describe "Admin tags", :admin do
expect(page).to have_content "bad tag" expect(page).to have_content "bad tag"
within("#tag_#{tag2.id}") do within("#tag_#{tag2.id}") do
click_link "Delete topic" accept_confirm { click_link "Delete topic" }
end end
visit admin_tags_path
expect(page).to have_content "Existence"
expect(page).not_to have_content "bad tag" expect(page).not_to have_content "bad tag"
expect(page).to have_content "Existence"
end end
context "Manage only tags of kind category" do context "Manage only tags of kind category" do

View File

@@ -63,11 +63,11 @@ describe "Valuator groups", :admin do
expect(page).to have_content "Health and Sports" expect(page).to have_content "Health and Sports"
end end
scenario "Delete" do scenario "Delete", :js do
create(:valuator_group) create(:valuator_group)
visit admin_valuator_groups_path 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 "Valuator group deleted successfully"
expect(page).to have_content "There are no valuator groups" expect(page).to have_content "There are no valuator groups"

View File

@@ -50,8 +50,8 @@ describe "Admin valuators", :admin do
expect(page).not_to have_content "Can edit dossier" expect(page).not_to have_content "Can edit dossier"
end end
scenario "Destroy" do scenario "Destroy", :js do
click_link "Delete" accept_confirm { click_link "Delete" }
within("#valuators") do within("#valuators") do
expect(page).not_to have_content(valuator.name) expect(page).not_to have_content(valuator.name)

View File

@@ -997,7 +997,7 @@ describe "Budget Investments" do
end end
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) user = create(:user, :level_two)
investment1 = create(:budget_investment, heading: heading, price: 10000, author: user) investment1 = create(:budget_investment, heading: heading, price: 10000, author: user)
@@ -1006,7 +1006,8 @@ describe "Budget Investments" do
within("#budget_investment_#{investment1.id}") do within("#budget_investment_#{investment1.id}") do
expect(page).to have_content(investment1.title) expect(page).to have_content(investment1.title)
click_link("Delete")
accept_confirm { click_link("Delete") }
end end
visit user_path(user, tab: :budget_investments) visit user_path(user, tab: :budget_investments)

View File

@@ -772,33 +772,31 @@ describe "Debates" do
end end
end end
scenario "Mark/Unmark a debate as featured", :admin do scenario "Mark/Unmark a debate as featured", :admin, :js do
debate = create(:debate) debate = create(:debate)
visit debates_path visit debates_path
within("#debates") do within("#debates") do
expect(page).not_to have_content "Featured" expect(page).not_to have_content "FEATURED"
end end
click_link debate.title click_link debate.title
accept_confirm { click_link "Featured" }
click_link "Featured"
visit debates_path
within("#debates") do within("#debates") do
expect(page).to have_content "Featured" expect(page).to have_content "FEATURED"
end end
within("#featured-debates") do within("#featured-debates") do
expect(page).to have_content debate.title expect(page).to have_content debate.title
click_link debate.title
end end
visit debate_path(debate) accept_confirm { click_link "Unmark featured" }
click_link "Unmark featured"
within("#debates") do within("#debates") do
expect(page).not_to have_content "Featured" expect(page).not_to have_content "FEATURED"
end end
end end

View File

@@ -365,7 +365,7 @@ describe "Emails" do
expect(email).to have_body_text(budget_path(budget)) expect(email).to have_body_text(budget_path(budget))
end end
scenario "Unfeasible investment" do scenario "Unfeasible investment", :js do
budget.update!(phase: "valuating") budget.update!(phase: "valuating")
valuator = create(:valuator) valuator = create(:valuator)
investment = create(:budget_investment, author: author, budget: budget, valuators: [valuator]) investment = create(:budget_investment, author: author, budget: budget, valuators: [valuator])
@@ -375,7 +375,7 @@ describe "Emails" do
within_fieldset("Feasibility") { choose "Unfeasible" } within_fieldset("Feasibility") { choose "Unfeasible" }
fill_in "Feasibility explanation", with: "This is not legal as stated in Article 34.9" 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" click_button "Save changes"
expect(page).to have_content "Dossier updated" expect(page).to have_content "Dossier updated"
@@ -478,6 +478,8 @@ describe "Emails" do
click_link "Send" 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_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_in_segment_2.email).count).to eq 1
expect(unread_emails_for(user_with_newsletter_not_in_segment.email).count).to eq 0 expect(unread_emails_for(user_with_newsletter_not_in_segment.email).count).to eq 0

View File

@@ -50,7 +50,7 @@ describe "Moderate budget investments" do
end end
describe "moderate in bulk" do 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 before do
visit moderation_budget_investments_path visit moderation_budget_investments_path
@@ -66,7 +66,8 @@ describe "Moderate budget investments" do
end end
scenario "Hide the investment" do 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}") expect(page).not_to have_css("investment_#{investment.id}")
investment.reload investment.reload
@@ -75,7 +76,8 @@ describe "Moderate budget investments" do
end end
scenario "Block the author" do scenario "Block the author" do
click_button "Block authors" accept_confirm { click_button "Block authors" }
expect(page).not_to have_css("investment_#{investment.id}") expect(page).not_to have_css("investment_#{investment.id}")
investment.reload investment.reload
@@ -84,7 +86,8 @@ describe "Moderate budget investments" do
end end
scenario "Ignore the investment" do 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}") expect(page).not_to have_css("investment_#{investment.id}")
investment.reload investment.reload
@@ -111,13 +114,13 @@ describe "Moderate budget investments" do
end end
end end
scenario "remembering page, filter and order" do scenario "remembering page, filter and order", :js do
stub_const("#{ModerateActions}::PER_PAGE", 2) stub_const("#{ModerateActions}::PER_PAGE", 2)
create_list(:budget_investment, 4, heading: heading, author: create(:user)) create_list(:budget_investment, 4, heading: heading, author: create(:user))
visit moderation_budget_investments_path(filter: "all", page: "2", order: "created_at") 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']") expect(page).to have_selector(".js-order-selector[data-order='created_at']")

View File

@@ -69,7 +69,7 @@ describe "Moderate comments" do
end end
describe "moderate in bulk" do 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) } let!(:comment) { create(:comment) }
before do before do
@@ -86,21 +86,24 @@ describe "Moderate comments" do
end end
scenario "Hide the comment" do 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(page).not_to have_css("comment_#{comment.id}")
expect(comment.reload).to be_hidden expect(comment.reload).to be_hidden
expect(comment.user).not_to be_hidden expect(comment.user).not_to be_hidden
end end
scenario "Block the user" do 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(page).not_to have_css("comment_#{comment.id}")
expect(comment.reload).to be_hidden expect(comment.reload).to be_hidden
expect(comment.user).to be_hidden expect(comment.user).to be_hidden
end end
scenario "Ignore the comment" do 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(page).not_to have_css("comment_#{comment.id}")
expect(comment.reload).to be_ignored_flag expect(comment.reload).to be_ignored_flag
expect(comment.reload).not_to be_hidden expect(comment.reload).not_to be_hidden
@@ -124,13 +127,13 @@ describe "Moderate comments" do
end end
end end
scenario "remembering page, filter and order" do scenario "remembering page, filter and order", :js do
stub_const("#{ModerateActions}::PER_PAGE", 2) stub_const("#{ModerateActions}::PER_PAGE", 2)
create_list(:comment, 4) create_list(:comment, 4)
visit moderation_comments_path(filter: "all", page: "2", order: "newest") 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']") expect(page).to have_selector(".js-order-selector[data-order='newest']")

View File

@@ -42,7 +42,7 @@ describe "Moderate debates" do
end end
describe "moderate in bulk" do 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) } let!(:debate) { create(:debate) }
before do before do
@@ -59,21 +59,24 @@ describe "Moderate debates" do
end end
scenario "Hide the debate" do 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(page).not_to have_css("debate_#{debate.id}")
expect(debate.reload).to be_hidden expect(debate.reload).to be_hidden
expect(debate.author).not_to be_hidden expect(debate.author).not_to be_hidden
end end
scenario "Block the author" do 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(page).not_to have_css("debate_#{debate.id}")
expect(debate.reload).to be_hidden expect(debate.reload).to be_hidden
expect(debate.author).to be_hidden expect(debate.author).to be_hidden
end end
scenario "Ignore the debate" do 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(page).not_to have_css("debate_#{debate.id}")
expect(debate.reload).to be_ignored_flag expect(debate.reload).to be_ignored_flag
expect(debate.reload).not_to be_hidden expect(debate.reload).not_to be_hidden
@@ -97,13 +100,13 @@ describe "Moderate debates" do
end end
end end
scenario "remembering page, filter and order" do scenario "remembering page, filter and order", :js do
stub_const("#{ModerateActions}::PER_PAGE", 2) stub_const("#{ModerateActions}::PER_PAGE", 2)
create_list(:debate, 4) create_list(:debate, 4)
visit moderation_debates_path(filter: "all", page: "2", order: "created_at") 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']") expect(page).to have_selector(".js-order-selector[data-order='created_at']")

View File

@@ -45,7 +45,7 @@ describe "Moderate proposal notifications" do
end end
describe "moderate in bulk" do 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) } let!(:proposal_notification) { create(:proposal_notification, created_at: Date.current - 4.days) }
before do before do
@@ -60,7 +60,8 @@ describe "Moderate proposal notifications" do
end end
scenario "Hide the proposal" do 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(page).not_to have_css("#proposal_notification_#{proposal_notification.id}")
expect(proposal_notification.reload).to be_hidden expect(proposal_notification.reload).to be_hidden
expect(proposal_notification.author).not_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 scenario "Block the author" do
author = create(:user) author = create(:user)
proposal_notification.update!(author: author) 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(page).not_to have_css("#proposal_notification_#{proposal_notification.id}")
expect(proposal_notification.reload).to be_hidden expect(proposal_notification.reload).to be_hidden
expect(author.reload).to be_hidden expect(author.reload).to be_hidden
@@ -100,13 +103,13 @@ describe "Moderate proposal notifications" do
end end
end end
scenario "remembering page, filter and order" do scenario "remembering page, filter and order", :js do
stub_const("#{ModerateActions}::PER_PAGE", 2) stub_const("#{ModerateActions}::PER_PAGE", 2)
create_list(:proposal, 4) create_list(:proposal, 4)
visit moderation_proposal_notifications_path(filter: "all", page: "2", order: "created_at") 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']") expect(page).to have_selector(".js-order-selector[data-order='created_at']")

View File

@@ -43,7 +43,7 @@ describe "Moderate proposals" do
describe "moderate in bulk" do describe "moderate in bulk" do
let!(:proposal) { create(:proposal) } 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 before do
visit moderation_proposals_path visit moderation_proposals_path
within(".menu.simple") do within(".menu.simple") do
@@ -58,21 +58,24 @@ describe "Moderate proposals" do
end end
scenario "Hide the proposal" do 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(page).not_to have_css("proposal_#{proposal.id}")
expect(proposal.reload).to be_hidden expect(proposal.reload).to be_hidden
expect(proposal.author).not_to be_hidden expect(proposal.author).not_to be_hidden
end end
scenario "Block the author" do 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(page).not_to have_css("proposal_#{proposal.id}")
expect(proposal.reload).to be_hidden expect(proposal.reload).to be_hidden
expect(proposal.author).to be_hidden expect(proposal.author).to be_hidden
end end
scenario "Ignore the proposal" do 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(page).not_to have_css("proposal_#{proposal.id}")
expect(proposal.reload).to be_ignored_flag expect(proposal.reload).to be_ignored_flag
expect(proposal.reload).not_to be_hidden expect(proposal.reload).not_to be_hidden
@@ -96,13 +99,13 @@ describe "Moderate proposals" do
end end
end end
scenario "remembering page, filter and order" do scenario "remembering page, filter and order", :js do
stub_const("#{ModerateActions}::PER_PAGE", 2) stub_const("#{ModerateActions}::PER_PAGE", 2)
create_list(:proposal, 4) create_list(:proposal, 4)
visit moderation_proposals_path(filter: "all", page: "2", order: "created_at") 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']") expect(page).to have_selector(".js-order-selector[data-order='created_at']")

View File

@@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
describe "Moderate users" do describe "Moderate users" do
scenario "Hide" do scenario "Hide", :js do
citizen = create(:user) citizen = create(:user)
moderator = create(:moderator) moderator = create(:moderator)
@@ -24,7 +24,7 @@ describe "Moderate users" do
visit debate_path(debate1) visit debate_path(debate1)
within("#debate_#{debate1.id}") do within("#debate_#{debate1.id}") do
click_link "Hide author" accept_confirm { click_link "Hide author" }
end end
expect(page).to have_current_path(debates_path) expect(page).to have_current_path(debates_path)

View File

@@ -379,15 +379,17 @@ describe "Valuation budget investments" do
end end
end end
scenario "Finish valuation" do scenario "Finish valuation", :js do
investment.update!(visible_to_valuators: true) investment.update!(visible_to_valuators: true)
visit valuation_budget_budget_investment_path(budget, investment) visit valuation_budget_budget_investment_path(budget, investment)
click_link "Edit dossier" click_link "Edit dossier"
find_field("budget_investment[valuation_finished]").click accept_confirm { find_field("budget_investment[valuation_finished]").click }
click_button "Save changes" click_button "Save changes"
expect(page).to have_content "Dossier updated"
visit valuation_budget_budget_investments_path(budget) visit valuation_budget_budget_investments_path(budget)
expect(page).not_to have_content investment.title expect(page).not_to have_content investment.title
click_link "Valuation finished" click_link "Valuation finished"