From 5297da5df5c7a8080a4cb355a148a86c539577ca Mon Sep 17 00:00:00 2001 From: Guillaume MORET <90462045+AyakorK@users.noreply.github.com> Date: Mon, 19 Feb 2024 11:11:21 +0100 Subject: [PATCH] fix: Flaky test on locales spec (#499) * fix: Try to fix flaky by authenticating user on each step * lint: Quick fixes --- spec/system/locales_spec.rb | 51 +++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/spec/system/locales_spec.rb b/spec/system/locales_spec.rb index 974ff0a848..9008d4029b 100644 --- a/spec/system/locales_spec.rb +++ b/spec/system/locales_spec.rb @@ -4,10 +4,12 @@ describe "Locales", type: :system do describe "switching locales" do - let(:organization) { create(:organization, available_locales: %w(fr en)) } + let(:organization) { create(:organization, available_locales: %w(fr en), default_locale: "en") } + let(:user) { create(:user, :confirmed, locale: "en", organization: organization) } before do switch_to_host(organization.host) + login_as user, scope: :user visit decidim.root_path end @@ -37,40 +39,45 @@ expect(page).to have_content("Accueil") end - it "displays devise messages with the right locale when not authenticated" do - within_language_menu do - click_link "Français" - end + context "when not authenticated" do + let(:user) { nil } - visit decidim_admin.root_path + it "displays devise messages with the right locale when not authenticated" do + within_language_menu do + click_link "Français" + end - expect(page).to have_content("Vous devez vous identifier ou vous créer un compte avant de continuer") - end + visit decidim_admin.root_path - it "displays devise messages with the right locale when authentication fails" do - within_language_menu do - click_link "Français" + expect(page).to have_content("Vous devez vous identifier ou vous créer un compte avant de continuer") end + end + + context "when authentication fails" do + let(:user) { nil } + + it "displays devise messages with the right locale" do + within_language_menu do + click_link "Français" + end - find(".sign-in-link").click + find(".sign-in-link").click - fill_in "session_user_email", with: "toto@example.org" - fill_in "session_user_password", with: "toto" + fill_in "session_user_email", with: "toto@example.org" + fill_in "session_user_password", with: "toto" - click_button "S'identifier" + click_button "S'identifier" - expect(page).to have_content("Email ou mot de passe invalide") + expect(page).to have_content("Email ou mot de passe invalide") + end end context "with a signed in user" do let(:user) { create(:user, :confirmed, locale: "fr", organization: organization) } - before do - login_as user, scope: :user - visit decidim.root_path - end - - it "uses the user's locale" do + it "displays content based on user's locale" do + expect(page).not_to have_content("Sign in") + expect(page).not_to have_content("S'identifier") expect(page).to have_content("Accueil") end end