]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/preferences_controller_test.rb
Localisation updates from https://translatewiki.net.
[rails.git] / test / controllers / preferences_controller_test.rb
index d442e2cd2b98f24fadc0c7f87e2e5e208025f52d..1cd07b7d9f68a4adfaa6fc655215a80a21edceab 100644 (file)
@@ -23,6 +23,7 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest
   def test_update_preferred_editor
     user = create(:user, :languages => [])
     user.preferences.create(:k => "site.color_scheme", :v => "light")
   def test_update_preferred_editor
     user = create(:user, :languages => [])
     user.preferences.create(:k => "site.color_scheme", :v => "light")
+    user.preferences.create(:k => "map.color_scheme", :v => "light")
     session_for(user)
 
     # Changing to a invalid editor should fail
     session_for(user)
 
     # Changing to a invalid editor should fail
@@ -34,6 +35,7 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest
     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
     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
+    assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v
 
     # Changing to a valid editor should work
     user.preferred_editor = "id"
 
     # Changing to a valid editor should work
     user.preferred_editor = "id"
@@ -44,6 +46,7 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest
     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
     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
+    assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v
 
     # Changing to the default editor should work
     user.preferred_editor = "default"
 
     # Changing to the default editor should work
     user.preferred_editor = "default"
@@ -54,6 +57,7 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest
     assert_select ".alert-success", /^Preferences updated/
     assert_select "dd", "Default (currently iD)"
     assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v
     assert_select ".alert-success", /^Preferences updated/
     assert_select "dd", "Default (currently iD)"
     assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v
+    assert_equal "light", user.preferences.find_by(:k => "map.color_scheme")&.v
   end
 
   def test_update_preferred_site_color_scheme
   end
 
   def test_update_preferred_site_color_scheme
@@ -77,4 +81,26 @@ class PreferencesControllerTest < ActionDispatch::IntegrationTest
     assert_select ".alert-success", /^Preferences updated/
     assert_equal "auto", user.preferences.find_by(:k => "site.color_scheme")&.v
   end
     assert_select ".alert-success", /^Preferences updated/
     assert_equal "auto", user.preferences.find_by(:k => "site.color_scheme")&.v
   end
+
+  def test_update_preferred_map_color_scheme
+    user = create(:user, :languages => [])
+    session_for(user)
+    assert_nil user.preferences.find_by(:k => "map.color_scheme")
+
+    # Changing when previously not defined
+    put preferences_path, :params => { :user => user.attributes, :map_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 => "map.color_scheme")&.v
+
+    # Changing when previously defined
+    put preferences_path, :params => { :user => user.attributes, :map_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 => "map.color_scheme")&.v
+  end
 end
 end