diff options
| -rw-r--r-- | background_scripts/settings.coffee | 14 | ||||
| -rw-r--r-- | tests/unit_tests/commands_test.coffee | 10 | ||||
| -rw-r--r-- | tests/unit_tests/settings_test.coffee | 30 | 
3 files changed, 42 insertions, 12 deletions
| diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee index 5b2e921a..2f62fc50 100644 --- a/background_scripts/settings.coffee +++ b/background_scripts/settings.coffee @@ -57,15 +57,5 @@ root.Settings = Settings =      nextPatterns: "next,more,>,\u2192,\xbb,\u226b,>>"  # Initialization code. -# settingsVersion was introduced in v1.31, and is used to coordinate data migration. We do not use -# previousVersion as it is used to coordinate the display of the upgrade message, and is not updated -# early enough when the extension loads. -# 1.31 was also the version where we converted all localStorage values to JSON. -if (!Settings.has("settingsVersion")) -  for key of localStorage -    # filterLinkHints' checkbox state used to be stored as a string -    if (key == "filterLinkHints") -      localStorage[key] = if (localStorage[key] == "true") then true else false -    else -      localStorage[key] = JSON.stringify(localStorage[key]) -  Settings.set("settingsVersion", Utils.getCurrentVersion()) +# We use this parameter to coordinate any necessary schema changes. +Settings.set("settingsVersion", Utils.getCurrentVersion()) diff --git a/tests/unit_tests/commands_test.coffee b/tests/unit_tests/commands_test.coffee new file mode 100644 index 00000000..99e0e444 --- /dev/null +++ b/tests/unit_tests/commands_test.coffee @@ -0,0 +1,10 @@ +require "./test_helper.js" +{Commands} = require "../../background_scripts/commands.js" + +context "Key mappings", +  should "lowercase keys correctly", -> +    assert.equal (Commands.normalizeKey '<c-a>'), '<c-a>' +    assert.equal (Commands.normalizeKey '<C-a>'), '<c-a>' +    assert.equal (Commands.normalizeKey '<C-A>'), '<c-A>' +    assert.equal (Commands.normalizeKey '<F12>'), '<f12>' +    assert.equal (Commands.normalizeKey '<C-F12>'), '<c-f12>' diff --git a/tests/unit_tests/settings_test.coffee b/tests/unit_tests/settings_test.coffee new file mode 100644 index 00000000..f86d63dc --- /dev/null +++ b/tests/unit_tests/settings_test.coffee @@ -0,0 +1,30 @@ +require "./test_helper.js" + +{Utils} = require "../../lib/utils.js" +Utils.getCurrentVersion = -> '1.39' +global.localStorage = {} +{Settings} = require "../../background_scripts/settings.js" + +context "settings", +   +  setup -> +    stub global, 'localStorage', {} + +  should "obtain defaults if no key is stored", -> +    assert.isFalse Settings.has 'scrollStepSize' +    assert.equal Settings.get('scrollStepSize'), 60 + +  should "store values", -> +    Settings.set 'scrollStepSize', 20 +    assert.equal Settings.get('scrollStepSize'), 20 + +  should "not store values equal to the default", -> +    Settings.set 'scrollStepSize', 20 +    assert.isTrue Settings.has 'scrollStepSize' +    Settings.set 'scrollStepSize', 60 +    assert.isFalse Settings.has 'scrollStepSize' + +  should "revert to defaults if no key is stored", -> +    Settings.set 'scrollStepSize', 20 +    Settings.clear 'scrollStepSize' +    assert.equal Settings.get('scrollStepSize'), 60 | 
