DEV: Experimenting with using built in core color palettes for the color picking component (#71)
This PR is the beginning of converting the color picker to use built in core color palettes. The `color_schemes` defined in `about.json` are created in core when the theme is imported, and we then show all user-selectable color palettes in this sidebar footer menu. An important caveat here is that all of the Horizon themes must be changed to `user_selectable` otherwise they will not show up in the color palette selector in the sidebar. When choosing a color palette that also has a corresponding dark color palette, *both* light mode and dark mode are correctly saved with the color palette(s) chosen, using the color palette cookie we already have in core. Anon users can also set a palette, which will be saved in a cookie. --------- Co-authored-by: Sérgio Saquetim <saquetim@discourse.org> Co-authored-by: Martin Brennan <martin@discourse.org> Co-authored-by: Osama Sayegh <asooomaasoooma90@gmail.com>
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "./page_objects/components/user_color_palette_selector"
|
||||
|
||||
describe "Horizon theme | High level", type: :system do
|
||||
let!(:theme) { upload_theme }
|
||||
let!(:theme) do
|
||||
horizon_theme = upload_theme
|
||||
ColorScheme
|
||||
.where(theme_id: horizon_theme.id)
|
||||
.where.not("name LIKE '%Dark%'")
|
||||
.update_all(user_selectable: true)
|
||||
horizon_theme
|
||||
end
|
||||
fab!(:current_user) { Fabricate(:user) }
|
||||
fab!(:tag_1) { Fabricate(:tag, name: "wow-cool") }
|
||||
fab!(:tag_2) { Fabricate(:tag, name: "another-tag") }
|
||||
@@ -10,6 +19,7 @@ describe "Horizon theme | High level", type: :system do
|
||||
let(:topic_list) { PageObjects::Components::TopicList.new }
|
||||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
|
||||
let(:palette_selector) { PageObjects::Components::UserColorPaletteSelector.new }
|
||||
|
||||
def run_all_high_level_tests
|
||||
expect(page).to have_css(".experimental-screen")
|
||||
@@ -33,18 +43,20 @@ describe "Horizon theme | High level", type: :system do
|
||||
],
|
||||
)
|
||||
|
||||
# Can see a topic in the list and navigate to it successfully
|
||||
# Can see a topic in the list and navigate to it successfully.
|
||||
topic_list.visit_topic(topic_1)
|
||||
expect(topic_page).to have_topic_title(topic_1.title)
|
||||
|
||||
# Can change site colors from the sidebar palette, which are remembered across page reloads
|
||||
palette_menu =
|
||||
PageObjects::Components::DMenu.new(find(".sidebar-footer-actions .user-color-palette"))
|
||||
palette_menu.expand
|
||||
find(".color-palette-menu__content .color-palette-menu__item[data-color='marigold']").click
|
||||
expect(page).to have_css(".custom-color-marigold")
|
||||
# Can change site colors from the sidebar palette, which are remembered
|
||||
# across page reloads.
|
||||
marigold_palette = ColorScheme.find_by(name: "Marigold")
|
||||
palette_selector.open_palette_menu
|
||||
palette_selector.click_palette_menu_item(marigold_palette.name)
|
||||
expect(palette_selector).to have_no_palette_menu
|
||||
|
||||
page.refresh
|
||||
expect(page).to have_css(".custom-color-marigold")
|
||||
expect(palette_selector).to have_selected_palette(marigold_palette)
|
||||
expect(palette_selector).to have_tertiary_color(marigold_palette)
|
||||
end
|
||||
|
||||
it "works for anon" do
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PageObjects
|
||||
module Components
|
||||
class UserColorPaletteSelector < PageObjects::Components::Base
|
||||
def sidebar_footer_button_css
|
||||
".sidebar-footer-actions .user-color-palette-selector"
|
||||
end
|
||||
|
||||
def palette_menu
|
||||
PageObjects::Components::DMenu.new(find(sidebar_footer_button_css))
|
||||
end
|
||||
|
||||
def open_palette_menu
|
||||
palette_menu.expand
|
||||
end
|
||||
|
||||
def has_no_palette_menu?
|
||||
has_no_css?(".user-color-palette-selector-content")
|
||||
end
|
||||
|
||||
def click_palette_menu_item(palette_name)
|
||||
find(
|
||||
".user-color-palette-menu__content .user-color-palette-menu__item[data-color-palette='#{palette_name}']",
|
||||
).click
|
||||
end
|
||||
|
||||
def has_selected_palette?(palette)
|
||||
has_css?(".user-color-palette-selector[data-selected-color-palette-id='#{palette.id}']")
|
||||
end
|
||||
|
||||
def has_tertiary_color?(palette)
|
||||
computed_color_hex =
|
||||
page.evaluate_script(
|
||||
"getComputedStyle(document.documentElement).getPropertyValue('--tertiary')",
|
||||
)
|
||||
computed_color_hex == "#" + palette.colors.find { |color| color.name == "tertiary" }.hex
|
||||
end
|
||||
|
||||
def has_computed_color?(color)
|
||||
computed_background_color =
|
||||
page.evaluate_script(
|
||||
"getComputedStyle(document.querySelector(\"li.sidebar-section-link-wrapper[data-list-item-name='everything'] .active\")).backgroundColor",
|
||||
)
|
||||
computed_background_color == color
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,100 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "./page_objects/components/user_color_palette_selector"
|
||||
|
||||
describe "Horizon theme | User color palette selector", type: :system do
|
||||
let!(:theme) do
|
||||
horizon_theme = upload_theme
|
||||
ColorScheme.where(theme_id: horizon_theme.id).update_all(user_selectable: true)
|
||||
horizon_theme
|
||||
end
|
||||
fab!(:current_user) { Fabricate(:user) }
|
||||
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
|
||||
let(:palette_selector) { PageObjects::Components::UserColorPaletteSelector.new }
|
||||
let(:interface_color_mode) { PageObjects::Components::InterfaceColorMode.new }
|
||||
let(:interface_color_selector) do
|
||||
PageObjects::Components::InterfaceColorSelector.new(".sidebar-footer-actions")
|
||||
end
|
||||
let(:marigold_palette) { ColorScheme.find_by(name: "Marigold") }
|
||||
let(:marigold_palette_dark) { ColorScheme.find_by(name: "Marigold Dark") }
|
||||
|
||||
before { SiteSetting.interface_color_selector = "sidebar_footer" }
|
||||
|
||||
it "does not show the sidebar button if there are no user-selectable color palettes" do
|
||||
ColorScheme.update_all(user_selectable: false)
|
||||
visit "/"
|
||||
expect(page).to have_no_css(palette_selector.sidebar_footer_button_css)
|
||||
end
|
||||
|
||||
describe "for logged in user" do
|
||||
before { sign_in(current_user) }
|
||||
|
||||
it "can open the user color palette menu and select a palette, which is preseved on reload" do
|
||||
visit "/"
|
||||
palette_selector.open_palette_menu
|
||||
palette_selector.click_palette_menu_item(marigold_palette.name)
|
||||
expect(palette_selector).to have_no_palette_menu
|
||||
page.refresh
|
||||
|
||||
expect(palette_selector).to have_selected_palette(marigold_palette)
|
||||
expect(palette_selector).to have_tertiary_color(marigold_palette)
|
||||
|
||||
page.refresh
|
||||
expect(palette_selector).to have_selected_palette(marigold_palette)
|
||||
end
|
||||
|
||||
it "uses the dark version of the palette if the user selects dark mode" do
|
||||
visit "/"
|
||||
palette_selector.open_palette_menu
|
||||
palette_selector.click_palette_menu_item(marigold_palette.name)
|
||||
expect(palette_selector).to have_no_palette_menu
|
||||
page.refresh
|
||||
|
||||
expect(palette_selector).to have_selected_palette(marigold_palette)
|
||||
expect(palette_selector).to have_computed_color("oklch(0.92 0.0708528 68.5036)")
|
||||
|
||||
interface_color_selector.expand
|
||||
interface_color_selector.dark_option.click
|
||||
expect(interface_color_mode).to have_dark_mode_forced
|
||||
expect(palette_selector).to have_computed_color("oklch(0.481966 0.0354264 68.5036)")
|
||||
|
||||
page.refresh
|
||||
expect(palette_selector).to have_selected_palette(marigold_palette)
|
||||
expect(palette_selector).to have_computed_color("oklch(0.481966 0.0354264 68.5036)")
|
||||
end
|
||||
end
|
||||
|
||||
describe "for anon" do
|
||||
it "can open the user color palette menu and select a palette, which is preseved on reload" do
|
||||
visit "/"
|
||||
palette_selector.open_palette_menu
|
||||
palette_selector.click_palette_menu_item(marigold_palette.name)
|
||||
expect(palette_selector).to have_no_palette_menu
|
||||
page.refresh
|
||||
|
||||
expect(palette_selector).to have_selected_palette(marigold_palette)
|
||||
expect(palette_selector).to have_tertiary_color(marigold_palette)
|
||||
end
|
||||
|
||||
it "uses the dark version of the palette if the user selects dark mode, which is preserved on reload" do
|
||||
visit "/"
|
||||
palette_selector.open_palette_menu
|
||||
palette_selector.click_palette_menu_item(marigold_palette.name)
|
||||
expect(palette_selector).to have_no_palette_menu
|
||||
page.refresh
|
||||
|
||||
expect(palette_selector).to have_selected_palette(marigold_palette)
|
||||
expect(palette_selector).to have_computed_color("oklch(0.92 0.0708528 68.5036)")
|
||||
|
||||
interface_color_selector.expand
|
||||
interface_color_selector.dark_option.click
|
||||
expect(interface_color_mode).to have_dark_mode_forced
|
||||
expect(palette_selector).to have_selected_palette(marigold_palette)
|
||||
expect(palette_selector).to have_computed_color("oklch(0.481966 0.0354264 68.5036)")
|
||||
|
||||
page.refresh
|
||||
expect(palette_selector).to have_selected_palette(marigold_palette)
|
||||
expect(palette_selector).to have_computed_color("oklch(0.481966 0.0354264 68.5036)")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user