discourse/spec/system/page_objects/pages/admin_customize_themes.rb
Gabriel Grubba 6800d63bfc
FIX: type object setting not redirecting on saving (#36150)
With https://github.com/discourse/discourse/pull/35349, now site
settings do not return a body on update, which broke the type object
setting editor's save flow. This commit adds handling for that case.

And also adds testing to ensure that after saving the setting, we are
redirected to another page.

Renamed `admin_objects_theme_setting_editor` to
`admin_objects_setting_editor` since it can be used for both themes and
settings.


Before:


https://github.com/user-attachments/assets/5e019428-e126-4084-80a6-eb324c851427


Now:


https://github.com/user-attachments/assets/9ac59ca2-1896-490a-866c-630a5a201471

A future todo would be to migrate [ThemeController#update_single_setting
](71834c898f/app/controllers/admin/themes_controller.rb (L343-L365))
to use the same pattern as
[`SiteSettingController#update`](d8e7741d96/app/controllers/admin/site_settings_controller.rb (L25-L53))
2025-11-21 10:26:08 -03:00

262 lines
7.5 KiB
Ruby

# frozen_string_literal: true
module PageObjects
module Pages
class AdminCustomizeThemes < PageObjects::Pages::AdminBase
def visit(theme_or_theme_id)
page.visit(
"/admin/customize/themes/#{theme_or_theme_id.is_a?(Theme) ? theme_or_theme_id.id : theme_or_theme_id}",
)
self
end
def has_colors_tab?
header.has_tab?("colors")
end
def has_colors_tab_active?
header.has_active_tab?("colors")
end
def has_no_colors_tab?
header.has_no_tab?("colors")
end
def colors_tab
header.tab("colors")
end
def has_settings_tab?
header.has_tab?("settings")
end
def has_no_settings_tab?
header.has_no_tab?("settings")
end
def settings_tab
header.tab("settings")
end
def changes_banner
PageObjects::Components::AdminChangesBanner.new
end
def has_color_scheme_selector?
page.has_css?(".theme-settings__color-scheme")
end
def has_no_color_scheme_selector?
page.has_no_css?(".theme-settings__color-scheme")
end
def color_palette_editor
PageObjects::Components::ColorPaletteEditor.new(page.find(".color-palette-editor"))
end
def palette_editor_save_button
page.find(".admin-theme__save-palette-changes")
end
def has_palette_editor_save_button?
page.has_css?(".admin-theme__save-palette-changes")
end
def has_no_palette_editor_save_button?
page.has_no_css?(".admin-theme__save-palette-changes")
end
def palette_editor_discard_button
page.find(".admin-theme__discard-palette-changes")
end
def has_palette_editor_discard_button?
page.has_css?(".admin-theme__discard-palette-changes")
end
def has_no_palette_editor_discard_button?
page.has_no_css?(".admin-theme__discard-palette-changes")
end
def has_inactive_themes?
has_css?(".inactive-indicator")
end
def has_no_inactive_themes?
has_no_css?(".inactive-indicator")
end
def has_select_inactive_mode_button?
has_css?(".select-inactive-mode")
end
def has_overridden_setting?(setting_name)
has_css?(setting_selector(setting_name, overridden: true))
end
def has_no_overriden_setting?(setting_name)
has_no_css?(setting_selector(setting_name, overridden: true))
end
def has_setting_description?(setting_name, description)
has_css?("#{setting_selector(setting_name)} .desc", exact_text: description)
end
def has_theme_site_setting?(setting_name)
find(theme_site_setting_selector(setting_name)).has_css?(
".setting-label",
text: SiteSetting.humanized_name(setting_name),
)
find(theme_site_setting_selector(setting_name)).has_css?(
".setting-value",
text: SiteSetting.description(setting_name),
)
end
def has_overridden_theme_site_setting?(setting_name)
has_css?(theme_site_setting_selector(setting_name, overridden: true))
end
def has_no_overridden_theme_site_setting?(setting_name)
has_no_css?(theme_site_setting_selector(setting_name, overridden: true))
end
def toggle_theme_site_setting(setting_name)
find(theme_site_setting_selector(setting_name)).find(
".setting-value input[type='checkbox']",
).click
find(theme_site_setting_selector(setting_name)).find(".setting-controls .ok").click
end
def reset_overridden_theme_site_setting(setting_name)
find(theme_site_setting_selector(setting_name, overridden: true)).find(
".setting-controls__undo",
).click
find(theme_site_setting_selector(setting_name)).find(".setting-controls .ok").click
end
def has_no_themes_list?
has_no_css?(".themes-list-header")
end
def has_back_button_to_themes_page?
has_css?(
'.back-to-themes-and-components a[href="/admin/config/customize/themes"]',
text: I18n.t("admin_js.admin.config_areas.themes_and_components.themes.back"),
)
end
def click_back_to_themes
find(".back-to-themes-and-components a").click
end
def has_back_button_to_components_page?
has_css?(
'.back-to-themes-and-components a[href="/admin/config/customize/components"]',
text: I18n.t("admin_js.admin.config_areas.themes_and_components.components.back"),
)
end
def click_add_all_themes_button
find(".relative-theme-selector .setting-label .btn-link").click
find(".setting-controls .ok").click
end
def has_no_page_header?
has_no_css?(".d-page-header")
end
def reset_overridden_setting(setting_name)
setting_section = find("section.theme.settings .setting[data-setting=\"#{setting_name}\"]")
setting_section.click_button(I18n.t("admin_js.admin.settings.reset"))
setting_section.find(".setting-controls .ok").click
end
def click_select_inactive_mode
find(".select-inactive-mode").click
end
def cancel_select_inactive_mode
find(".cancel-select-inactive-mode").click
end
def has_inactive_themes_selected?(count:)
has_css?(".inactive-theme input:checked", count: count)
end
def has_themes?(count:)
has_css?(".themes-list-container__item", count: count)
end
def toggle_all_inactive
find(".toggle-all-inactive").click
end
def has_disabled_delete_theme_button?
find_button("Delete", disabled: true)
end
def click_delete_button_and_confirm
find(".delete").click
PageObjects::Components::Dialog.new.click_danger
self
end
def click_edit_objects_setting_button(setting_name)
find(".theme-setting[data-setting=\"#{setting_name}\"] .setting-value-edit-button").click
PageObjects::Pages::AdminObjectsSettingEditor.new
end
def click_theme_settings_editor_button
click_button(I18n.t("admin_js.admin.customize.theme.settings_editor"))
PageObjects::Components::AdminThemeSettingsEditor.new.opened?
end
def switch_to_components
find(".components-tab").click
end
def switch_to_themes
find(".themes-tab").click
end
def search(term)
find(".themes-list-search__input").fill_in with: term
end
def has_no_search?
has_no_css?(".themes-list-search__input")
end
def click_delete
find(".theme-controls .btn-danger").click
end
def confirm_delete
find(".dialog-footer .btn-danger").click
end
def included_components_selector
PageObjects::Components::SelectKit.new(".included-components-setting .select-kit")
end
def relative_themes_save_button
find(".relative-theme-selector .setting-controls__ok")
end
def has_reset_button_for_setting?(css_selector)
has_css?("#{css_selector} .setting-controls__undo")
end
private
def setting_selector(setting_name, overridden: false)
"section.theme.settings .setting#{overridden ? ".overridden" : ""}[data-setting=\"#{setting_name}\"]"
end
def theme_site_setting_selector(setting_name, overridden: false)
"section.theme.theme-site-settings .setting#{overridden ? ".overridden" : ""}.theme-site-setting[data-setting=\"#{setting_name}\"]"
end
end
end
end