Files
discourse/spec/system/user_page/user_preferences_interface_spec.rb
Osama Sayegh c6bbbd0608 FIX: Set the correct state of the dark mode checkbox user preference (#31214)
This commit fixes a bug in the "Dark Mode" checkbox in the interface user
preferences where the checkbox state doesn't appear in the disabled
state if the user disables dark mode.

This happens because when rendering the checkbox, we check the relevant
user options field within the controller's `init` method, but at that
point in the controller's life cycle, the `user_option` object isn't
available. What we should do instead is move this check to the route's
`setupController` method where the `user_option` object is available and
we can set the correct state on the controller.

https://meta.discourse.org/t/-/349976 (private topic)
2025-02-06 20:31:37 +03:00

90 lines
3.3 KiB
Ruby

# frozen_string_literal: true
describe "User preferences | Interface", type: :system do
fab!(:user)
let(:user_preferences_page) { PageObjects::Pages::UserPreferences.new }
let(:user_preferences_interface_page) { PageObjects::Pages::UserPreferencesInterface.new }
before { sign_in(user) }
describe "Bookmarks" do
it "changes the bookmark after notification preference" do
user_preferences_page.visit(user)
click_link(I18n.t("js.user.preferences_nav.interface"))
dropdown = PageObjects::Components::SelectKit.new("#bookmark-after-notification-mode")
# preselects the default user_option.bookmark_auto_delete_preference value of 3 (clear_reminder)
expect(dropdown).to have_selected_value(Bookmark.auto_delete_preferences[:clear_reminder])
dropdown.select_row_by_value(Bookmark.auto_delete_preferences[:when_reminder_sent])
click_button(I18n.t("js.save"))
# the preference page reloads after saving, so we need to poll the db
try_until_success(timeout: 20) do
expect(
UserOption.exists?(
user_id: user.id,
bookmark_auto_delete_preference: Bookmark.auto_delete_preferences[:when_reminder_sent],
),
).to be_truthy
end
end
end
describe "Default Home Page" do
context "when a user has picked a home page that is no longer available in top_menu" do
it "shows the selected homepage" do
SiteSetting.top_menu = "latest|hot"
user.user_option.update!(homepage_id: UserOption::HOMEPAGES.key("unread"))
user_preferences_page.visit(user)
click_link(I18n.t("js.user.preferences_nav.interface"))
dropdown = PageObjects::Components::SelectKit.new("#home-selector")
expect(dropdown).to have_selected_name("Unread")
end
end
it "shows only the available home pages from top_menu" do
SiteSetting.top_menu = "latest|hot"
user_preferences_page.visit(user)
click_link(I18n.t("js.user.preferences_nav.interface"))
dropdown = PageObjects::Components::SelectKit.new("#home-selector")
dropdown.expand
expect(dropdown).to have_option_value(UserOption::HOMEPAGES.key("latest"))
expect(dropdown).to have_option_value(UserOption::HOMEPAGES.key("hot"))
expect(dropdown).to have_no_option_value(UserOption::HOMEPAGES.key("top"))
expect(dropdown).to have_no_option_value(UserOption::HOMEPAGES.key("new"))
end
end
describe "Color palette" do
context "when there's only 1 dark color palette" do
before do
dark = ColorScheme.find_by(base_scheme_id: "Dark")
ColorScheme.where.not(id: dark.id).destroy_all
user.user_option.update!(dark_scheme_id: dark.id, theme_ids: [SiteSetting.default_theme_id])
end
it "displays a checkbox for activating/deactivating the dark palette" do
user_preferences_interface_page.visit(user)
expect(user_preferences_interface_page.dark_mode_checkbox.checked?).to eq(true)
user_preferences_interface_page.dark_mode_checkbox.click
user_preferences_interface_page.save_changes
expect(user_preferences_interface_page.dark_mode_checkbox.checked?).to eq(false)
page.refresh
expect(user_preferences_interface_page.dark_mode_checkbox.checked?).to eq(false)
end
end
end
end