Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix constant reassignment warnings in specs (#39233)

Jarek Radosz479570134f78
diff --git a/spec/system/category_localizations_spec.rb b/spec/system/category_localizations_spec.rb
index b3965dd7b8c..970905c9b9f 100644
--- a/spec/system/category_localizations_spec.rb
+++ b/spec/system/category_localizations_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Category Localizations" do
- SWITCHER_SELECTOR = "button[data-identifier='language-switcher']"
+ let(:switcher_selector) { "button[data-identifier='language-switcher']" }
fab!(:admin)
fab!(:category) do
@@ -17,7 +17,7 @@ describe "Category Localizations" do
end
let(:category_page) { PageObjects::Pages::Category.new }
let(:form) { PageObjects::Components::FormKit.new("form") }
- let(:switcher) { PageObjects::Components::DMenu.new(SWITCHER_SELECTOR) }
+ let(:switcher) { PageObjects::Components::DMenu.new(switcher_selector) }
before do
SiteSetting.content_localization_supported_locales = "es|ja|fr"
diff --git a/spec/system/content_localization_language_switcher_spec.rb b/spec/system/content_localization_language_switcher_spec.rb
index 372e3f87067..e43868858e6 100644
--- a/spec/system/content_localization_language_switcher_spec.rb
+++ b/spec/system/content_localization_language_switcher_spec.rb
@@ -1,11 +1,11 @@
# frozen_string_literal: true
describe "Content localization language switcher" do
- SWITCHER_SELECTOR = "button[data-identifier='language-switcher']"
- TOGGLE_LOCALIZE_BUTTON_SELECTOR = "button.btn-toggle-localized-content"
+ let(:switcher_selector) { "button[data-identifier='language-switcher']" }
+ let(:toggle_localize_button_selector) { "button.btn-toggle-localized-content" }
let(:topic_list) { PageObjects::Components::TopicList.new }
- let(:switcher) { PageObjects::Components::DMenu.new(SWITCHER_SELECTOR) }
+ let(:switcher) { PageObjects::Components::DMenu.new(switcher_selector) }
fab!(:japanese_user) { Fabricate(:user, locale: "ja") }
@@ -55,7 +55,7 @@ describe "Content localization language switcher" do
SiteSetting.content_localization_language_switcher = "anonymous"
visit("/")
- expect(page).to have_no_css(SWITCHER_SELECTOR)
+ expect(page).to have_no_css(switcher_selector)
SiteSetting.content_localization_enabled = true
@@ -75,42 +75,42 @@ describe "Content localization language switcher" do
it "only shows the language switcher if turned on for various types of users (anon, logged in)" do
SiteSetting.content_localization_language_switcher = "none"
visit("/")
- expect(page).not_to have_css(SWITCHER_SELECTOR)
+ expect(page).not_to have_css(switcher_selector)
SiteSetting.content_localization_language_switcher = "anonymous"
visit("/")
- expect(page).to have_css(SWITCHER_SELECTOR)
+ expect(page).to have_css(switcher_selector)
SiteSetting.content_localization_language_switcher = "all"
visit("/")
- expect(page).to have_css(SWITCHER_SELECTOR)
+ expect(page).to have_css(switcher_selector)
sign_in(japanese_user)
SiteSetting.content_localization_language_switcher = "none"
visit("/")
- expect(page).not_to have_css(SWITCHER_SELECTOR)
+ expect(page).not_to have_css(switcher_selector)
SiteSetting.content_localization_language_switcher = "anonymous"
visit("/")
- expect(page).not_to have_css(SWITCHER_SELECTOR)
+ expect(page).not_to have_css(switcher_selector)
SiteSetting.content_localization_language_switcher = "all"
visit("/")
- expect(page).to have_css(SWITCHER_SELECTOR)
+ expect(page).to have_css(switcher_selector)
end
it "displays the current language code on the trigger button" do
SiteSetting.content_localization_language_switcher = "all"
visit("/")
- expect(page.find(SWITCHER_SELECTOR)).to have_content("EN")
+ expect(page.find(switcher_selector)).to have_content("EN")
select_language("ja")
- expect(page.find(SWITCHER_SELECTOR)).to have_content("JA")
+ expect(page.find(switcher_selector)).to have_content("JA")
select_language("es")
- expect(page.find(SWITCHER_SELECTOR)).to have_content("ES")
+ expect(page.find(switcher_selector)).to have_content("ES")
end
it "shows localized content when switching languages (anon, logged in)" do
@@ -151,15 +151,15 @@ describe "Content localization language switcher" do
expect(topic_list).to have_content("孫子兵法からの人生戦略")
I18n.with_locale(:ja) do
- expect(page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR)["title"]).to eq(
+ expect(page.find(toggle_localize_button_selector)["title"]).to eq(
I18n.t("js.content_localization.toggle_localized.translated"),
)
end
- page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR).click
+ page.find(toggle_localize_button_selector).click
expect(topic_list).to have_content("Life strategies from The Art of War")
I18n.with_locale(:ja) do
- expect(page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR)["title"]).to eq(
+ expect(page.find(toggle_localize_button_selector)["title"]).to eq(
I18n.t("js.content_localization.toggle_localized.not_translated"),
)
end
@@ -168,7 +168,7 @@ describe "Content localization language switcher" do
expect(topic_list).to have_content("Estrategias de vida de El arte de la guerra")
I18n.with_locale("es") do
- expect(page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR)["title"]).to eq(
+ expect(page.find(toggle_localize_button_selector)["title"]).to eq(
I18n.t("js.content_localization.toggle_localized.translated"),
)
end
diff --git a/spec/system/content_localization_spec.rb b/spec/system/content_localization_spec.rb
index dd43551a66b..3978ef3e658 100644
--- a/spec/system/content_localization_spec.rb
+++ b/spec/system/content_localization_spec.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
describe "Content Localization" do
- TOGGLE_LOCALIZE_BUTTON_SELECTOR = "button.btn-toggle-localized-content"
+ let(:toggle_localize_button_selector) { "button.btn-toggle-localized-content" }
+ let(:switcher_selector) { "button[data-identifier='language-switcher']" }
fab!(:japanese_user) { Fabricate(:user, locale: "ja") }
fab!(:site_local_user) { Fabricate(:user, locale: "en") }
@@ -84,15 +85,15 @@ describe "Content Localization" do
expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true)
I18n.with_locale(:ja) do
- expect(page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR)["title"]).to eq(
+ expect(page.find(toggle_localize_button_selector)["title"]).to eq(
I18n.t("js.content_localization.toggle_localized.translated"),
)
end
- page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR).click
+ page.find(toggle_localize_button_selector).click
expect(topic_page.has_topic_title?("Life strategies from The Art of War")).to eq(true)
I18n.with_locale(:ja) do
- expect(page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR)["title"]).to eq(
+ expect(page.find(toggle_localize_button_selector)["title"]).to eq(
I18n.t("js.content_localization.toggle_localized.not_translated"),
)
end
@@ -106,7 +107,7 @@ describe "Content Localization" do
visit("/t/#{topic.id}")
expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true)
- page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR).click
+ page.find(toggle_localize_button_selector).click
expect(topic_page.has_topic_title?("Life strategies from The Art of War")).to eq(true)
# preference persists after full page reload
@@ -294,11 +295,11 @@ describe "Content Localization" do
expect(topic_page).to have_topic_title(original_translated_title)
# View original - displayed title should update to new original title
- page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR).click
+ page.find(toggle_localize_button_selector).click
expect(topic_page).to have_topic_title("New Original Title")
# switch back to Japanese to test translation editing
- page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR).click
+ page.find(toggle_localize_button_selector).click
# Viewing translation - Edit translation
topic_page.click_topic_edit_title
@@ -403,7 +404,7 @@ describe "Content Localization" do
expect(topic_page).to have_post_content(post_number: 21, content: "English translation 21")
# toggle should show correct state of post content
- page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR).click
+ page.find(toggle_localize_button_selector).click
scroll_to_post(21)
expect(post_21_obj.post).to have_content("日本語コンテンツ 21")
@@ -437,10 +438,10 @@ describe "Content Localization" do
topic_page.visit_topic(shady_topic)
expect(page).to have_title(shady_topic_ja_localization.fancy_title)
- page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR).click
+ page.find(toggle_localize_button_selector).click
expect(page).to have_title(shady_topic.title)
- page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR).click
+ page.find(toggle_localize_button_selector).click
expect(page).to have_title(shady_topic_ja_localization.fancy_title)
SiteSetting.content_localization_enabled = false
@@ -527,11 +528,9 @@ describe "Content Localization" do
end
context "for tags" do
- SWITCHER_SELECTOR = "button[data-identifier='language-switcher']"
-
let(:discovery) { PageObjects::Pages::Discovery.new }
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
- let(:switcher) { PageObjects::Components::DMenu.new(SWITCHER_SELECTOR) }
+ let(:switcher) { PageObjects::Components::DMenu.new(switcher_selector) }
fab!(:tag) { Fabricate(:tag, name: "strategy", locale: "en") }
fab!(:tag_localization) { Fabricate(:tag_localization, tag:, locale: "ja", name: "戦略") }