Skip to content

Commit

Permalink
fix: Flaky test on locales spec (#499)
Browse files Browse the repository at this point in the history
* fix: Try to fix flaky by authenticating user on each step

* lint: Quick fixes
  • Loading branch information
AyakorK authored Feb 19, 2024
1 parent beed47e commit 5297da5
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions spec/system/locales_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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: "[email protected]"
fill_in "session_user_password", with: "toto"
fill_in "session_user_email", with: "[email protected]"
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
Expand Down

0 comments on commit 5297da5

Please sign in to comment.