mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-21 04:42:56 +08:00
This update is a follow-up to b0ab1b2321, where we now allow localizations for a category to be set in the category settings UI.
86 lines
3.7 KiB
Ruby
Vendored
86 lines
3.7 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 { SiteSetting.experimental_content_localization = true }
|
|
|
|
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
|