Skip to content

Commit

Permalink
Use JavaScript in tests opening modal dialogs
Browse files Browse the repository at this point in the history
This way we reproduce the user experience in the tests, and we can make
sure modal dialogs open when we expect it.
  • Loading branch information
javierm committed Apr 7, 2021
1 parent fbc7898 commit b2bc4d1
Show file tree
Hide file tree
Showing 38 changed files with 221 additions and 178 deletions.
4 changes: 2 additions & 2 deletions spec/shared/system/admin_progressable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@
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%"
Expand Down
12 changes: 6 additions & 6 deletions spec/shared/system/documentable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,37 @@
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
Expand Down
64 changes: 42 additions & 22 deletions spec/system/admin/activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
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)
Expand All @@ -42,7 +42,9 @@
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

Expand All @@ -51,15 +53,17 @@
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
Expand Down Expand Up @@ -90,7 +94,7 @@
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)
Expand All @@ -105,7 +109,9 @@
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

Expand All @@ -114,15 +120,17 @@
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
Expand Down Expand Up @@ -154,7 +162,7 @@
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!")
Expand All @@ -169,7 +177,9 @@
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

Expand All @@ -178,15 +188,17 @@
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
Expand All @@ -198,13 +210,13 @@
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
Expand Down Expand Up @@ -238,7 +250,7 @@
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)
Expand All @@ -253,7 +265,9 @@
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

Expand All @@ -264,7 +278,7 @@
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)
Expand All @@ -279,7 +293,9 @@
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

Expand All @@ -290,7 +306,7 @@
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!")
Expand All @@ -305,7 +321,9 @@
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

Expand All @@ -316,15 +334,17 @@
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
Expand Down
4 changes: 2 additions & 2 deletions spec/system/admin/admin_notifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@
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"
Expand Down
12 changes: 6 additions & 6 deletions spec/system/admin/administrators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
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
expect(page).not_to have_content user_administrator.name
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
Expand Down Expand Up @@ -101,11 +101,11 @@
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)
Expand Down
10 changes: 3 additions & 7 deletions spec/system/admin/banners_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
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:https://www.url.com",
Expand All @@ -176,15 +176,11 @@
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"
Expand Down
8 changes: 4 additions & 4 deletions spec/system/admin/budget_groups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@
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}"
Expand Down
Loading

0 comments on commit b2bc4d1

Please sign in to comment.