From ab11cb92eafe14182361eed729792d8fafecf177 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Mon, 9 Dec 2024 17:09:17 +1000 Subject: [PATCH] DEV: Add system spec for styling step --- .../wizard-fields-dropdown-test.gjs | 2 +- app/models/theme.rb | 4 ++ lib/wizard/builder.rb | 2 +- spec/system/page_objects/pages/wizard.rb | 51 +++++++++++++++++++ spec/system/wizard_spec.rb | 31 ++++++++++- 5 files changed, 87 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/integration/components/wizard-fields-dropdown-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/wizard-fields-dropdown-test.gjs index 5806f06c6c8..e0598aa90d5 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/wizard-fields-dropdown-test.gjs +++ b/app/assets/javascripts/discourse/tests/integration/components/wizard-fields-dropdown-test.gjs @@ -1,4 +1,4 @@ -import { click, render } from "@ember/test-helpers"; +import { render } from "@ember/test-helpers"; import { module, test } from "qunit"; import Dropdown from "discourse/static/wizard/components/fields/dropdown"; import { Choice, Field } from "discourse/static/wizard/models/wizard"; diff --git a/app/models/theme.rb b/app/models/theme.rb index a95d88ee547..b2fc9129fad 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -372,6 +372,10 @@ class Theme < ActiveRecord::Base end end + def self.find_default + find_by(id: SiteSetting.default_theme_id) + end + def self.lookup_field(theme_id, target, field, skip_transformation: false, csp_nonce: nil) return "" if theme_id.blank? diff --git a/lib/wizard/builder.rb b/lib/wizard/builder.rb index 102fb6f9051..45d2d5729b9 100644 --- a/lib/wizard/builder.rb +++ b/lib/wizard/builder.rb @@ -137,7 +137,7 @@ class Wizard def append_styling_step @wizard.append_step("styling") do |step| step.emoji = "art" - default_theme = Theme.find_by(id: SiteSetting.default_theme_id) + default_theme = Theme.find_default default_theme_override = SiteSetting.exists?(name: "default_theme_id") base_scheme = default_theme&.color_scheme&.base_scheme_id diff --git a/spec/system/page_objects/pages/wizard.rb b/spec/system/page_objects/pages/wizard.rb index f79368a031c..c97db0853cb 100644 --- a/spec/system/page_objects/pages/wizard.rb +++ b/spec/system/page_objects/pages/wizard.rb @@ -82,6 +82,57 @@ class PageObjects::Pages::Wizard::BrandingStep < PageObjects::Pages::Wizard::Ste end class PageObjects::Pages::Wizard::StylingStep < PageObjects::Pages::Wizard::StepBase + def select_color_palette_option(palette) + select_kit = + PageObjects::Components::SelectKit.new(".dropdown-color-scheme .wizard-container__dropdown") + select_kit.expand + select_kit.select_row_by_value(palette) + end + + def select_body_font_option(font) + select_kit = + PageObjects::Components::SelectKit.new(".dropdown-body-font .wizard-container__dropdown") + select_kit.expand + select_kit.select_row_by_value(font) + end + + def select_heading_font_option(font) + select_kit = + PageObjects::Components::SelectKit.new(".dropdown-heading-font .wizard-container__dropdown") + select_kit.expand + select_kit.select_row_by_value(font) + end + + def select_homepage_style_option(homepage) + select_kit = + PageObjects::Components::SelectKit.new(".dropdown-homepage-style .wizard-container__dropdown") + select_kit.expand + select_kit.select_row_by_value(homepage) + end + + def has_selected_color_palette?(palette) + select_kit = + PageObjects::Components::SelectKit.new(".dropdown-color-scheme .wizard-container__dropdown") + select_kit.has_selected_value?(palette) + end + + def has_selected_body_font?(font) + select_kit = + PageObjects::Components::SelectKit.new(".dropdown-body-font .wizard-container__dropdown") + select_kit.has_selected_value?(font) + end + + def has_selected_heading_font?(font) + select_kit = + PageObjects::Components::SelectKit.new(".dropdown-heading-font .wizard-container__dropdown") + select_kit.has_selected_value?(font) + end + + def has_selected_homepage_style?(hompage) + select_kit = + PageObjects::Components::SelectKit.new(".dropdown-homepage-style .wizard-container__dropdown") + select_kit.has_selected_value?(hompage) + end end class PageObjects::Pages::Wizard::CorporateStep < PageObjects::Pages::Wizard::StepBase diff --git a/spec/system/wizard_spec.rb b/spec/system/wizard_spec.rb index ce9989d2650..73bf70afa62 100644 --- a/spec/system/wizard_spec.rb +++ b/spec/system/wizard_spec.rb @@ -66,10 +66,32 @@ describe "Wizard", type: :system do it "lets user configure styling including fonts and colors" do wizard_page.go_to_step("styling") expect(wizard_page).to be_on_step("styling") + + wizard_page.styling_step.select_color_palette_option("Dark") + wizard_page.styling_step.select_body_font_option("lato") + wizard_page.styling_step.select_heading_font_option("merriweather") + wizard_page.styling_step.select_homepage_style_option("categories_only") + + wizard_page.go_to_next_step + expect(wizard_page).to be_on_step("ready") + + expect(Theme.find_default.color_scheme_id).to eq( + ColorScheme.find_by(base_scheme_id: "Dark", via_wizard: true).id, + ) + expect(SiteSetting.base_font).to eq("lato") + expect(SiteSetting.heading_font).to eq("merriweather") + expect(SiteSetting.homepage).to eq("categories") + + wizard_page.go_to_step("styling") + + expect(wizard_page.styling_step).to have_selected_color_palette("Dark") + expect(wizard_page.styling_step).to have_selected_body_font("lato") + expect(wizard_page.styling_step).to have_selected_heading_font("merriweather") + expect(wizard_page.styling_step).to have_selected_homepage_style("categories_only") end end - context "when wizard is completed" do + describe "Wizard Step: Ready" do it "redirects to latest" do wizard_page.go_to_step("ready") wizard_page.click_jump_in @@ -88,4 +110,11 @@ describe "Wizard", type: :system do expect(page).to have_current_path(topic.url) end end + + describe "Wizard Step: Corporate" do + it "lets user configure corporate including governing law and city for disputes" do + wizard_page.go_to_step("corporate") + expect(wizard_page).to be_on_step("corporate") + end + end end