|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe "Full page translation", type: :system do |
| 4 | + fab!(:japanese_user) { Fabricate(:user, locale: "ja") } |
| 5 | + fab!(:site_local_user) { Fabricate(:user, locale: "en") } |
| 6 | + fab!(:author) { Fabricate(:user) } |
| 7 | + |
| 8 | + fab!(:topic) { Fabricate(:topic, title: "Life strategies from The Art of War", user: author) } |
| 9 | + fab!(:post_1) do |
| 10 | + Fabricate(:post, topic: topic, raw: "The masterpiece isn’t just about military strategy") |
| 11 | + end |
| 12 | + fab!(:post_2) do |
| 13 | + Fabricate(:post, topic: topic, raw: "The greatest victory is that which requires no battle") |
| 14 | + end |
| 15 | + |
| 16 | + let(:topic_page) { PageObjects::Pages::Topic.new } |
| 17 | + |
| 18 | + before do |
| 19 | + # topic translation setup |
| 20 | + topic.set_detected_locale("en") |
| 21 | + post_1.set_detected_locale("en") |
| 22 | + post_2.set_detected_locale("en") |
| 23 | + |
| 24 | + topic.set_translation("ja", "孫子兵法からの人生戦略") |
| 25 | + topic.set_translation("es", "Estrategias de vida de El arte de la guerra") |
| 26 | + post_1.set_translation("ja", "傑作は単なる軍事戦略についてではありません") |
| 27 | + post_2.set_translation("ja", "最大の勝利は戦いを必要としないものです") |
| 28 | + end |
| 29 | + |
| 30 | + context "when the feature is enabled" do |
| 31 | + before do |
| 32 | + SiteSetting.translator_enabled = true |
| 33 | + SiteSetting.allow_user_locale = true |
| 34 | + SiteSetting.set_locale_from_cookie = true |
| 35 | + SiteSetting.set_locale_from_param = true |
| 36 | + SiteSetting.experimental_anon_language_switcher = true |
| 37 | + SiteSetting.experimental_topic_translation = true |
| 38 | + end |
| 39 | + |
| 40 | + it "shows the correct language based on the selected language and login status" do |
| 41 | + visit("/t/#{topic.slug}/#{topic.id}?lang=ja") |
| 42 | + expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true) |
| 43 | + expect(find(topic_page.post_by_number_selector(1))).to have_content("傑作は単なる軍事戦略についてではありません") |
| 44 | + |
| 45 | + visit("/t/#{topic.id}") |
| 46 | + expect(topic_page.has_topic_title?("Life strategies from The Art of War")).to eq(true) |
| 47 | + expect(find(topic_page.post_by_number_selector(1))).to have_content( |
| 48 | + "The masterpiece isn’t just about military strategy", |
| 49 | + ) |
| 50 | + |
| 51 | + sign_in(japanese_user) |
| 52 | + visit("/") |
| 53 | + visit("/t/#{topic.id}") |
| 54 | + expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true) |
| 55 | + end |
| 56 | + end |
| 57 | +end |
0 commit comments