discourse/spec/system/edit_category_localizations_spec.rb
Keegan George 4d380a28e7
FEATURE: Add post language on creating a new post (#33160)
This is a second attempt at:
https://github.com/discourse/discourse/pull/33001

We had to [revert the
commit](https://github.com/discourse/discourse/pull/33157) because it
was performing a site-setting check at boot time, which is prone to
issues and not allowed.

This PR:
- re-introduces the changes in the original PR
- a fix by not performing a site-setting check at boot time (verified
by: `SKIP_DB_AND_REDIS=1 DISCOURSE_DEV_DB="nonexist" bin/rails runner
"puts 'booted'"` locally and should be caught by the new CI check
introduced here: https://github.com/discourse/discourse/pull/33158)
- adds a fix to the translation editor to not show the original post
locale in the dropdown, as well as adding an indicator of what the
original post locale is in a small badge in the header:
- ![Screenshot 2025-06-11 at 08 42
36](https://github.com/user-attachments/assets/5f0944c5-ec4d-40b3-b97f-25b1fcab8329)
2025-06-11 10:39:01 -07:00

95 lines
4.1 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Edit Category Localizations", type: :system do
fab!(:admin)
fab!(:category) do
Fabricate(:category, name: "Feature Requests", slug: "feature-requests", topic_count: 1234)
end
let(:category_page) { PageObjects::Pages::Category.new }
let(:form) { PageObjects::Components::FormKit.new("form") }
before { sign_in(admin) }
context "when content localization setting is disabled" do
before { SiteSetting.experimental_content_localization = false }
it "should not show the localization tab" do
category_page.visit_settings(category)
expect(category_page).to have_no_setting_tab("localizations")
end
end
context "when content localization setting is enabled" do
before do
SiteSetting.default_locale = "en"
SiteSetting.experimental_content_localization = true
SiteSetting.experimental_content_localization_supported_locales = "es|fr"
SiteSetting.experimental_content_localization_allowed_groups = Group::AUTO_GROUPS[:everyone]
if SiteSetting.client_settings.exclude?(:available_content_localization_locales)
SiteSetting.client_settings << :available_content_localization_locales
end
end
it "should show the localization tab" do
category_page.visit_settings(category)
expect(category_page).to have_setting_tab("localizations")
end
describe "when editing a category with no category localizations" do
before { category.update(category_localizations: []) }
it "should show info hint to add new localizations" do
category_page.visit_edit_localizations(category)
expect(form).to have_an_alert(I18n.t("js.category.localization.hint"))
end
it "should allow you to add new localizations" do
category_page.visit_edit_localizations(category)
category_page.find(".edit-category-tab-localizations .add-localization").click
form.field("localizations.0.locale").select("es")
form.field("localizations.0.name").fill_in("Solicitud de función")
form.field("localizations.0.description").fill_in(
"Solicitar nuevas funcionalidades en esta categoría",
)
category_page.find(".edit-category-tab-localizations .add-localization").click
form.field("localizations.1.locale").select("fr")
form.field("localizations.1.name").fill_in("Demande de fonctionnalité")
form.field("localizations.1.description").fill_in(
"Demander de nouvelles fonctionnalités dans cette catégorie",
)
category_page.save_settings
page.refresh
expect(CategoryLocalization.where(category_id: category.id).count).to eq(2)
expect(CategoryLocalization.where(category_id: category.id, locale: "es").count).to eq(1)
expect(CategoryLocalization.where(category_id: category.id, locale: "fr").count).to eq(1)
expect(CategoryLocalization.where(category_id: category.id, locale: "es").first.name).to eq(
"Solicitud de función",
)
expect(CategoryLocalization.where(category_id: category.id, locale: "fr").first.name).to eq(
"Demande de fonctionnalité",
)
expect(
CategoryLocalization.where(category_id: category.id, locale: "es").first.description,
).to eq("Solicitar nuevas funcionalidades en esta categoría")
expect(
CategoryLocalization.where(category_id: category.id, locale: "fr").first.description,
).to eq("Demander de nouvelles fonctionnalités dans cette catégorie")
end
end
describe "when editing a category with localizations" do
fab!(:category_localization) { Fabricate(:category_localization, category: category) }
it "should allow you to delete localizations" do
expect(CategoryLocalization.where(category_id: category.id).count).to eq(1)
category_page.visit_edit_localizations(category)
page.find(".edit-category-tab-localizations .remove-localization").click
category_page.save_settings
page.refresh
expect(CategoryLocalization.where(category_id: category.id).count).to eq(0)
end
end
end
end