discourse/spec/system/content_localization_spec.rb
Natalie Tay d81faa1226
FIX: Do not set locale when replying and also default to none (#33312)
This PR relates to the locale setting in the composer and fixes 2
quirks:
- When replying to a post, the composer sets the locale of the new post
in composer to the locale of the post being replied. This PR defaults
the value to "none"
- When creating a new post, the composer sets the locale to the user's
locale. However we are seeing the behaviour that users do not write in
the locale they set their profile to. This PR defaults the value to
"none"
2025-06-23 21:11:03 +08:00

95 lines
3.4 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
describe "Content Localization" do
fab!(:japanese_user) { Fabricate(:user, locale: "ja") }
fab!(:site_local_user) { Fabricate(:user, locale: "en") }
fab!(:author) { Fabricate(:user) }
fab!(:jap_group) { Fabricate(:group).tap { |g| g.add(japanese_user) } }
fab!(:topic) do
Fabricate(:topic, title: "Life strategies from The Art of War", locale: "en", user: author)
end
fab!(:post_1) do
Fabricate(
:post,
topic:,
locale: "en",
raw: "The masterpiece isnt just about military strategy",
)
end
fab!(:post_2) do
Fabricate(
:post,
topic:,
locale: "en",
raw: "The greatest victory is that which requires no battle",
)
end
fab!(:post_3) { Fabricate(:post, topic:, locale: "ja", raw: "将とは、智・信・仁・勇・厳なり。") }
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:composer) { PageObjects::Components::Composer.new }
let(:post_1_obj) { PageObjects::Components::Post.new(1) }
before do
Fabricate(:topic_localization, topic:, locale: "ja", fancy_title: "孫子兵法からの人生戦略")
Fabricate(:topic_localization, topic:, locale: "es", fancy_title: "Estrategias de vida de ...")
Fabricate(:post_localization, post: post_1, locale: "ja", cooked: "傑作は単なる軍事戦略についてではありません")
Fabricate(:post_localization, post: post_2, locale: "ja", cooked: "最大の勝利は戦いを必要としないものです")
Fabricate(:post_localization, post: post_3, locale: "en", cooked: "A general is one who ..")
end
context "when the feature is enabled for English and Japanese" do
before do
SiteSetting.allow_user_locale = true
SiteSetting.content_localization_enabled = true
SiteSetting.content_localization_allowed_groups =
"#{Group::AUTO_GROUPS[:admins]}|#{jap_group.id}"
SiteSetting.content_localization_supported_locales = "en|ja"
end
it "shows the correct language based on the selected language and login status" do
sign_in(japanese_user)
visit("/")
visit("/t/#{topic.id}")
expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true)
end
it "shows original content when 'Show Original' is selected" do
sign_in(japanese_user)
visit("/")
topic_list.visit_topic_with_title("孫子兵法からの人生戦略")
expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true)
page.find("button.btn-toggle-localized-content").click
expect(topic_page.has_topic_title?("Life strategies from The Art of War")).to eq(true)
visit("/")
topic_list.visit_topic_with_title("Life strategies from The Art of War")
end
it "allows users to set their post's locale when posting" do
sign_in(japanese_user)
visit("/")
topic_list.visit_topic_with_title("孫子兵法からの人生戦略")
topic_page.click_post_action_button(post_1, :reply)
expect(composer).to be_opened
expect(composer.locale.text.gsub(/\u200B/, "")).to be_blank
composer.set_locale("日本語")
composer.fill_content("新しい投稿の内容 をここに入力します。")
composer.create
sign_in(site_local_user)
topic_page.visit_topic(topic)
expect(post_1_obj).to have_css(".post-info.post-language")
end
end
end