discourse/spec/system/anon_language_switcher_spec.rb
Natalie Tay 0a242221fc
DEV: Force full refresh from language switcher (#33522)
While topics, posts, and titles had the language switched, controls were
still in the old language. Force a full refresh.

Related: t/157985
2025-07-09 11:17:42 +08:00

65 lines
2.1 KiB
Ruby
Vendored
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
RSpec.describe "Anonymous user language switcher", type: :system do
SWITCHER_SELECTOR = "button[data-identifier='language-switcher']"
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:switcher) { PageObjects::Components::DMenu.new(SWITCHER_SELECTOR) }
fab!(:japanese_user) { Fabricate(:user, locale: "ja") }
fab!(:topic) { Fabricate(:topic, title: "Life strategies from The Art of War", locale: "en") }
fab!(:post_1) do
Fabricate(
:post,
topic:,
locale: "en",
raw: "The masterpiece isnt just about military strategy",
)
end
fab!(:topic_localization) do
Fabricate(:topic_localization, topic:, locale: "ja", fancy_title: "孫子兵法からの人生戦略")
end
fab!(:post_localization) do
Fabricate(:post_localization, post: post_1, locale: "ja", cooked: "傑作は単なる軍事戦略についてではありません")
end
before do
SiteSetting.default_locale = "en"
SiteSetting.content_localization_supported_locales = "es|ja"
SiteSetting.content_localization_enabled = true
SiteSetting.allow_user_locale = true
SiteSetting.set_locale_from_cookie = true
end
it "only shows the language switcher based on what is in target languages" do
SiteSetting.content_localization_anon_language_switcher = false
visit("/")
expect(page).not_to have_css(SWITCHER_SELECTOR)
SiteSetting.content_localization_anon_language_switcher = true
visit("/")
switcher.expand
expect(switcher).to have_content("English (US)")
expect(switcher).to have_content("日本語")
expect(switcher).to have_content("Español")
SiteSetting.content_localization_supported_locales = "ja"
visit("/")
switcher.expand
expect(switcher).not_to have_content("Español")
switcher.option("[data-menu-option-id='ja']").click
expect(topic_list).to have_content("孫子兵法からの人生戦略")
I18n.with_locale("ja") do
expect(page.find("#navigation-bar")).to have_content(I18n.t("js.filters.latest.title"))
end
sign_in(japanese_user)
expect(page).not_to have_css(SWITCHER_SELECTOR)
end
end