2022-12-07 19:38:36 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-06 21:26:58 -04:00
|
|
|
describe "Admin Customize Themes", type: :system do
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:color_scheme)
|
2024-05-01 20:26:07 -04:00
|
|
|
fab!(:theme) { Fabricate(:theme, name: "Cool theme 1") }
|
2024-04-19 13:23:27 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin, locale: "en") }
|
2022-12-07 19:38:36 -05:00
|
|
|
|
2024-03-05 19:24:29 -05:00
|
|
|
let(:admin_customize_themes_page) { PageObjects::Pages::AdminCustomizeThemes.new }
|
|
|
|
|
2022-12-07 19:38:36 -05:00
|
|
|
before { sign_in(admin) }
|
|
|
|
|
2023-10-08 17:35:53 -04:00
|
|
|
describe "when visiting the page to customize themes" do
|
2024-05-01 20:26:07 -04:00
|
|
|
fab!(:theme_2) { Fabricate(:theme, name: "Cool theme 2") }
|
|
|
|
fab!(:theme_3) { Fabricate(:theme, name: "Cool theme 3") }
|
2023-10-08 17:35:53 -04:00
|
|
|
let(:delete_themes_confirm_modal) { PageObjects::Modals::DeleteThemesConfirm.new }
|
|
|
|
|
|
|
|
it "should allow admin to bulk delete inactive themes" do
|
|
|
|
visit("/admin/customize/themes")
|
|
|
|
|
|
|
|
expect(admin_customize_themes_page).to have_inactive_themes
|
|
|
|
|
|
|
|
admin_customize_themes_page.click_select_inactive_mode
|
|
|
|
expect(admin_customize_themes_page).to have_inactive_themes_selected(count: 0)
|
|
|
|
admin_customize_themes_page.toggle_all_inactive
|
|
|
|
expect(admin_customize_themes_page).to have_inactive_themes_selected(count: 3)
|
|
|
|
|
|
|
|
admin_customize_themes_page.cancel_select_inactive_mode
|
|
|
|
expect(admin_customize_themes_page).to have_select_inactive_mode_button
|
|
|
|
|
|
|
|
admin_customize_themes_page.click_select_inactive_mode
|
|
|
|
expect(admin_customize_themes_page).to have_disabled_delete_theme_button
|
|
|
|
|
|
|
|
admin_customize_themes_page.toggle_all_inactive
|
|
|
|
|
|
|
|
admin_customize_themes_page.click_delete_themes_button
|
|
|
|
|
2023-10-08 21:04:45 -04:00
|
|
|
expect(delete_themes_confirm_modal).to have_theme(theme.name)
|
|
|
|
expect(delete_themes_confirm_modal).to have_theme(theme_2.name)
|
|
|
|
expect(delete_themes_confirm_modal).to have_theme(theme_3.name)
|
2023-10-08 17:35:53 -04:00
|
|
|
delete_themes_confirm_modal.confirm
|
|
|
|
|
|
|
|
expect(admin_customize_themes_page).to have_no_inactive_themes
|
|
|
|
end
|
2023-11-07 22:42:27 -05:00
|
|
|
|
|
|
|
it "selects the themes tab by default" do
|
|
|
|
visit("/admin/customize/themes")
|
|
|
|
expect(find(".themes-list-header")).to have_css(".themes-tab.active")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "selects the component tab when visiting the theme-components route" do
|
2024-04-16 21:45:59 -04:00
|
|
|
visit("/admin/customize/components")
|
2023-11-07 22:42:27 -05:00
|
|
|
expect(find(".themes-list-header")).to have_css(".components-tab.active")
|
|
|
|
end
|
2024-04-16 21:45:59 -04:00
|
|
|
|
|
|
|
it "switching between themes and components tabs keeps the search visible only if both tabs have at least 10 items" do
|
2024-04-28 23:39:14 -04:00
|
|
|
(1..6).each { |number| Fabricate(:theme, component: false, name: "Cool theme #{number}") }
|
2024-04-16 21:45:59 -04:00
|
|
|
(1..5).each { |number| Fabricate(:theme, component: true, name: "Cool component #{number}") }
|
|
|
|
|
|
|
|
visit("/admin/customize/themes")
|
|
|
|
expect(admin_customize_themes_page).to have_themes(count: 11)
|
|
|
|
|
|
|
|
admin_customize_themes_page.search("5")
|
|
|
|
expect(admin_customize_themes_page).to have_themes(count: 1)
|
|
|
|
|
|
|
|
admin_customize_themes_page.switch_to_components
|
|
|
|
expect(admin_customize_themes_page).to have_no_search
|
|
|
|
expect(admin_customize_themes_page).to have_themes(count: 5)
|
|
|
|
|
|
|
|
(6..11).each { |number| Fabricate(:theme, component: true, name: "Cool component #{number}") }
|
|
|
|
|
|
|
|
visit("/admin/customize/components")
|
|
|
|
expect(admin_customize_themes_page).to have_themes(count: 11)
|
|
|
|
|
|
|
|
admin_customize_themes_page.search("5")
|
|
|
|
expect(admin_customize_themes_page).to have_themes(count: 1)
|
|
|
|
|
|
|
|
admin_customize_themes_page.switch_to_themes
|
|
|
|
expect(admin_customize_themes_page).to have_themes(count: 1)
|
|
|
|
end
|
2023-10-08 17:35:53 -04:00
|
|
|
end
|
|
|
|
|
2023-11-07 22:42:27 -05:00
|
|
|
describe "when visiting the page to customize a single theme" do
|
2022-12-07 19:38:36 -05:00
|
|
|
it "should allow admin to update the color scheme of the theme" do
|
|
|
|
visit("/admin/customize/themes/#{theme.id}")
|
|
|
|
|
|
|
|
color_scheme_settings = find(".theme-settings__color-scheme")
|
|
|
|
|
|
|
|
expect(color_scheme_settings).not_to have_css(".submit-edit")
|
|
|
|
expect(color_scheme_settings).not_to have_css(".cancel-edit")
|
|
|
|
|
|
|
|
color_scheme_settings.find(".color-palettes").click
|
|
|
|
color_scheme_settings.find(".color-palettes-row[data-value='#{color_scheme.id}']").click
|
|
|
|
color_scheme_settings.find(".submit-edit").click
|
|
|
|
|
|
|
|
expect(color_scheme_settings.find(".setting-value")).to have_content(color_scheme.name)
|
|
|
|
expect(color_scheme_settings).not_to have_css(".submit-edit")
|
|
|
|
expect(color_scheme_settings).not_to have_css(".cancel-edit")
|
|
|
|
end
|
|
|
|
end
|
2023-04-24 10:30:51 -04:00
|
|
|
|
|
|
|
describe "when editing a local theme" do
|
|
|
|
it "The saved value is present in the editor" do
|
|
|
|
theme.set_field(target: "common", name: "head_tag", value: "console.log('test')", type_id: 0)
|
|
|
|
theme.save!
|
|
|
|
|
|
|
|
visit("/admin/customize/themes/#{theme.id}/common/head_tag/edit")
|
|
|
|
|
|
|
|
ace_content = find(".ace_content")
|
|
|
|
expect(ace_content.text).to eq("console.log('test')")
|
|
|
|
end
|
|
|
|
end
|
2024-03-18 12:00:28 -04:00
|
|
|
|
|
|
|
describe "when editing theme translations" do
|
|
|
|
it "should allow admin to edit and save the theme translations" do
|
|
|
|
theme.set_field(
|
|
|
|
target: :translations,
|
|
|
|
name: "en",
|
|
|
|
value: { en: { group: { hello: "Hello there!" } } }.deep_stringify_keys.to_yaml,
|
|
|
|
)
|
|
|
|
|
|
|
|
theme.save!
|
|
|
|
|
|
|
|
visit("/admin/customize/themes/#{theme.id}")
|
|
|
|
|
|
|
|
theme_translations_settings_editor =
|
|
|
|
PageObjects::Components::AdminThemeTranslationsSettingsEditor.new
|
|
|
|
|
|
|
|
theme_translations_settings_editor.fill_in("Hello World")
|
|
|
|
theme_translations_settings_editor.save
|
|
|
|
|
|
|
|
visit("/admin/customize/themes/#{theme.id}")
|
|
|
|
|
|
|
|
expect(theme_translations_settings_editor.get_input_value).to have_content("Hello World")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow admin to edit and save the theme translations from other languages" do
|
|
|
|
theme.set_field(
|
|
|
|
target: :translations,
|
|
|
|
name: "en",
|
|
|
|
value: { en: { group: { hello: "Hello there!" } } }.deep_stringify_keys.to_yaml,
|
|
|
|
)
|
|
|
|
theme.set_field(
|
|
|
|
target: :translations,
|
|
|
|
name: "fr",
|
|
|
|
value: { fr: { group: { hello: "Bonjour!" } } }.deep_stringify_keys.to_yaml,
|
|
|
|
)
|
|
|
|
theme.save!
|
|
|
|
|
|
|
|
visit("/admin/customize/themes/#{theme.id}")
|
|
|
|
|
|
|
|
theme_translations_settings_editor =
|
|
|
|
PageObjects::Components::AdminThemeTranslationsSettingsEditor.new
|
|
|
|
expect(theme_translations_settings_editor.get_input_value).to have_content("Hello there!")
|
|
|
|
|
|
|
|
theme_translations_picker = PageObjects::Components::SelectKit.new(".translation-selector")
|
|
|
|
theme_translations_picker.select_row_by_value("fr")
|
|
|
|
|
|
|
|
expect(theme_translations_settings_editor.get_input_value).to have_content("Bonjour!")
|
|
|
|
|
|
|
|
theme_translations_settings_editor.fill_in("Hello World in French")
|
|
|
|
theme_translations_settings_editor.save
|
|
|
|
end
|
2024-04-19 13:23:27 -04:00
|
|
|
|
|
|
|
it "should match the current user locale translation" do
|
|
|
|
SiteSetting.allow_user_locale = true
|
|
|
|
SiteSetting.set_locale_from_accept_language_header = true
|
|
|
|
SiteSetting.default_locale = "fr"
|
|
|
|
|
|
|
|
theme.set_field(
|
|
|
|
target: :translations,
|
|
|
|
name: "en",
|
|
|
|
value: { en: { group: { hello: "Hello there!" } } }.deep_stringify_keys.to_yaml,
|
|
|
|
)
|
|
|
|
theme.set_field(
|
|
|
|
target: :translations,
|
|
|
|
name: "fr",
|
|
|
|
value: { fr: { group: { hello: "Bonjour!" } } }.deep_stringify_keys.to_yaml,
|
|
|
|
)
|
|
|
|
theme.save!
|
|
|
|
|
|
|
|
visit("/admin/customize/themes/#{theme.id}")
|
|
|
|
|
|
|
|
theme_translations_settings_editor =
|
|
|
|
PageObjects::Components::AdminThemeTranslationsSettingsEditor.new
|
|
|
|
|
|
|
|
expect(theme_translations_settings_editor.get_input_value).to have_content("Hello there!")
|
|
|
|
|
|
|
|
theme_translations_picker = PageObjects::Components::SelectKit.new(".translation-selector")
|
|
|
|
expect(theme_translations_picker.component.text).to eq("English (US)")
|
|
|
|
end
|
2024-03-18 12:00:28 -04:00
|
|
|
end
|
2022-12-07 19:38:36 -05:00
|
|
|
end
|