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

@@ -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/)