From c79eec7fdc7293f4ea67c5beaefc9068fa7c8b3e Mon Sep 17 00:00:00 2001
From: Alan Guo Xiang Tan <gxtan1990@gmail.com>
Date: Thu, 8 Dec 2022 08:38:36 +0800
Subject: [PATCH] DEV: Add system test for updating color scheme of a theme
 (#19370)

Follow-up to 63119144ff481b1a18b69c0d638ece1b03c54766
---
 .../addon/templates/customize-themes-show.hbs |  4 ++-
 spec/system/admin_customize_themes_spec.rb    | 32 +++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 spec/system/admin_customize_themes_spec.rb

diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-show.hbs b/app/assets/javascripts/admin/addon/templates/customize-themes-show.hbs
index 4fa8ebe52dc..d4a62121f73 100644
--- a/app/assets/javascripts/admin/addon/templates/customize-themes-show.hbs
+++ b/app/assets/javascripts/admin/addon/templates/customize-themes-show.hbs
@@ -173,11 +173,12 @@
     {{/if}}
 
     {{#unless this.model.component}}
-      <DSection @class="form-horizontal theme settings control-unit">
+      <DSection @class="form-horizontal theme settings control-unit theme-settings__color-scheme">
         <div class="row setting">
           <div class="setting-label">
             {{i18n "admin.customize.theme.color_scheme"}}
           </div>
+
           <div class="setting-value">
             <ColorPalettes @content={{this.colorSchemes}} @value={{this.colorSchemeId}} @icon="paint-brush" @options={{hash
                 filterable=true
@@ -185,6 +186,7 @@
 
             <div class="desc">{{i18n "admin.customize.theme.color_scheme_select"}}</div>
           </div>
+
           <div class="setting-controls">
             {{#if this.colorSchemeChanged}}
               <DButton @action={{action "changeScheme"}} @class="ok submit-edit" @icon="check" />
diff --git a/spec/system/admin_customize_themes_spec.rb b/spec/system/admin_customize_themes_spec.rb
new file mode 100644
index 00000000000..d74e9acdfd6
--- /dev/null
+++ b/spec/system/admin_customize_themes_spec.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+describe 'Admin Customize Themes', type: :system, js: true do
+  fab!(:color_scheme) { Fabricate(:color_scheme) }
+  fab!(:theme) { Fabricate(:theme) }
+  fab!(:admin) { Fabricate(:admin) }
+
+  before do
+    sign_in(admin)
+  end
+
+  describe 'when visiting the page to customize the theme' do
+    it 'should allow admin to update the color scheme of the theme' do
+      visit("/admin/customize/themes/#{theme.id}")
+
+      color_scheme_settings = find(".theme-settings__color-scheme")
+
+      expect(color_scheme_settings).not_to have_css(".submit-edit")
+      expect(color_scheme_settings).not_to have_css(".cancel-edit")
+
+      color_scheme_settings.find(".color-palettes").click
+      color_scheme_settings.find(".color-palettes-row[data-value='#{color_scheme.id}']").click
+      color_scheme_settings.find(".submit-edit").click
+
+      expect(color_scheme_settings.find('.setting-value')).to have_content(color_scheme.name)
+      expect(color_scheme_settings).not_to have_css(".submit-edit")
+      expect(color_scheme_settings).not_to have_css(".cancel-edit")
+
+      expect(theme.reload.color_scheme_id).to eq(color_scheme.id)
+    end
+  end
+end