0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-12 03:37:13 +08:00
discourse/spec/system/page_objects/components/design_wizard_panel.rb
Keegan George 9866827083
DEV: Code review and fixes
- Don't fire the onboarding step's completion callback against a destroyed
  component. Previewing a homepage routes away from the banner, so the step
  hands its callback back on teardown and the service falls back to writing
  the store key and audit event itself.
- Make the collapsed banner's "x of 3 steps completed" count reactive. It was
  reading the key value store, which doesn't trigger a re-render.
- Stop memoizing a font stack probed before the stylesheet that defines the
  font classes has loaded, which pinned the wrong font for the page's lifetime.
- Add the missing `start_posting.completed` label, which rendered as a raw
  i18n key once the step was done, plus an integrity spec so a step can't ship
  without both labels. Sentence case for the other two step titles.
- Collapse the eight site setting steps in DesignWizard::Apply into one that
  iterates the hash the contract already builds.
- Move the wizard's stylesheet link handling into color-scheme-manager so all
  the light/dark link knowledge lives in one place.
- Give the step dots their own class instead of borrowing the image carousel's,
  and put the panel on its own z-layer below modals so dialogs behind it stay
  reachable.
- Dock the panel to the bottom edge on narrow viewports. A full height side
  rail covered the page it's meant to be previewing.
- Pull the hardcoded base-light values in design-wizard.scss into named
  variables so each one is declared once.
- Drop the dead --design-wizard-chrome-font-size plumbing.
- Note why update_palette_selectability resets everything and why update_all
  is safe there.
- Tests: specs for PalettePairs and ResolvePalette, the user selectable palette
  toggle in both directions, a failed progress save, and the case where there
  are no palettes to offer. Fixed a viewport assertion that couldn't fail and
  a link cleanup that leaked between tests.
2026-08-06 11:41:03 -07:00

113 lines
2.9 KiB
Ruby
Vendored

# frozen_string_literal: true
module PageObjects
module Components
class DesignWizardPanel < PageObjects::Components::Base
WIZARD_SELECTOR = ".design-wizard"
def visible?
has_css?(WIZARD_SELECTOR)
end
def hidden?
has_no_css?(WIZARD_SELECTOR)
end
def has_site_sidebar?
has_css?(".sidebar-sections")
end
def select_theme(theme_id)
find("#{WIZARD_SELECTOR}__theme-card[data-theme-id='#{theme_id}']").click
end
def has_selected_theme?(theme)
has_css?(
"#{WIZARD_SELECTOR}__theme-card[data-theme-id='#{theme.id}'] input[type='radio']:checked",
)
end
def has_no_selected_theme?
has_no_css?("#{WIZARD_SELECTOR}__theme-card input[type='radio']:checked")
end
def has_disabled_next?
has_css?("#{WIZARD_SELECTOR}__next[disabled]")
end
def select_palette(pair_key)
find("#{WIZARD_SELECTOR}__swatch[data-pair-key='#{pair_key}']").click
end
def toggle_user_selectable_palettes
user_selectable_switch.toggle
end
def has_user_selectable_palettes?
user_selectable_switch.checked?
end
def has_no_user_selectable_palettes?
user_selectable_switch.unchecked?
end
def select_homepage(key)
find("#{WIZARD_SELECTOR}__homepage-card[data-homepage='#{key}']").click
end
def select_body_font(font_key)
groups = all("#{WIZARD_SELECTOR}__font-group")
groups[0].find("#{WIZARD_SELECTOR}__font-select").click
find(
"[data-identifier='design-wizard-base-font'] .btn.body-font-#{font_key.tr("_", "-")}",
).click
end
def has_palette_preview?
has_css?("link[data-scheme-id]", visible: :all)
end
def has_no_palette_preview?
has_no_css?("link[data-scheme-id]", visible: :all)
end
def layout_dimensions
rect = find(WIZARD_SELECTOR).evaluate_script(<<~JS)
(() => {
const { width, top, bottom } = this.getBoundingClientRect();
return { width, top, bottom };
})()
JS
{
panel_width: rect["width"],
panel_top: rect["top"],
panel_bottom: rect["bottom"],
viewport_width: page.evaluate_script("window.innerWidth"),
viewport_height: page.evaluate_script("window.innerHeight"),
document_scroll_width: page.evaluate_script("document.documentElement.scrollWidth"),
}
end
def next_step
find("#{WIZARD_SELECTOR}__next").click
end
def save
find("#{WIZARD_SELECTOR}__save").click
end
def close
find("#{WIZARD_SELECTOR}__close").click
end
private
def user_selectable_switch
PageObjects::Components::DToggleSwitch.new(
"#{WIZARD_SELECTOR}__user-selectable [role='switch']",
)
end
end
end
end