UX: add color-scheme meta tag to _head (#30245)

Adds the `color-scheme` meta tag to the `_head` partial and removes it from the finish installation template to prevent it from being added twice.
This commit is contained in:
Renato Atilio
2024-12-13 08:10:08 -03:00
committed by GitHub
parent 9e9abe0a82
commit a21f064fad
4 changed files with 56 additions and 1 deletions

View File

@ -903,4 +903,45 @@ RSpec.describe ApplicationHelper do
HTML
end
end
describe "#discourse_color_scheme_meta_tag" do
fab!(:color_scheme)
before { SiteSetting.default_dark_mode_color_scheme_id = -1 }
it "renders a 'light' color-scheme if no dark scheme is set and the current scheme is light" do
ColorSchemeRevisor.revise(
color_scheme,
colors: [{ name: "primary", hex: "333333" }, { name: "secondary", hex: "DDDDDD" }],
)
helper.request.cookies["color_scheme_id"] = color_scheme.id
expect(helper.discourse_color_scheme_meta_tag).to eq(<<~HTML)
<meta name="color-scheme" content="light">
HTML
end
it "renders a 'dark' color-scheme if no dark scheme is set and the default scheme is dark" do
ColorSchemeRevisor.revise(
color_scheme,
colors: [{ name: "primary", hex: "F8F8F8" }, { name: "secondary", hex: "232323" }],
)
@scheme_id = color_scheme.id
expect(helper.discourse_color_scheme_meta_tag).to eq(<<~HTML)
<meta name="color-scheme" content="dark">
HTML
end
it "renders a 'light dark' color-scheme if a dark scheme is set" do
dark = Fabricate(:color_scheme)
dark.save!
helper.request.cookies["dark_scheme_id"] = dark.id
expect(helper.discourse_color_scheme_meta_tag).to eq(<<~HTML)
<meta name="color-scheme" content="light dark">
HTML
end
end
end