A platform for community discussion. Free, open, simple.
# frozen_string_literal: true
module PageObjects
module Pages
class AdminCustomizeThemesConfigArea < PageObjects::Pages::Base
def visit(query_params = {})
page.visit("/admin/config/customize?#{query_params.to_query}")
self
end
def find_theme_card(theme)
find(".theme-card.#{theme.name.parameterize}")
end
def subheader
find(".d-page-subheader")
end
def open_theme_menu(theme)
find_theme_card(theme).find(".theme-card__footer-menu-trigger").click
end
def mark_as_default(theme)
open_theme_menu(theme)
find(".set-default").click
expect(page).to have_css(
"meta[name=discourse_theme_id][content='#{theme.id}']",
visible: false, # wait for reload
)
end
def delete_theme(theme)
open_theme_menu(theme)
find(".delete").click
confirmation_dialog = PageObjects::Components::Dialog.new
confirmation_dialog.click_danger
expect(confirmation_dialog).to be_closed
end
def has_default_badge?(theme)
has_badge?(theme, "--default", text: I18n.t("admin_js.admin.customize.theme.default"))
end
def has_no_default_badge?(theme)
has_no_badge?(theme, "--default")
end
def has_badge?(theme, badge, **kwargs)
find_theme_card(theme).has_css?(".theme-card__badge.#{badge}", **kwargs)
end
def has_no_badge?(theme, badge)
find_theme_card(theme).has_no_css?(".theme-card__badge.#{badge}")
end
def has_disabled_delete_button?(theme)
open_theme_menu(theme)
has_css?(".--danger.delete[disabled]")
end
def has_themes?(names)
expect(all(".theme-card__title").map(&:text)).to eq(names)
end
def has_theme_cards?(count:)
has_css?(".themes-cards-container > .admin-config-area-card", count: count)
end
def has_theme_named?(name)
has_css?(".theme-card.#{name.parameterize}")
end
def has_install_more_themes_card?
has_css?(
".theme-card.--install-more",
text: I18n.t("admin_js.admin.customize.theme.install_more_themes"),
)
end
def click_install_more_themes
find(".theme-card.--install-more").click_button(
I18n.t("admin_js.admin.config_areas.themes_and_components.themes.install"),
)
PageObjects::Modals::InstallTheme.new
end
def has_no_theme?(name)
has_no_css?(".theme-card.#{name.parameterize}")
end
def toggle_selectable(theme)
open_theme_menu(theme)
find(".set-selectable").click
end
def click_edit(theme)
find_theme_card(theme).find(".edit").click
end
def click_edit_by_name(name)
find(".theme-card.#{name.parameterize}").find(".edit").click
end
def click_install_button
PageObjects::Components::AdminCustomizeThemeInstallButton.new.click
end
def screenshot_toggle_button(theme)
find_theme_card(theme).find(".theme-card-preview__screenshot-toggle")
end
def has_screenshot_toggle_button?(theme)
find_theme_card(theme).has_css?(".theme-card-preview__screenshot-toggle")
end
def has_no_screenshot_toggle_button?(theme)
find_theme_card(theme).has_no_css?(".theme-card-preview__screenshot-toggle")
end
def click_screenshot_toggle(theme)
find_theme_card(theme).hover
screenshot_toggle_button(theme).click
end
def screenshot_image(theme)
find_theme_card(theme).find(".theme-card-preview__image")
end
def has_screenshot_with_icon?(theme, icon_name)
find_theme_card(theme).hover
find_theme_card(theme).has_css?(
".theme-card-preview__screenshot-toggle .d-icon-#{icon_name}",
)
end
end
end
end