JavaScript is used by about 98% of web users, so by testing without it enabled, we're only testing that the application works for a very reduced number of users. We proceeded this way in the past because CONSUL started using Rails 4.2 and truncating the database between JavaScript tests with database cleaner, which made these tests terribly slow. When we upgraded to Rails 5.1 and introduced system tests, we started using database transactions in JavaScript tests, making these tests much faster. So now we can use JavaScript tests everywhere without critically slowing down our test suite.
93 lines
3.0 KiB
Ruby
93 lines
3.0 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Admin hidden proposals", :admin do
|
|
scenario "List shows all relevant info" do
|
|
proposal = create(:proposal, :hidden)
|
|
visit admin_hidden_proposals_path
|
|
|
|
expect(page).to have_content(proposal.title)
|
|
expect(page).to have_content(proposal.summary)
|
|
expect(page).to have_content(proposal.description)
|
|
|
|
find("td", text: proposal.summary).hover
|
|
|
|
expect(page).to have_content(proposal.video_url)
|
|
end
|
|
|
|
scenario "Restore" do
|
|
proposal = create(:proposal, :hidden)
|
|
visit admin_hidden_proposals_path
|
|
|
|
accept_confirm { click_link "Restore" }
|
|
|
|
expect(page).not_to have_content(proposal.title)
|
|
|
|
expect(proposal.reload).not_to be_hidden
|
|
expect(proposal).to be_ignored_flag
|
|
end
|
|
|
|
scenario "Confirm hide" do
|
|
proposal = create(:proposal, :hidden)
|
|
visit admin_hidden_proposals_path
|
|
|
|
click_link "Confirm moderation"
|
|
|
|
expect(page).not_to have_content(proposal.title)
|
|
click_link("Confirmed")
|
|
expect(page).to have_content(proposal.title)
|
|
|
|
expect(proposal.reload).to be_confirmed_hide
|
|
end
|
|
|
|
scenario "Current filter is properly highlighted" do
|
|
visit admin_hidden_proposals_path
|
|
expect(page).not_to have_link("Pending")
|
|
expect(page).to have_link("All")
|
|
expect(page).to have_link("Confirmed")
|
|
|
|
visit admin_hidden_proposals_path(filter: "Pending")
|
|
expect(page).not_to have_link("Pending")
|
|
expect(page).to have_link("All")
|
|
expect(page).to have_link("Confirmed")
|
|
|
|
visit admin_hidden_proposals_path(filter: "all")
|
|
expect(page).to have_link("Pending")
|
|
expect(page).not_to have_link("All")
|
|
expect(page).to have_link("Confirmed")
|
|
|
|
visit admin_hidden_proposals_path(filter: "with_confirmed_hide")
|
|
expect(page).to have_link("All")
|
|
expect(page).to have_link("Pending")
|
|
expect(page).not_to have_link("Confirmed")
|
|
end
|
|
|
|
scenario "Filtering proposals" do
|
|
create(:proposal, :hidden, title: "Unconfirmed proposal")
|
|
create(:proposal, :hidden, :with_confirmed_hide, title: "Confirmed proposal")
|
|
|
|
visit admin_hidden_proposals_path(filter: "pending")
|
|
expect(page).to have_content("Unconfirmed proposal")
|
|
expect(page).not_to have_content("Confirmed proposal")
|
|
|
|
visit admin_hidden_proposals_path(filter: "all")
|
|
expect(page).to have_content("Unconfirmed proposal")
|
|
expect(page).to have_content("Confirmed proposal")
|
|
|
|
visit admin_hidden_proposals_path(filter: "with_confirmed_hide")
|
|
expect(page).not_to have_content("Unconfirmed proposal")
|
|
expect(page).to have_content("Confirmed proposal")
|
|
end
|
|
|
|
scenario "Action links remember the pagination setting and the filter" 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)
|
|
|
|
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/)
|
|
end
|
|
end
|