Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add "Increase contrast" checkboxes for "Light high contrast" and "Dark high contrast" that force high contrast in Automatic mode

Kabiru Mwenja740bedb08492
diff --git a/app/forms/my/look_and_feel_form.rb b/app/forms/my/look_and_feel_form.rb
index c0439de7e7c..fce3c53a493 100644
--- a/app/forms/my/look_and_feel_form.rb
+++ b/app/forms/my/look_and_feel_form.rb
@@ -38,14 +38,31 @@ class My::LookAndFeelForm < ApplicationForm
caption: I18n.t("activerecord.attributes.user_preference.mode_guideline"),
required: true,
include_blank: false,
- input_width: :small
+ input_width: :small,
+ data: {
+ my__look_and_feel_target: "themeSelect",
+ action: "my--look-and-feel#updateContrastOptions"
+ }
) do |select|
- theme_options_for_select.each do |theme|
- select.option(
- value: theme[1],
- label: theme[0]
- )
- end
+ theme_options_for_select.each { |(label, value)| select.option(value:, label:) }
+ end
+
+ f.check_box_group(data: { my__look_and_feel_target: "autoThemeContrast" }) do |group|
+ group.check_box name: :enable_auto_light_theme_contrast,
+ label: I18n.t("activerecord.attributes.user_preference.enable_auto_light_theme_contrast"),
+ checked: user_preference.enable_auto_light_theme_contrast?,
+ caption: I18n.t("activerecord.attributes.user_preference.enable_auto_light_theme_contrast_caption")
+ group.check_box name: :enable_auto_dark_theme_contrast,
+ label: I18n.t("activerecord.attributes.user_preference.enable_auto_dark_theme_contrast"),
+ checked: user_preference.enable_auto_dark_theme_contrast?,
+ caption: I18n.t("activerecord.attributes.user_preference.enable_auto_dark_theme_contrast_caption")
+ end
+
+ f.check_box_group(data: { my__look_and_feel_target: "singleThemeContrast" }) do |group|
+ group.check_box name: :increase_theme_contrast,
+ label: I18n.t("activerecord.attributes.user_preference.increase_contrast"),
+ checked: user_preference.increase_theme_contrast?,
+ caption: I18n.t("activerecord.attributes.user_preference.increase_contrast_caption")
end
f.select_list(
@@ -55,12 +72,7 @@ class My::LookAndFeelForm < ApplicationForm
include_blank: false,
input_width: :small
) do |select|
- comment_sort_order_options.each do |theme|
- select.option(
- value: theme[1],
- label: theme[0]
- )
- end
+ comment_sort_order_options.each { |(label, value)| select.option(value:, label:) }
end
f.check_box name: :disable_keyboard_shortcuts,
@@ -72,4 +84,10 @@ class My::LookAndFeelForm < ApplicationForm
label: I18n.t("activerecord.attributes.user_preference.button_update_look_and_feel"),
scheme: :default)
end
+
+ private
+
+ def user_preference
+ User.current.pref
+ end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index daa31632dbd..ee9780ad6ea 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -291,9 +291,7 @@ module ApplicationHelper
def theme_options_for_select
[
[I18n.t("themes.light"), "light"],
- [I18n.t("themes.light_high_contrast"), "light_high_contrast"],
[I18n.t("themes.dark"), "dark"],
- [I18n.t("themes.dark_high_contrast"), "dark_high_contrast"],
[I18n.t("themes.sync_with_os"), "sync_with_os"]
]
end
@@ -315,18 +313,15 @@ module ApplicationHelper
end
def user_theme_data_attributes
- if User.current.pref.sync_with_os_theme?
- # Theme will be set by inline script before body renders to prevent flickering
- { auto_theme_switcher_mode_value: User.current.pref.theme,
- auto_theme_switcher_desktop_light_high_contrast_logo_class: "op-logo--link_high_contrast",
- auto_theme_switcher_mobile_white_logo_class: "op-logo--icon_white" }
- else
- mode, _theme_suffix = User.current.pref.theme.split("_", 2)
- {
- color_mode: mode,
- "#{mode}_theme": User.current.pref.theme
- }
- end
+ theme = User.current.pref.theme
+
+ { auto_theme_switcher_theme_value: theme,
+ auto_theme_switcher_increase_contrast_value: User.current.pref.increase_theme_contrast?,
+ auto_theme_switcher_enable_auto_light_theme_contrast_value: User.current.pref.enable_auto_light_theme_contrast?,
+ auto_theme_switcher_enable_auto_dark_theme_contrast_value: User.current.pref.enable_auto_dark_theme_contrast?,
+ auto_theme_switcher_desktop_light_high_contrast_logo_class: "op-logo--link_high_contrast",
+ auto_theme_switcher_mobile_white_logo_class: "op-logo--icon_white",
+ color_mode: theme, "#{theme}_theme": theme }
end
def highlight_default_language(lang_options)
diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb
index 533c873ede5..2235758f342 100644
--- a/app/models/permitted_params.rb
+++ b/app/models/permitted_params.rb
@@ -266,6 +266,9 @@ class PermittedParams
def pref
params.fetch(:pref, {}).permit(:time_zone,
:theme,
+ :increase_theme_contrast,
+ :enable_auto_light_theme_contrast,
+ :enable_auto_dark_theme_contrast,
:comments_sorting,
:disable_keyboard_shortcuts,
:warn_on_leaving_unsaved,
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 96001645cb9..9b23607041f 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -38,7 +38,8 @@ class UserPreference < ApplicationRecord
WORKDAYS_FROM_MONDAY_TO_FRIDAY = [1, 2, 3, 4, 5].freeze
- THEMES = %w[light light_high_contrast dark dark_high_contrast sync_with_os].freeze
+ COLOR_MODES = %w[light dark].freeze
+ THEMES = COLOR_MODES + %w[sync_with_os].freeze
##
# Retrieve keys from settings, and allow accessing
@@ -132,7 +133,19 @@ class UserPreference < ApplicationRecord
super.presence || Setting.user_default_theme
end
- %w[dark light].each do |base_theme_name|
+ def increase_theme_contrast=(value)
+ settings[:increase_theme_contrast] = to_boolean(value)
+ end
+
+ def enable_auto_light_theme_contrast=(value)
+ settings[:enable_auto_light_theme_contrast] = to_boolean(value)
+ end
+
+ def enable_auto_dark_theme_contrast=(value)
+ settings[:enable_auto_dark_theme_contrast] = to_boolean(value)
+ end
+
+ COLOR_MODES.each do |base_theme_name|
define_method("base_theme_#{base_theme_name}?") { theme.split("_", 2)[0] == base_theme_name.to_s }
end
@@ -140,6 +153,14 @@ class UserPreference < ApplicationRecord
define_method("#{theme_name}_theme?") { theme == theme_name.to_s }
end
+ def light_high_contrast_theme?
+ light_theme? && increase_theme_contrast?
+ end
+
+ def dark_high_contrast_theme?
+ dark_theme? && increase_theme_contrast?
+ end
+
def time_zone
super.presence || Setting.user_default_timezone.presence || "Etc/UTC"
end
diff --git a/app/views/my/interface.html.erb b/app/views/my/interface.html.erb
index c46059ba529..3bc01fb9f44 100644
--- a/app/views/my/interface.html.erb
+++ b/app/views/my/interface.html.erb
@@ -47,7 +47,13 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
<%=
- settings_primer_form_with(model: @user.pref, scope: :pref, url: { action: "update_settings" }, method: :patch, data: { turbo: false }) do |form|
+ settings_primer_form_with(
+ model: @user.pref,
+ scope: :pref,
+ url: { action: "update_settings" },
+ method: :patch,
+ data: { turbo: false, controller: "my--look-and-feel" }
+ ) do |form|
render(My::LookAndFeelForm.new(form))
end
%>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 5bf1329ec4c..8468dc2b211 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -758,9 +758,7 @@ en:
themes:
dark: "Dark"
- dark_high_contrast: "Dark high contrast"
light: "Light"
- light_high_contrast: "Light high contrast"
sync_with_os: "Automatic (match OS color mode)"
types:
@@ -1285,6 +1283,13 @@ en:
auto_hide_popups: "Automatically hide success banners"
auto_hide_popups_caption: "When enabled, the green success banners will automatically disappear after 5 seconds."
warn_on_leaving_unsaved: "Warn me when leaving a work package with unsaved changes"
+ increase_theme_contrast: "Increase theme contrast"
+ increase_contrast: "Increase contrast"
+ increase_contrast_caption: "Enables high-contrast mode for the chosen colour mode."
+ enable_auto_light_theme_contrast: "Force high-contrast when in Light mode"
+ enable_auto_dark_theme_contrast: "Force high-contrast when in Dark mode"
+ enable_auto_light_theme_contrast_caption: "Enabling this will force high-contrast mode when light mode is active (in Automatic mode)."
+ enable_auto_dark_theme_contrast_caption: "Enabling this will force high-contrast mode when dark mode is active (in Automatic mode)."
theme: "Color mode"
time_zone: "Time zone"
mode_guideline: "Some modes will overwrite custom theme colors for accessibility and legibility. Please select Light mode for full custom theme support."
diff --git a/config/schemas/user_preferences.schema.json b/config/schemas/user_preferences.schema.json
index a70857bf89b..56189b7e7b9 100644
--- a/config/schemas/user_preferences.schema.json
+++ b/config/schemas/user_preferences.schema.json
@@ -11,7 +11,16 @@
},
"theme": {
"type": "string",
- "enum": ["light", "light_high_contrast", "dark", "dark_high_contrast", "sync_with_os"]
+ "enum": ["light", "dark", "sync_with_os"]
+ },
+ "increase_theme_contrast": {
+ "type": "boolean"
+ },
+ "enable_auto_light_theme_contrast": {
+ "type": "boolean"
+ },
+ "enable_auto_dark_theme_contrast": {
+ "type": "boolean"
},
"disable_keyboard_shortcuts": {
"type": "boolean"
diff --git a/frontend/src/app/core/setup/globals/theme-utils.ts b/frontend/src/app/core/setup/globals/theme-utils.ts
index c19c8b45c55..3e71c689378 100644
--- a/frontend/src/app/core/setup/globals/theme-utils.ts
+++ b/frontend/src/app/core/setup/globals/theme-utils.ts
@@ -30,14 +30,9 @@
export type OpColorMode = 'light' | 'dark';
-export type OpTheme = OpColorMode | `${OpColorMode}_high_contrast` | 'sync_with_os';
+export type OpTheme = OpColorMode | 'sync_with_os';
export class ThemeUtils {
- public applySystemThemeImmediately():void {
- const colorMode = this.detectSystemColorMode();
- this.applyThemeToBody(colorMode);
- }
-
public detectOpColorMode():OpColorMode {
return document.body.getAttribute('data-color-mode') as OpColorMode;
}
@@ -46,21 +41,12 @@ export class ThemeUtils {
return this.prefersSystemLightMode() ? 'light' : 'dark';
}
- public prefersSystemLightHighContrast():boolean {
- return this.prefersSystemLightMode() && this.prefersSystemHighContrast();
- }
-
public prefersSystemLightMode():boolean {
return window.matchMedia('(prefers-color-scheme: light)').matches;
}
- public prefersSystemHighContrast():boolean {
- return window.matchMedia('(prefers-contrast: more)').matches;
- }
-
- public applyThemeToBody(colorMode:OpColorMode):void {
+ public applyThemeToBody(colorMode:OpColorMode, increaseContrast:boolean):void {
const body = document.body;
- const increaseContrast = this.prefersSystemHighContrast();
const otherColorMode = (colorMode === 'light' ? 'dark' : 'light');
body.setAttribute('data-color-mode', colorMode);
diff --git a/frontend/src/stimulus/controllers/auto-theme-switcher.controller.ts b/frontend/src/stimulus/controllers/auto-theme-switcher.controller.ts
index 55b08efd8d9..d967cf007dd 100644
--- a/frontend/src/stimulus/controllers/auto-theme-switcher.controller.ts
+++ b/frontend/src/stimulus/controllers/auto-theme-switcher.controller.ts
@@ -30,25 +30,37 @@
import { Controller } from '@hotwired/stimulus';
import { useMatchMedia } from 'stimulus-use';
-import { OpTheme } from 'core-app/core/setup/globals/theme-utils';
+import { OpColorMode, OpTheme } from 'core-app/core/setup/globals/theme-utils';
export default class AutoThemeSwitcher extends Controller {
static values = {
- mode: String,
+ theme: String,
+ increaseContrast: Boolean,
+ enableAutoLightThemeContrast: Boolean,
+ enableAutoDarkThemeContrast: Boolean,
};
static targets = ['desktopLogo', 'mobileLogo'];
static classes = ['desktopLightHighContrastLogo', 'mobileWhiteLogo'];
- declare readonly modeValue:OpTheme;
+ declare readonly themeValue:OpTheme;
+ declare readonly increaseContrastValue:boolean;
+ declare readonly enableAutoLightThemeContrastValue:boolean;
+ declare readonly enableAutoDarkThemeContrastValue:boolean;
declare readonly desktopLogoTarget:HTMLLinkElement;
declare readonly mobileLogoTarget:HTMLLinkElement;
declare readonly desktopLightHighContrastLogoClass:string;
declare readonly mobileWhiteLogoClass:string;
connect() {
- if (this.modeValue !== 'sync_with_os') return;
+ if (this.themeValue === 'sync_with_os') {
+ this.syncWithOS();
+ } else {
+ this.applyTheme(this.themeValue, this.increaseContrastValue);
+ }
+ }
+ syncWithOS():void {
useMatchMedia(this, {
mediaQueries: {
lightMode: '(prefers-color-scheme: light)',
@@ -59,6 +71,11 @@ export default class AutoThemeSwitcher extends Controller {
this.applySystemTheme();
}
+ applyTheme(theme:OpColorMode, increaseContrast:boolean):void {
+ window.OpenProject.theme.applyThemeToBody(theme, increaseContrast);
+ this.updateOpLogoContrast(increaseContrast);
+ }
+
lightModeChanged():void {
this.applySystemTheme();
}
@@ -68,13 +85,16 @@ export default class AutoThemeSwitcher extends Controller {
}
private applySystemTheme():void {
- window.OpenProject.theme.applySystemThemeImmediately();
- this.updateOpLogoContrast();
+ const colorMode = window.OpenProject.theme.detectSystemColorMode();
+ const themeContrastPreference = {
+ light: this.enableAutoLightThemeContrastValue,
+ dark: this.enableAutoDarkThemeContrastValue,
+ };
+ this.applyTheme(colorMode, themeContrastPreference[colorMode]);
}
- private updateOpLogoContrast():void {
- const prefersSystemLightHighContrast = window.OpenProject.theme.prefersSystemLightHighContrast();
- this.desktopLogoTarget.classList.toggle(this.desktopLightHighContrastLogoClass, prefersSystemLightHighContrast);
- this.mobileLogoTarget.classList.toggle(this.mobileWhiteLogoClass, !prefersSystemLightHighContrast);
+ private updateOpLogoContrast(increaseContrast:boolean):void {
+ this.desktopLogoTarget.classList.toggle(this.desktopLightHighContrastLogoClass, increaseContrast);
+ this.mobileLogoTarget.classList.toggle(this.mobileWhiteLogoClass, !increaseContrast);
}
}
diff --git a/frontend/src/stimulus/controllers/dynamic/my/look-and-feel.controller.ts b/frontend/src/stimulus/controllers/dynamic/my/look-and-feel.controller.ts
new file mode 100644
index 00000000000..c16db186dff
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/my/look-and-feel.controller.ts
@@ -0,0 +1,63 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) the OpenProject GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 3.
+ *
+ * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+ * Copyright (C) 2006-2013 Jean-Philippe Lang
+ * Copyright (C) 2010-2013 the ChiliProject Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * See COPYRIGHT and LICENSE files for more details.
+ * ++
+ */
+
+import { Controller } from '@hotwired/stimulus';
+
+export default class LookAndFeelController extends Controller {
+ static targets = ['themeSelect', 'autoThemeContrast', 'singleThemeContrast'];
+
+ declare themeSelectTarget:HTMLSelectElement;
+ declare autoThemeContrastTarget:HTMLElement;
+ declare singleThemeContrastTarget:HTMLElement;
+
+ private syncWithOsValue = 'sync_with_os';
+ private displayNoneClass = 'd-none';
+ private viewComponentSelector = '[data-view-component="true"]';
+
+ connect() {
+ this.toggleOptionGroups();
+ }
+
+ updateContrastOptions() {
+ this.toggleOptionGroups();
+ }
+
+ private toggleOptionGroups() {
+ const isSyncWithOs = this.themeSelectTarget.value === this.syncWithOsValue;
+
+ this.toggleElementVisibility(this.autoThemeContrastTarget, !isSyncWithOs);
+ this.toggleElementVisibility(this.singleThemeContrastTarget, isSyncWithOs);
+ }
+
+ private toggleElementVisibility(targetElement:HTMLElement, shouldHide:boolean) {
+ const container = targetElement.closest(this.viewComponentSelector);
+ container?.classList.toggle(this.displayNoneClass, shouldHide);
+ }
+}
diff --git a/spec/features/my/interface_spec.rb b/spec/features/my/interface_spec.rb
index c7fc3553d69..a764a5c5c45 100644
--- a/spec/features/my/interface_spec.rb
+++ b/spec/features/my/interface_spec.rb
@@ -47,28 +47,59 @@ RSpec.describe "My account Interface settings",
expect(page).to have_css("body[data-color-mode='light'][data-light-theme='light']")
- select "Light high contrast", from: "Color mode"
+ select "Dark", from: "Color mode"
click_on "Update look and feel"
- expect(page).to have_css("body[data-color-mode='light'][data-light-theme='light_high_contrast']")
+ expect(page).to have_css("body[data-color-mode='dark'][data-dark-theme='dark']")
- select "Dark", from: "Color mode"
+ select "Automatic (match OS color mode)", from: "Color mode"
click_on "Update look and feel"
- expect(page).to have_css("body[data-color-mode='dark'][data-dark-theme='dark']")
+ expect(page).to have_css("body[data-auto-theme-switcher-theme-value='sync_with_os']")
+ end
+
+ it "allows user to increase contrast for single theme modes" do
+ click_on "Interface"
- select "Dark high contrast", from: "Color mode"
+ select "Light", from: "Color mode"
+
+ expect(page).to have_field("Increase contrast")
+ expect(page).to have_no_field("Force high-contrast when in Light mode")
+ expect(page).to have_no_field("Force high-contrast when in Dark mode")
+
+ check "Increase contrast"
+ click_on "Update look and feel"
+
+ expect(page).to have_css("body[data-color-mode='light'][data-light-theme='light_high_contrast']")
+
+ select "Dark", from: "Color mode"
+
+ check "Increase contrast"
click_on "Update look and feel"
expect(page).to have_css("body[data-color-mode='dark'][data-dark-theme='dark_high_contrast']")
+ end
+
+ it "shows appropriate contrast options based on theme selection" do
+ click_on "Interface"
+
+ select "Light", from: "Color mode"
+ expect(page).to have_field("Increase contrast")
+ expect(page).to have_no_field("Force high-contrast when in Light mode")
+ expect(page).to have_no_field("Force high-contrast when in Dark mode")
select "Automatic (match OS color mode)", from: "Color mode"
- click_on "Update look and feel"
+ expect(page).to have_no_field("Increase contrast")
+ expect(page).to have_field("Force high-contrast when in Light mode")
+ expect(page).to have_field("Force high-contrast when in Dark mode")
- expect(page).to have_css("body[data-auto-theme-switcher-mode-value='sync_with_os']")
+ select "Dark", from: "Color mode"
+ expect(page).to have_field("Increase contrast")
+ expect(page).to have_no_field("Force high-contrast when in Light mode")
+ expect(page).to have_no_field("Force high-contrast when in Dark mode")
end
- describe "Automatic (match OS color mode)" do
+ describe "Automatic (match OS color mode)" do
def set_automatic_mode_with_reload
click_on "Interface"
@@ -76,6 +107,20 @@ RSpec.describe "My account Interface settings",
click_on "Update look and feel"
end
+ it "allows user to configure auto-contrast for both light and dark modes" do
+ click_on "Interface"
+
+ select "Automatic (match OS color mode)", from: "Color mode"
+
+ check "Force high-contrast when in Light mode"
+ check "Force high-contrast when in Dark mode"
+ click_on "Update look and feel"
+
+ expect(page).to have_css("body[data-auto-theme-switcher-theme-value='sync_with_os']")
+ expect(page).to have_css("body[data-auto-theme-switcher-enable-auto-light-theme-contrast-value='true']")
+ expect(page).to have_css("body[data-auto-theme-switcher-enable-auto-dark-theme-contrast-value='true']")
+ end
+
context "with OS in dark mode", driver: :chrome_dark_mode do
it "syncs with OS colour mode" do
set_automatic_mode_with_reload
diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rb
index f638896ec39..ac9af652f27 100644
--- a/spec/models/user_preference_spec.rb
+++ b/spec/models/user_preference_spec.rb
@@ -267,23 +267,51 @@ RSpec.describe UserPreference do
end
end
- context "with a light high contrast theme specified" do
- let(:settings) { { "theme" => "light_high_contrast" } }
+ context "with a light theme and contrast enabled" do
+ let(:settings) { { "theme" => "light", "increase_theme_contrast" => true } }
- it "returns the light high contrast theme" do
- expect(subject.theme).to eq("light_high_contrast")
+ it "returns light theme with high contrast detection" do
+ expect(subject.theme).to eq("light")
+ expect(subject).to be_a_light_theme
expect(subject).to be_a_light_high_contrast_theme
expect(subject).to be_a_base_theme_light
+ expect(subject.increase_theme_contrast?).to be true
end
end
- context "with a dark high contrast theme specified" do
- let(:settings) { { "theme" => "dark_high_contrast" } }
+ context "with a dark theme and contrast enabled" do
+ let(:settings) { { "theme" => "dark", "increase_theme_contrast" => true } }
- it "returns the dark high contrast theme" do
- expect(subject.theme).to eq("dark_high_contrast")
+ it "returns dark theme with high contrast detection" do
+ expect(subject.theme).to eq("dark")
+ expect(subject).to be_a_dark_theme
expect(subject).to be_a_dark_high_contrast_theme
expect(subject).to be_a_base_theme_dark
+ expect(subject.increase_theme_contrast?).to be true
+ end
+ end
+
+ context "with light theme and contrast disabled" do
+ let(:settings) { { "theme" => "light", "increase_theme_contrast" => false } }
+
+ it "returns light theme without high contrast" do
+ expect(subject.theme).to eq("light")
+ expect(subject).to be_a_light_theme
+ expect(subject).not_to be_a_light_high_contrast_theme
+ expect(subject).to be_a_base_theme_light
+ expect(subject.increase_theme_contrast?).to be false
+ end
+ end
+
+ context "with dark theme and contrast disabled" do
+ let(:settings) { { "theme" => "dark", "increase_theme_contrast" => false } }
+
+ it "returns dark theme without high contrast" do
+ expect(subject.theme).to eq("dark")
+ expect(subject).to be_a_dark_theme
+ expect(subject).not_to be_a_dark_high_contrast_theme
+ expect(subject).to be_a_base_theme_dark
+ expect(subject.increase_theme_contrast?).to be false
end
end
@@ -295,5 +323,31 @@ RSpec.describe UserPreference do
expect(subject).to be_a_sync_with_os_theme
end
end
+
+ context "with unset contrast settings" do
+ let(:settings) { { "theme" => "light" } }
+
+ it "defaults contrast settings to false" do
+ expect(subject).not_to be_increase_theme_contrast
+ expect(subject).not_to be_enable_auto_light_theme_contrast
+ expect(subject).not_to be_enable_auto_dark_theme_contrast
+ expect(subject).not_to be_a_light_high_contrast_theme
+ expect(subject).not_to be_a_dark_high_contrast_theme
+ end
+ end
+ end
+
+ describe "contrast settings" do
+ it_behaves_like "accepts real and false booleans",
+ :increase_theme_contrast=,
+ :increase_theme_contrast?
+
+ it_behaves_like "accepts real and false booleans",
+ :enable_auto_light_theme_contrast=,
+ :enable_auto_light_theme_contrast?
+
+ it_behaves_like "accepts real and false booleans",
+ :enable_auto_dark_theme_contrast=,
+ :enable_auto_dark_theme_contrast?
end
end