There were many cases where we were clicking on a link or (most of the
time) a button and then calling the `visit` method. In the past, it
worked just fine because clicking on buttons usually results in non-AJAX
requests, meaning that the test waited for the request to finish before
continuing.
That's no longer the case, though. In the last few months/years (not
sure since when) we're getting sporadic failures because the test
doesn't wait for the request to finish before making another request
with the `visit` method. This sometimes results in flaky tests.
Some of these tests have recently failed in our CI. Here are a few
examples (note the numbers don't follow an order because these tests
failed in different jobs):
```
1) Admin edit translatable records Current locale translation does not
exist For ActivePoll Shows first available fallback
Failure/Error: expect(page).to have_content "Sondage en Français"
expected to find text "Sondage en Français" in "Language: \n
\nEnglish\nDeutsch\nEspañol\nFrançais\nNederlands\nPortuguês
brasileiro\n中文\n Go back to CONSUL DEMOCRACY\nCONSUL
DEMOCRACY\nADMINISTRATION\nMenu\nNotifications\nMy content\nMy
account\nSign out\nProposals\nDebates\nComments\nPolls\n
Collaborative Legislation\nParticipatory budgets\nVoting booths
\nSignature Sheets\nMessages to users\nSite content\nModerated
content\nProfiles\nStatistics\nSettings\nProposals dashboard\n×
\nPolls description updated successfully.\nList of polls\nPolls
description\nCreate poll\nThere are no polls."
2) Public area translatable records Existing records Update a
translation With valid data Changes the existing translation
Failure/Error: expect(page).to have_field "Debate title",
with: "Title in English"
expected to find field "Debate title" that is not disabled but
there were no matches
2) Admin collaborative legislation Update Edit milestones summary
Failure/Error: expect(page).to have_content "There is still a long
journey ahead of us"
expected to find text "There is still a long journey ahead of us"
in "Language: \n
\nEnglish\nDeutsch\nEspañol\nFrançais\nNederlands\nPortuguês
brasileiro\n中文\n Go back to CONSUL DEMOCRACY\nCONSUL
DEMOCRACY\nADMINISTRATION\nMenu\nNotifications\nMy content\nMy
account\nSign out\nProposals\nDebates\nComments\nPolls\n
Collaborative Legislation\nParticipatory budgets\nVoting booths
\nSignature Sheets\nMessages to users\nSite content\nModerated
content\nProfiles\nStatistics\nSettings\nProposals dashboard\n×
\nProcess updated successfully. Click to visit\nBack\nAn example
legislation process\nInformation\nHomepage\nDebate\nProposals\n
Drafting\nFollowing\n1 language in use\nCurrent language\n
English\nSummary\n Format\n ◢\n Milestone\nManage progress
bars\nDon't have defined milestones\nCreate new milestone".
(However, it was found 1 time including non-visible text.)
3) Admin collaborative legislation SDG related list create Collaborative
Legislation with sdg related list
Failure/Error:
within("tr", text: "Legislation process with SDG related content") do
expect(page).to have_css "td", exact_text: "17"
end
Capybara::ElementNotFound:
Unable to find css "tr"
4) Valuation budget investments Valuate Feasibility can be marked as
pending
Failure/Error: expect(find("#budget_investment_feasibility_undecided"))
.not_to be_checked
Capybara::ElementNotFound:
Unable to find css "#budget_investment_feasibility_undecided"
3) Custom information texts Show custom texts instead of default ones
Failure/Error:
within("#section_help") do
expect(page).to have_content "Custom help with debates"
expect(page).not_to have_content "Help with debates"
end
4) Admin budgets Update Deselect all selected staff
Failure/Error: expect(page).to have_link "Select administrators"
expected to find link "Select administrators" but there were no
matches
3) Admin polls SDG related list edit poll with sdg related list
Failure/Error:
within("tr", text: "Upcoming poll with SDG related content") do
expect(page).to have_css "td", exact_text: "17"
end
Capybara::ElementNotFound:
Unable to find css "tr"
4) Admin polls SDG related list create poll with sdg related list
Failure/Error:
within("tr", text: "Upcoming poll with SDG related content") do
expect(page).to have_css "td", exact_text: "17"
end
Capybara::ElementNotFound:
Unable to find css "tr"
5) Admin custom images Image is replaced on admin newsletters
Failure/Error:
within(".newsletter-body-content") do
expect(page).to have_css("img[src*='logo_email_custom.png']")
end
Capybara::ElementNotFound:
Unable to find css ".newsletter-body-content"
6) Admin custom images Image is replaced on front views
Failure/Error:
within("#map") do
expect(page).to
have_css("img[src*='custom_map.jpg'][alt='Districts list']")
end
Capybara::ElementNotFound:
Unable to find css "#map"
```
294 lines
8.1 KiB
Ruby
294 lines
8.1 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Polls" do
|
|
let!(:proposal) { create(:proposal, :draft) }
|
|
|
|
before { login_as(proposal.author) }
|
|
|
|
scenario "Has a link to polls feature" do
|
|
visit proposal_dashboard_path(proposal)
|
|
|
|
expect(page).to have_link("Polls")
|
|
end
|
|
|
|
scenario "Create a poll" do
|
|
visit proposal_dashboard_path(proposal)
|
|
click_link "Polls"
|
|
click_link "Create poll"
|
|
|
|
start_date = 1.week.from_now
|
|
end_date = 2.weeks.from_now
|
|
|
|
fill_in "poll_name", with: "Proposal poll"
|
|
fill_in "poll_starts_at", with: start_date.strftime("%d/%m/%Y")
|
|
fill_in "poll_ends_at", with: end_date.strftime("%d/%m/%Y")
|
|
fill_in "poll_description", with: "Proposal's poll description. This poll..."
|
|
|
|
expect(page).not_to have_css("#poll_results_enabled")
|
|
expect(page).not_to have_css("#poll_stats_enabled")
|
|
|
|
click_link "Add question"
|
|
|
|
fill_in "Question", with: "First question"
|
|
|
|
click_link "Add answer"
|
|
|
|
fill_in "Answer", with: "First answer"
|
|
|
|
click_button "Create poll"
|
|
expect(page).to have_content "Poll created successfully"
|
|
expect(page).to have_content "Proposal poll"
|
|
expect(page).to have_content I18n.l(start_date.to_date)
|
|
end
|
|
|
|
describe "Datepicker" do
|
|
scenario "displays the expected format when changing the date field" do
|
|
visit new_proposal_dashboard_poll_path(proposal)
|
|
|
|
fill_in "Start Date", with: "20/02/2002"
|
|
find_field("Start Date").click
|
|
within(".ui-datepicker") { click_link "22" }
|
|
|
|
expect(page).to have_field "Start Date", with: "22/02/2002"
|
|
end
|
|
|
|
scenario "is closed after using the browser back button" do
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
click_link "Create poll"
|
|
find_field("Start Date").click
|
|
|
|
expect(page).to have_css "#ui-datepicker-div"
|
|
|
|
go_back
|
|
|
|
expect(page).to have_link "Create poll"
|
|
expect(page).not_to have_css "#ui-datepicker-div"
|
|
end
|
|
|
|
scenario "works after using the browser back button" do
|
|
visit new_proposal_dashboard_poll_path(proposal)
|
|
click_link "Polls"
|
|
|
|
expect(page).to have_link "Create poll"
|
|
|
|
go_back
|
|
find_field("Start Date").click
|
|
|
|
expect(page).to have_css "#ui-datepicker-div"
|
|
end
|
|
end
|
|
|
|
scenario "Create a poll redirects back to form when invalid data" do
|
|
visit proposal_dashboard_path(proposal)
|
|
click_link "Polls"
|
|
click_link "Create poll"
|
|
|
|
click_button "Create poll"
|
|
|
|
expect(page).to have_content("New poll")
|
|
end
|
|
|
|
scenario "Edit poll is allowed for upcoming polls" do
|
|
poll = create(:poll, related: proposal, starts_at: 1.week.from_now)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
within "div#poll_#{poll.id}" do
|
|
expect(page).to have_content("Edit survey")
|
|
|
|
click_link "Edit survey"
|
|
end
|
|
|
|
click_button "Update poll"
|
|
|
|
expect(page).to have_content "Poll updated successfully"
|
|
end
|
|
|
|
scenario "Edit poll redirects back when invalid data" do
|
|
poll = create(:poll, related: proposal, starts_at: 1.week.from_now)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
within "div#poll_#{poll.id}" do
|
|
expect(page).to have_content("Edit survey")
|
|
|
|
click_link "Edit survey"
|
|
end
|
|
|
|
fill_in "poll_name", with: ""
|
|
|
|
click_button "Update poll"
|
|
|
|
expect(page).to have_content("Edit poll")
|
|
end
|
|
|
|
scenario "Edit poll is not allowed for current polls" do
|
|
poll = create(:poll, related: proposal)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
within "div#poll_#{poll.id}" do
|
|
expect(page).not_to have_content("Edit survey")
|
|
end
|
|
end
|
|
|
|
scenario "Edit poll is not allowed for expired polls" do
|
|
poll = create(:poll, :expired, related: proposal)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
within "div#poll_#{poll.id}" do
|
|
expect(page).not_to have_content("Edit survey")
|
|
end
|
|
end
|
|
|
|
scenario "Edit poll should allow to remove questions" do
|
|
poll = create(:poll, related: proposal, starts_at: 1.week.from_now)
|
|
create(:poll_question, poll: poll)
|
|
create(:poll_question, poll: poll)
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
within "div#poll_#{poll.id}" do
|
|
click_link "Edit survey"
|
|
end
|
|
|
|
within ".js-questions" do
|
|
expect(page).to have_css ".nested-fields", count: 2
|
|
within first(".nested-fields") do
|
|
click_link class: "delete"
|
|
end
|
|
expect(page).to have_css ".nested-fields", count: 1
|
|
end
|
|
|
|
click_button "Update poll"
|
|
|
|
expect(page).to have_content "Poll updated successfully"
|
|
|
|
visit edit_proposal_dashboard_poll_path(proposal, poll)
|
|
|
|
expect(page).to have_css ".nested-fields", count: 1
|
|
end
|
|
|
|
scenario "Edit poll allows users to remove options" do
|
|
poll = create(:poll, related: proposal, starts_at: 1.week.from_now)
|
|
create(:poll_question, :yes_no, poll: poll)
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
within "div#poll_#{poll.id}" do
|
|
click_link "Edit survey"
|
|
end
|
|
|
|
within ".js-questions .js-options" do
|
|
expect(page).to have_css ".nested-fields", count: 2
|
|
within first(".nested-fields") do
|
|
click_link class: "delete"
|
|
end
|
|
expect(page).to have_css ".nested-fields", count: 1
|
|
end
|
|
|
|
click_button "Update poll"
|
|
|
|
expect(page).to have_content "Poll updated successfully"
|
|
|
|
visit edit_proposal_dashboard_poll_path(proposal, poll)
|
|
|
|
within ".js-questions .js-options" do
|
|
expect(page).to have_css ".nested-fields", count: 1
|
|
end
|
|
end
|
|
|
|
scenario "Can destroy poll without responses" do
|
|
poll = create(:poll, related: proposal)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
within("#poll_#{poll.id}") do
|
|
accept_confirm { click_button "Delete survey" }
|
|
end
|
|
|
|
expect(page).to have_content("Survey deleted successfully")
|
|
expect(page).not_to have_content(poll.name)
|
|
end
|
|
|
|
scenario "Can't destroy poll with responses" do
|
|
poll = create(:poll, related: proposal)
|
|
create(:poll_question, poll: poll)
|
|
create(:poll_voter, poll: poll)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
within("#poll_#{poll.id}") do
|
|
accept_confirm { click_button "Delete survey" }
|
|
end
|
|
|
|
expect(page).to have_content("You cannot destroy a survey that has responses")
|
|
expect(page).to have_content(poll.name)
|
|
end
|
|
|
|
scenario "View results not available for upcoming polls" do
|
|
poll = create(:poll, related: proposal, starts_at: 1.week.from_now)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
within "div#poll_#{poll.id}" do
|
|
expect(page).not_to have_content("View results")
|
|
end
|
|
end
|
|
|
|
scenario "View results available for current polls" do
|
|
poll = create(:poll, related: proposal)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
within "div#poll_#{poll.id}" do
|
|
expect(page).to have_content("View results")
|
|
end
|
|
end
|
|
|
|
scenario "View results available for expired polls" do
|
|
poll = create(:poll, :expired, related: proposal)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
within "div#poll_#{poll.id}" do
|
|
expect(page).to have_content("View results")
|
|
end
|
|
end
|
|
|
|
scenario "View results redirects to results in public zone" do
|
|
poll = create(:poll, :expired, related: proposal)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
click_link "View results"
|
|
|
|
expect(page).to have_current_path(results_proposal_poll_path(proposal, poll))
|
|
end
|
|
|
|
scenario "Enable and disable results" do
|
|
create(:poll, related: proposal)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
check "Show results"
|
|
|
|
expect(find_field("Show results")).to be_checked
|
|
|
|
uncheck "Show results"
|
|
|
|
expect(find_field("Show results")).not_to be_checked
|
|
end
|
|
|
|
scenario "Poll card" do
|
|
poll = create(:poll, :expired, related: proposal)
|
|
|
|
visit proposal_dashboard_polls_path(proposal)
|
|
|
|
within "div#poll_#{poll.id}" do
|
|
expect(page).to have_content(I18n.l(poll.starts_at.to_date))
|
|
expect(page).to have_content(I18n.l(poll.ends_at.to_date))
|
|
expect(page).to have_link(poll.title)
|
|
expect(page).to have_link(poll.title, href: proposal_poll_path(proposal, poll))
|
|
expect(page).to have_link("View results", href: results_proposal_poll_path(proposal, poll))
|
|
end
|
|
end
|
|
end
|