A platform for community discussion. Free, open, simple.
FIX: Remove default val for colors step if a default theme has been set.
Guo Xiang Tan4e91839c979f
diff --git a/app/models/color_scheme.rb b/app/models/color_scheme.rbindex d954c0b0811..151f8c353f8 100644--- a/app/models/color_scheme.rb+++ b/app/models/color_scheme.rb@@ -101,6 +101,8 @@ class ColorScheme < ActiveRecord::Base# rubocop:enable Layout/AlignHash+ LIGHT_THEME_ID = 'Light'+def self.base_color_scheme_colorsbase_with_hash = {}@@ -109,7 +111,7 @@ class ColorScheme < ActiveRecord::Baseendlist = [- { id: 'Light', colors: base_with_hash }+ { id: LIGHT_THEME_ID, colors: base_with_hash }]CUSTOM_SCHEMES.each do |k, v|diff --git a/lib/wizard/builder.rb b/lib/wizard/builder.rbindex 55e12bd70cd..c43af1f3369 100644--- a/lib/wizard/builder.rb+++ b/lib/wizard/builder.rb@@ -147,9 +147,22 @@ class Wizard@wizard.append_step('colors') do |step|default_theme = Theme.find_by(id: SiteSetting.default_theme_id)- scheme_id = default_theme&.color_scheme&.base_scheme_id || 'Light'+ default_theme_override = SiteSetting.exists?(name: "default_theme_id")++ scheme_id =+ if default_theme_override+ default_theme&.color_scheme&.base_scheme_id+ else+ ColorScheme::LIGHT_THEME_ID+ end++ themes = step.add_field(+ id: 'theme_previews',+ type: 'component',+ required: !default_theme_override,+ value: scheme_id+ )- themes = step.add_field(id: 'theme_previews', type: 'component', required: true, value: scheme_id)ColorScheme.base_color_scheme_colors.each do |t|with_hash = t[:colors].dupwith_hash.map { |k, v| with_hash[k] = "##{v}" }@@ -157,7 +170,13 @@ class Wizardendstep.on_update do |updater|- scheme_name = updater.fields[:theme_previews] || 'Light'+ scheme_name = (+ (updater.fields[:theme_previews] || "") ||+ ColorScheme::LIGHT_THEME_ID+ )++ next unless scheme_name.present?+name = I18n.t("color_schemes.#{scheme_name.downcase.gsub(' ', '_')}_theme_name")theme = nildiff --git a/spec/components/wizard/step_updater_spec.rb b/spec/components/wizard/step_updater_spec.rbindex 81e2dbca189..cc333267025 100644--- a/spec/components/wizard/step_updater_spec.rb+++ b/spec/components/wizard/step_updater_spec.rb@@ -183,6 +183,20 @@ describe Wizard::StepUpdater doendend+ context "with an existing default theme" do+ fab!(:theme) { Fabricate(:theme) }++ before do+ theme.set_default!+ end++ it "should not update the default theme when no option has been selected" do+ expect do+ wizard.create_updater('colors', {}).update+ end.to_not change { SiteSetting.default_theme_id }+ end+ end+context "without an existing theme" dobefore doTheme.delete_all@@ -203,14 +217,19 @@ describe Wizard::StepUpdater docontext 'light theme' doit "creates the theme" do- updater = wizard.create_updater('colors', {})+ updater = wizard.create_updater('colors',+ theme_previews: ColorScheme::LIGHT_THEME_ID+ )expect { updater.update }.to change { Theme.count }.by(1)theme = Theme.lastexpect(theme.user_id).to eq(wizard.user.id)- expect(theme.color_scheme).to eq(ColorScheme.find_by(name: 'Light'))++ expect(theme.color_scheme).to eq(ColorScheme.find_by(name:+ ColorScheme::LIGHT_THEME_ID+ ))endendenddiff --git a/spec/components/wizard/wizard_builder_spec.rb b/spec/components/wizard/wizard_builder_spec.rbindex 7d0ed2f239b..22230819e25 100644--- a/spec/components/wizard/wizard_builder_spec.rb+++ b/spec/components/wizard/wizard_builder_spec.rb@@ -145,4 +145,32 @@ describe Wizard::Builder doexpect(login_required_field.id).to eq('privacy')endend++ context "colors step" do+ fab!(:theme) { Fabricate(:theme) }+ let(:colors_step) { wizard.steps.find { |s| s.id == 'colors' } }+ let(:field) { colors_step.fields.first }++ describe "when the default theme has not been override" do+ before do+ SiteSetting.find_by(name: "default_theme_id").destroy!+ end++ it 'should set the right default values' do+ expect(field.required).to eq(true)+ expect(field.value).to eq(ColorScheme::LIGHT_THEME_ID)+ end+ end++ describe "when the default them hass been override" do+ before do+ theme.set_default!+ end++ it 'should set the right default values' do+ expect(field.required).to eq(false)+ expect(field.value).to eq(nil)+ end+ end+ endend