X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/e0d0b68785bd1a765b796a826eeeb2782f841ada..045af66d438a7fa3567cb4a10ea2f6a255e742c8:/test/controllers/preferences_controller_test.rb?ds=inline diff --git a/test/controllers/preferences_controller_test.rb b/test/controllers/preferences_controller_test.rb index 81760fe5d..d442e2cd2 100644 --- a/test/controllers/preferences_controller_test.rb +++ b/test/controllers/preferences_controller_test.rb @@ -22,6 +22,7 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest def test_update_preferred_editor user = create(:user, :languages => []) + user.preferences.create(:k => "site.color_scheme", :v => "light") session_for(user) # Changing to a invalid editor should fail @@ -32,6 +33,7 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest assert_select ".alert-success", false assert_select ".alert-danger", true assert_select "form > div > select#user_preferred_editor > option[selected]", false + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v # Changing to a valid editor should work user.preferred_editor = "id" @@ -41,6 +43,7 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest assert_template :show assert_select ".alert-success", /^Preferences updated/ assert_select "dd", "iD (in-browser editor)" + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v # Changing to the default editor should work user.preferred_editor = "default" @@ -50,5 +53,28 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest assert_template :show assert_select ".alert-success", /^Preferences updated/ assert_select "dd", "Default (currently iD)" + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v + end + + def test_update_preferred_site_color_scheme + user = create(:user, :languages => []) + session_for(user) + assert_nil user.preferences.find_by(:k => "site.color_scheme") + + # Changing when previously not defined + put preferences_path, :params => { :user => user.attributes, :site_color_scheme => "light" } + assert_redirected_to preferences_path + follow_redirect! + assert_template :show + assert_select ".alert-success", /^Preferences updated/ + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v + + # Changing when previously defined + put preferences_path, :params => { :user => user.attributes, :site_color_scheme => "auto" } + assert_redirected_to preferences_path + follow_redirect! + assert_template :show + assert_select ".alert-success", /^Preferences updated/ + assert_equal "auto", user.preferences.find_by(:k => "site.color_scheme")&.v end end