FIX: Remove default val for colors step if a default theme has been set.

FIX: Remove default val for colors step if a default theme has been set.

Running through the wizard after a default theme has been configured will always revert the default theme to the light theme.

diff --git a/app/models/color_scheme.rb b/app/models/color_scheme.rb
index d954c0b..151f8c3 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_colors
     base_with_hash = {}
 
@@ -109,7 +111,7 @@ class ColorScheme < ActiveRecord::Base
     end
 
     list = [
-      { 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.rb
index 55e12bd..c43af1f 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].dup
           with_hash.map { |k, v| with_hash[k] = "##{v}" }
@@ -157,7 +170,13 @@ class Wizard
         end
 
         step.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 = nil
diff --git a/spec/components/wizard/step_updater_spec.rb b/spec/components/wizard/step_updater_spec.rb
index 81e2dbc..cc33326 100644
--- a/spec/components/wizard/step_updater_spec.rb
+++ b/spec/components/wizard/step_updater_spec.rb
@@ -183,6 +183,20 @@ describe Wizard::StepUpdater do
       end
     end
 
+    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" do
       before do
         Theme.delete_all
@@ -203,14 +217,19 @@ describe Wizard::StepUpdater do
 
       context 'light theme' do
         it "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.last
 
           expect(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
+          ))
         end
       end
     end
diff --git a/spec/components/wizard/wizard_builder_spec.rb b/spec/components/wizard/wizard_builder_spec.rb
index 7d0ed2f..2223081 100644
--- a/spec/components/wizard/wizard_builder_spec.rb
+++ b/spec/components/wizard/wizard_builder_spec.rb
@@ -145,4 +145,32 @@ describe Wizard::Builder do
       expect(login_required_field.id).to eq('privacy')
     end
   end
+
+  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
+  end
 end

GitHub sha: 4e91839c