discourse-translator/spec/system/anon_language_switcher_spec.rb
Natalie Tay 48682c26c6
FEATURE: Show experimental language switcher for anon users (#198)
This commit allows anon users to select a language using a language switcher, this feature is behind an experimental site setting experimental_anon_language_switcher. The set of languages are defined by the same one available to existing users of the site, with the required allow_user_locale setting turned on:

de7e213052/app/models/locale_site_setting.rb (L37-L50)

In the near future, we may consider shortening this list of languages, and will also expand this feature into user-contributed content.
2025-01-24 12:01:31 +08:00

28 lines
1 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Anonymous user language switcher", type: :system do
fab!(:japanese_user) { Fabricate(:user, locale: "ja") }
it "shows the correct language based on the selected language and login status" do
SWITCHER_SELECTOR = "button[data-identifier='discourse-translator_language-switcher']"
visit("/")
expect(page).not_to have_css(SWITCHER_SELECTOR)
SiteSetting.translator_enabled = true
SiteSetting.allow_user_locale = true
SiteSetting.set_locale_from_cookie = true
SiteSetting.experimental_anon_language_switcher = true
visit("/")
expect(page).to have_css(SWITCHER_SELECTOR)
expect(find(".nav-item_latest")).to have_content("Latest")
switcher = PageObjects::Components::DMenu.new(SWITCHER_SELECTOR)
switcher.expand
switcher.click_button("Español")
expect(find(".nav-item_latest")).to have_content("Recientes")
sign_in(japanese_user)
visit("/")
expect(find(".nav-item_latest")).to have_content("最新")
end
end