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"
```
577 lines
18 KiB
Ruby
577 lines
18 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Admin edit translatable records", :admin do
|
|
before do
|
|
translatable.main_link_url = "https://consuldemocracy.org" if translatable.is_a?(Budget::Phase)
|
|
translatable.update!(attributes)
|
|
end
|
|
|
|
let(:fields) { translatable.translated_attribute_names }
|
|
|
|
let(:attributes) do
|
|
fields.product(%i[en es]).to_h do |field, locale|
|
|
[:"#{field}_#{locale}", text_for(field, locale)]
|
|
end
|
|
end
|
|
|
|
context "Add a translation" do
|
|
context "Input fields" do
|
|
let(:translatable) { create(:budget_heading) }
|
|
let(:path) { admin_polymorphic_path(translatable, action: :edit) }
|
|
|
|
scenario "Maintains existing translations" do
|
|
visit path
|
|
|
|
select "Français", from: "Add language"
|
|
fill_in "Heading name", with: "Nom en Français"
|
|
click_button "Save heading"
|
|
|
|
expect(page).to have_content "Heading updated successfully"
|
|
|
|
visit path
|
|
|
|
expect(page).to have_field "Heading name", with: "Heading name in English"
|
|
|
|
select "Español", from: "Current language"
|
|
|
|
expect(page).to have_field "Heading name", with: "Nombre de la partida en español"
|
|
|
|
select "Français", from: "Current language"
|
|
|
|
expect(page).to have_field "Heading name", with: "Nom en Français"
|
|
end
|
|
end
|
|
|
|
context "CKEditor fields" do
|
|
let(:translatable) { create(:site_customization_page) }
|
|
let(:path) { edit_admin_site_customization_page_path(translatable) }
|
|
|
|
scenario "Maintains existing translations" do
|
|
visit path
|
|
|
|
select "Français", from: "Add language"
|
|
fill_in "Title", with: "Titre en Français"
|
|
fill_in "Subtitle", with: "Sous-titres en Français"
|
|
fill_in_ckeditor "Content", with: "Contenu en Français"
|
|
click_button "Update Custom page"
|
|
|
|
expect(page).to have_content "Page updated successfully"
|
|
|
|
visit path
|
|
|
|
expect(page).to have_ckeditor "Content", with: "Content in English"
|
|
|
|
select "Español", from: "Current language"
|
|
|
|
expect(page).to have_ckeditor "Content", with: "Contenido en español"
|
|
|
|
select "Français", from: "Current language"
|
|
|
|
expect(page).to have_ckeditor "Content", with: "Contenu en Français"
|
|
end
|
|
end
|
|
|
|
context "Markdownit field" do
|
|
let(:translatable) { create(:legislation_draft_version) }
|
|
let(:path) { edit_admin_legislation_process_draft_version_path(translatable.process, translatable) }
|
|
|
|
scenario "Maintains existing translations" do
|
|
visit path
|
|
|
|
select "Français", from: "Add language"
|
|
fill_in "Version title", with: "Titre en Français"
|
|
click_link class: "fullscreen-toggle"
|
|
fill_in "Text", with: "Texte en Français"
|
|
click_link class: "fullscreen-toggle"
|
|
click_button "Save changes"
|
|
|
|
expect(page).to have_content "Draft updated successfully"
|
|
|
|
visit path
|
|
click_link class: "fullscreen-toggle"
|
|
|
|
expect(page).to have_field "Text", with: "Text in English"
|
|
|
|
click_link class: "fullscreen-toggle"
|
|
select "Español", from: "Current language"
|
|
click_link class: "fullscreen-toggle"
|
|
|
|
expect(page).to have_field "Text", with: "Texto en español"
|
|
|
|
click_link class: "fullscreen-toggle"
|
|
select "Français", from: "Current language"
|
|
click_link class: "fullscreen-toggle"
|
|
|
|
expect(page).to have_field "Text", with: "Texte en Français"
|
|
end
|
|
end
|
|
|
|
context "Locale with non-underscored name" do
|
|
let(:translatable) { create(:legislation_question) }
|
|
let(:path) { edit_admin_legislation_process_question_path(translatable.process, translatable) }
|
|
|
|
scenario "Adds a translation for that locale" do
|
|
visit path
|
|
|
|
select "Português brasileiro", from: "Add language"
|
|
fill_in "Question", with: "Português"
|
|
click_button "Save changes"
|
|
|
|
expect(page).to have_content "Question updated successfully"
|
|
|
|
visit path
|
|
select "Português brasileiro", from: "Language:"
|
|
|
|
expect(page).to have_field "Questão", with: "Português"
|
|
end
|
|
end
|
|
end
|
|
|
|
context "Add an invalid translation" do
|
|
let(:translatable) { create(:budget_investment) }
|
|
|
|
context "Input field" do
|
|
let(:translatable) { create(:budget, main_link_url: "https://consuldemocracy.org") }
|
|
|
|
scenario "Shows validation erros" do
|
|
visit edit_admin_budget_path(translatable)
|
|
|
|
select "Français", from: "Add language"
|
|
fill_in "Name", with: ""
|
|
click_button "Update Budget"
|
|
|
|
expect(page).to have_css "#error_explanation"
|
|
|
|
select "Français", from: "Current language"
|
|
|
|
expect(page).to have_field "Name", with: "", class: "is-invalid-input"
|
|
end
|
|
end
|
|
|
|
context "CKEditor field" do
|
|
let(:translatable) { create(:budget_investment) }
|
|
|
|
scenario "Shows validation errors" do
|
|
visit edit_admin_budget_budget_investment_path(translatable.budget, translatable)
|
|
|
|
select "Français", from: "Add language"
|
|
fill_in "Title", with: "Titre en Français"
|
|
fill_in_ckeditor "Description", with: ""
|
|
click_button "Update"
|
|
|
|
expect(page).to have_css "#error_explanation"
|
|
|
|
select "Français", from: "Current language"
|
|
|
|
expect(page).to have_ckeditor "Description", with: ""
|
|
end
|
|
end
|
|
|
|
context "Markdownit field" do
|
|
let(:translatable) { create(:legislation_draft_version) }
|
|
|
|
scenario "Shows validation errors" do
|
|
visit edit_admin_legislation_process_draft_version_path(translatable.process, translatable)
|
|
|
|
select "Français", from: "Add language"
|
|
fill_in "Version title", with: "Titre en Français"
|
|
click_link class: "fullscreen-toggle"
|
|
fill_in "Text", with: ""
|
|
click_link class: "fullscreen-toggle"
|
|
click_button "Save changes"
|
|
|
|
expect(page).to have_css "#error_explanation"
|
|
|
|
select "Français", from: "Current language"
|
|
click_link class: "fullscreen-toggle"
|
|
|
|
expect(page).to have_field "Text", with: "", class: "is-invalid-input"
|
|
end
|
|
end
|
|
end
|
|
|
|
context "Update a translation" do
|
|
context "Input fields" do
|
|
let(:translatable) { create(:widget_card) }
|
|
let(:path) { edit_admin_widget_card_path(translatable) }
|
|
|
|
scenario "Changes the existing translation" do
|
|
visit path
|
|
|
|
select "Español", from: "Current language"
|
|
|
|
within(".translatable-fields") do
|
|
fill_in "Title", with: "Título corregido"
|
|
fill_in "Description", with: "Descripción corregida"
|
|
fill_in "Link text", with: "Texto del enlace corregido"
|
|
fill_in "Label (optional)", with: "Etiqueta corregida"
|
|
end
|
|
|
|
click_button "Save card"
|
|
|
|
expect(page).to have_content "Card updated successfully"
|
|
|
|
visit path
|
|
|
|
expect(page).to have_field "Title", with: "Title in English"
|
|
|
|
select "Español", from: "Language:"
|
|
|
|
expect(page).to have_field "Título", with: "Título corregido"
|
|
expect(page).to have_field "Descripción", with: "Descripción corregida"
|
|
expect(page).to have_field "Texto del enlace", with: "Texto del enlace corregido"
|
|
expect(page).to have_field "Etiqueta (opcional)", with: "Etiqueta corregida"
|
|
end
|
|
end
|
|
|
|
context "CKEditor fields" do
|
|
let(:translatable) { create(:poll_question_option, poll: create(:poll, :future)) }
|
|
let(:path) { edit_admin_question_option_path(translatable.question, translatable) }
|
|
|
|
scenario "Changes the existing translation" do
|
|
visit path
|
|
|
|
select "Español", from: "Current language"
|
|
|
|
within(".translatable-fields") do
|
|
fill_in "Answer", with: "Respuesta corregida"
|
|
fill_in_ckeditor "Description", with: "Descripción corregida"
|
|
end
|
|
|
|
click_button "Save"
|
|
|
|
expect(page).to have_content "Changes saved"
|
|
|
|
visit path
|
|
|
|
expect(page).to have_field "Answer", with: "Answer in English"
|
|
|
|
select "Español", from: "Language:"
|
|
|
|
expect(page).to have_field "Respuesta", with: "Respuesta corregida"
|
|
expect(page).to have_ckeditor "Descripción", with: "Descripción corregida"
|
|
end
|
|
end
|
|
|
|
context "Change value of a translated field to blank" do
|
|
let(:translatable) { create(:poll, :future) }
|
|
let(:path) { edit_admin_poll_path(translatable) }
|
|
|
|
scenario "Updates the field to a blank value" do
|
|
visit path
|
|
|
|
expect(page).to have_field "Summary", with: "Summary in English"
|
|
|
|
fill_in "Summary", with: ""
|
|
click_button "Update poll"
|
|
|
|
expect(page).to have_content "Poll updated successfully"
|
|
|
|
visit path
|
|
|
|
expect(page).to have_field "Summary", with: ""
|
|
end
|
|
end
|
|
end
|
|
|
|
context "Update a translation with invalid data" do
|
|
context "Input fields" do
|
|
let(:translatable) { create(:banner) }
|
|
|
|
scenario "Show validation errors" do
|
|
visit edit_admin_banner_path(translatable)
|
|
select "Español", from: "Current language"
|
|
|
|
expect(page).to have_field "Title", with: "Title en español"
|
|
|
|
fill_in "Title", with: ""
|
|
click_button "Save changes"
|
|
|
|
expect(page).to have_css "#error_explanation"
|
|
|
|
select "Español", from: "Current language"
|
|
|
|
expect(page).to have_field "Title", with: "", class: "is-invalid-input"
|
|
end
|
|
end
|
|
|
|
context "Markdownit field" do
|
|
let(:translatable) { create(:legislation_draft_version) }
|
|
|
|
scenario "Shows validation errors" do
|
|
visit edit_admin_legislation_process_draft_version_path(translatable.process, translatable)
|
|
|
|
select "Español", from: "Current language"
|
|
click_link class: "fullscreen-toggle"
|
|
|
|
expect(page).to have_field "Text", with: "Texto en español"
|
|
|
|
fill_in "Text", with: ""
|
|
click_link class: "fullscreen-toggle"
|
|
click_button "Save changes"
|
|
|
|
expect(page).to have_css "#error_explanation"
|
|
|
|
select "Español", from: "Current language"
|
|
click_link class: "fullscreen-toggle"
|
|
|
|
expect(page).to have_field "Text", with: ""
|
|
end
|
|
end
|
|
end
|
|
|
|
context "Update a translation not having the current locale" do
|
|
let(:translatable) { create(:legislation_process) }
|
|
|
|
before do
|
|
translatable.translations.destroy_all
|
|
translatable.translations.create!(locale: :fr, title: "Titre en Français")
|
|
end
|
|
|
|
scenario "Does not add a translation for the current locale" do
|
|
visit edit_admin_legislation_process_path(translatable)
|
|
|
|
expect_to_have_language_selected "Français"
|
|
expect_not_to_have_language "English"
|
|
|
|
click_button "Save changes"
|
|
|
|
expect(page).to have_content "Process updated successfully"
|
|
|
|
visit edit_admin_legislation_process_path(translatable)
|
|
|
|
expect_to_have_language_selected "Français"
|
|
expect_not_to_have_language "English"
|
|
end
|
|
end
|
|
|
|
context "Remove a translation" do
|
|
let(:translatable) { create(:budget_group) }
|
|
let(:path) { edit_admin_budget_group_path(translatable.budget, translatable) }
|
|
|
|
scenario "Keeps the other languages" do
|
|
visit path
|
|
|
|
select "Español", from: "Current language"
|
|
click_link "Remove language"
|
|
|
|
expect(page).not_to have_select "Current language", with_options: ["Español"]
|
|
|
|
click_button "Save group"
|
|
|
|
expect(page).to have_content "Group updated successfully"
|
|
|
|
visit path
|
|
|
|
expect(page).not_to have_select "Current language", with_options: ["Español"]
|
|
expect(page).to have_select "Current language", with_options: ["English"]
|
|
end
|
|
end
|
|
|
|
context "Remove all translations" do
|
|
let(:translatable) { create(:milestone) }
|
|
|
|
scenario "Shows an error message when there's a mandatory translatable field" do
|
|
translatable.update!(status: nil)
|
|
|
|
visit admin_polymorphic_path(translatable, action: :edit)
|
|
|
|
click_link "Remove language"
|
|
click_link "Remove language"
|
|
|
|
click_button "Update milestone"
|
|
|
|
expect(page).to have_content "Is mandatory to provide one translation at least"
|
|
end
|
|
|
|
scenario "Is successful when there isn't a mandatory translatable field" do
|
|
translatable.update!(status: Milestone::Status.first)
|
|
|
|
visit admin_polymorphic_path(translatable, action: :edit)
|
|
|
|
click_link "Remove language"
|
|
click_link "Remove language"
|
|
|
|
click_button "Update milestone"
|
|
|
|
expect(page).to have_content "Milestone updated successfully"
|
|
end
|
|
end
|
|
|
|
context "Remove a translation with invalid data" do
|
|
let(:translatable) { create(:poll_question, poll: create(:poll, :future)) }
|
|
let(:path) { edit_admin_question_path(translatable) }
|
|
|
|
scenario "Doesn't remove the translation" do
|
|
visit path
|
|
|
|
select "Español", from: "Current language"
|
|
click_link "Remove language"
|
|
|
|
select "English", from: "Current language"
|
|
fill_in "Question", with: ""
|
|
click_button "Save"
|
|
|
|
expect(page).to have_css "#error_explanation"
|
|
expect(page).to have_field "Question", with: "", class: "is-invalid-input"
|
|
expect_to_have_language_selected "English"
|
|
expect_not_to_have_language "Español"
|
|
|
|
visit path
|
|
select "Español", from: "Current language"
|
|
|
|
expect(page).to have_field "Question", with: "Pregunta en español"
|
|
end
|
|
end
|
|
|
|
context "Current locale translation does not exist" do
|
|
context "For all translatable except ActivePoll and Budget::Phase" do
|
|
let(:translatable) { create(:admin_notification, segment_recipient: "all_users") }
|
|
|
|
scenario "Shows first available fallback" do
|
|
translatable.update!({ title_fr: "Titre en Français", body_fr: "Texte en Français" })
|
|
|
|
visit edit_admin_admin_notification_path(translatable)
|
|
|
|
select "English", from: "Current language"
|
|
click_link "Remove language"
|
|
select "Español", from: "Current language"
|
|
click_link "Remove language"
|
|
|
|
click_button "Update notification"
|
|
|
|
expect(page).to have_content "Titre en Français"
|
|
end
|
|
end
|
|
|
|
context "For Budget::Phase" do
|
|
let(:translatable) { create(:budget).phases.last }
|
|
|
|
scenario "Shows first available fallback" do
|
|
translatable.update!({ name_fr: "Name en Français", description_fr: "Phase en Français" })
|
|
|
|
visit edit_admin_budget_budget_phase_path(translatable.budget, translatable)
|
|
|
|
select "English", from: "Current language"
|
|
click_link "Remove language"
|
|
select "Español", from: "Current language"
|
|
click_link "Remove language"
|
|
|
|
click_button "Save changes"
|
|
|
|
expect(page).to have_content "Changes saved"
|
|
|
|
visit budgets_path
|
|
click_link "Name en Français"
|
|
|
|
expect(page).to have_content "Phase en Français"
|
|
end
|
|
end
|
|
|
|
context "For ActivePoll" do
|
|
let(:translatable) { create(:active_poll) }
|
|
|
|
scenario "Shows first available fallback" do
|
|
translatable.update!({ description_fr: "Sondage en Français" })
|
|
|
|
visit edit_admin_active_polls_path(translatable)
|
|
|
|
select "English", from: "Current language"
|
|
click_link "Remove language"
|
|
select "Español", from: "Current language"
|
|
click_link "Remove language"
|
|
click_button "Save"
|
|
|
|
expect(page).to have_content "Polls description updated successfully"
|
|
|
|
visit polls_path
|
|
|
|
expect(page).to have_content "Sondage en Français"
|
|
end
|
|
end
|
|
end
|
|
|
|
context "Globalize javascript interface" do
|
|
let(:translatable) { create(:i18n_content) }
|
|
let(:content) { translatable }
|
|
let(:path) { admin_site_customization_information_texts_path }
|
|
|
|
scenario "Select current locale when its translation exists" do
|
|
visit path
|
|
|
|
expect_to_have_language_selected "English"
|
|
|
|
select "Español", from: "Language:"
|
|
|
|
expect_to_have_language_selected "Español"
|
|
end
|
|
|
|
scenario "Select first locale of existing translations when current locale translation does not exists" do
|
|
content.translations.where(locale: :en).destroy_all
|
|
visit path
|
|
|
|
expect_to_have_language_selected "Español"
|
|
end
|
|
|
|
scenario "Show selected locale form" do
|
|
visit path
|
|
|
|
expect(page).to have_field content.key, with: "Value in English"
|
|
|
|
select "Español", from: "Current language"
|
|
|
|
expect(page).to have_field content.key, with: "Value en español"
|
|
end
|
|
|
|
scenario "Select a locale and add it to the form" do
|
|
visit path
|
|
|
|
select "Français", from: "Add language"
|
|
|
|
expect_to_have_language_selected "Français"
|
|
expect(page).to have_select "Add language", selected: ""
|
|
expect(page).to have_field "contents_content_#{content.key}values_value_fr"
|
|
end
|
|
|
|
context "Languages in use" do
|
|
scenario "Show default description" do
|
|
visit path
|
|
|
|
expect(page).to have_content "2 languages in use"
|
|
end
|
|
|
|
scenario "Increase description count after add new language" do
|
|
visit path
|
|
|
|
select "Français", from: "Add language"
|
|
|
|
expect(page).to have_content "3 languages in use"
|
|
end
|
|
|
|
scenario "Decrease description count after remove a language" do
|
|
visit path
|
|
|
|
click_link "Remove language"
|
|
|
|
expect(page).to have_content "1 language in use"
|
|
end
|
|
end
|
|
|
|
context "When translation interface feature setting" do
|
|
scenario "Is enabled translation interface should be rendered" do
|
|
visit path
|
|
|
|
expect(page).to have_css ".globalize-languages"
|
|
end
|
|
|
|
scenario "Is disabled translation interface should be rendered" do
|
|
Setting["feature.translation_interface"] = nil
|
|
|
|
visit path
|
|
|
|
expect(page).to have_css ".globalize-languages"
|
|
end
|
|
end
|
|
end
|
|
end
|