diff --git a/lib/gui/pages/settings/controllers/settings.js b/lib/gui/pages/settings/controllers/settings.js
index 2a66af75..b96b9b05 100644
--- a/lib/gui/pages/settings/controllers/settings.js
+++ b/lib/gui/pages/settings/controllers/settings.js
@@ -19,10 +19,17 @@
module.exports = function(SettingsModel) {
/**
- * @summary Settings data
+ * @summary Current settings value
* @type Object
* @public
*/
- this.storage = SettingsModel.data;
+ this.currentData = SettingsModel.getAll();
+
+ /**
+ * @summary Settings model
+ * @type Object
+ * @public
+ */
+ this.model = SettingsModel;
};
diff --git a/lib/gui/pages/settings/templates/settings.tpl.html b/lib/gui/pages/settings/templates/settings.tpl.html
index b0469e42..79f0d71d 100644
--- a/lib/gui/pages/settings/templates/settings.tpl.html
+++ b/lib/gui/pages/settings/templates/settings.tpl.html
@@ -3,21 +3,30 @@
diff --git a/lib/gui/partials/main.html b/lib/gui/partials/main.html
index ad7db37d..12544267 100644
--- a/lib/gui/partials/main.html
+++ b/lib/gui/partials/main.html
@@ -98,10 +98,10 @@
-
+
Your removable drive did not pass validation check.
Please insert another one and
-
+
Oops, seems something went wrong. Click to retry
diff --git a/package.json b/package.json
index 5bf28e40..d63ec932 100644
--- a/package.json
+++ b/package.json
@@ -72,8 +72,8 @@
"immutable": "^3.8.1",
"is-elevated": "^1.0.0",
"lodash": "^4.5.1",
- "ngstorage": "^0.3.10",
"redux": "^3.5.2",
+ "redux-localstorage": "^0.4.1",
"resin-cli-errors": "^1.2.0",
"resin-cli-form": "^1.4.1",
"resin-cli-visuals": "^1.2.8",
diff --git a/tests/gui/components/update-notifier.spec.js b/tests/gui/components/update-notifier.spec.js
index 8d6fe3ae..9050404d 100644
--- a/tests/gui/components/update-notifier.spec.js
+++ b/tests/gui/components/update-notifier.spec.js
@@ -28,7 +28,7 @@ describe('Browser: UpdateNotifier', function() {
describe('given the `sleepUpdateCheck` is disabled', function() {
beforeEach(function() {
- SettingsModel.data.sleepUpdateCheck = false;
+ SettingsModel.set('sleepUpdateCheck', false);
});
it('should return true', function() {
@@ -41,13 +41,13 @@ describe('Browser: UpdateNotifier', function() {
describe('given the `sleepUpdateCheck` is enabled', function() {
beforeEach(function() {
- SettingsModel.data.sleepUpdateCheck = true;
+ SettingsModel.set('sleepUpdateCheck', true);
});
describe('given the `lastUpdateNotify` was never updated', function() {
beforeEach(function() {
- SettingsModel.data.lastUpdateNotify = undefined;
+ SettingsModel.set('lastUpdateNotify', undefined);
});
it('should return true', function() {
@@ -60,7 +60,7 @@ describe('Browser: UpdateNotifier', function() {
describe('given the `lastUpdateNotify` was very recently updated', function() {
beforeEach(function() {
- SettingsModel.data.lastUpdateNotify = Date.now() + 1000;
+ SettingsModel.set('lastUpdateNotify', Date.now() + 1000);
});
it('should return false', function() {
@@ -73,7 +73,7 @@ describe('Browser: UpdateNotifier', function() {
describe('given the `lastUpdateNotify` was updated long ago', function() {
beforeEach(function() {
- SettingsModel.data.lastUpdateNotify = Date.now() + UPDATE_NOTIFIER_SLEEP_TIME + 1000;
+ SettingsModel.set('lastUpdateNotify', Date.now() + UPDATE_NOTIFIER_SLEEP_TIME + 1000);
});
it('should return true', function() {
@@ -82,9 +82,9 @@ describe('Browser: UpdateNotifier', function() {
});
it('should unset the `sleepUpdateCheck` setting', function() {
- m.chai.expect(SettingsModel.data.sleepUpdateCheck).to.be.true;
+ m.chai.expect(SettingsModel.get('sleepUpdateCheck')).to.be.true;
UpdateNotifierService.shouldCheckForUpdates();
- m.chai.expect(SettingsModel.data.sleepUpdateCheck).to.be.false;
+ m.chai.expect(SettingsModel.get('sleepUpdateCheck')).to.be.false;
});
});
diff --git a/tests/gui/models/settings.spec.js b/tests/gui/models/settings.spec.js
new file mode 100644
index 00000000..c85476b7
--- /dev/null
+++ b/tests/gui/models/settings.spec.js
@@ -0,0 +1,101 @@
+'use strict';
+
+const m = require('mochainon');
+const _ = require('lodash');
+const angular = require('angular');
+require('angular-mocks');
+const Store = require('../../../lib/gui/models/store');
+
+describe('Browser: SettingsModel', function() {
+
+ beforeEach(angular.mock.module(
+ require('../../../lib/gui/models/settings')
+ ));
+
+ describe('SettingsModel', function() {
+
+ const SUPPORTED_KEYS = _.keys(Store.Defaults.get('settings').toJS());
+ let SettingsModel;
+
+ beforeEach(angular.mock.inject(function(_SettingsModel_) {
+ SettingsModel = _SettingsModel_;
+ }));
+
+ beforeEach(function() {
+ this.settings = SettingsModel.getAll();
+ });
+
+ afterEach(function() {
+ _.each(SUPPORTED_KEYS, (supportedKey) => {
+ SettingsModel.set(supportedKey, this.settings[supportedKey]);
+ });
+ });
+
+ it('should be able to set and read values', function() {
+ const keyUnderTest = _.first(SUPPORTED_KEYS);
+ const originalValue = SettingsModel.get(keyUnderTest);
+
+ SettingsModel.set(keyUnderTest, !originalValue);
+ m.chai.expect(SettingsModel.get(keyUnderTest)).to.equal(!originalValue);
+ SettingsModel.set(keyUnderTest, originalValue);
+ m.chai.expect(SettingsModel.get(keyUnderTest)).to.equal(originalValue);
+ });
+
+ describe('.set()', function() {
+
+ it('should throw if the key is not supported', function() {
+ m.chai.expect(function() {
+ SettingsModel.set('foobar', true);
+ }).to.throw('Unsupported setting: foobar');
+ });
+
+ it('should throw if no key', function() {
+ m.chai.expect(function() {
+ SettingsModel.set(null, true);
+ }).to.throw('Missing setting key');
+ });
+
+ it('should throw if key is not a string', function() {
+ m.chai.expect(function() {
+ SettingsModel.set(1234, true);
+ }).to.throw('Invalid setting key: 1234');
+ });
+
+ it('should throw if setting an object', function() {
+ const keyUnderTest = _.first(SUPPORTED_KEYS);
+ m.chai.expect(function() {
+ SettingsModel.set(keyUnderTest, {
+ x: 1
+ });
+ }).to.throw('Invalid setting value: [object Object]');
+ });
+
+ it('should throw if setting an array', function() {
+ const keyUnderTest = _.first(SUPPORTED_KEYS);
+ m.chai.expect(function() {
+ SettingsModel.set(keyUnderTest, [ 1, 2, 3 ]);
+ }).to.throw('Invalid setting value: 1,2,3');
+ });
+
+ it('should set the key to undefined if no value', function() {
+ const keyUnderTest = _.first(SUPPORTED_KEYS);
+ SettingsModel.set(keyUnderTest);
+ m.chai.expect(SettingsModel.get(keyUnderTest)).to.be.undefined;
+ });
+
+ });
+
+ describe('.getAll()', function() {
+
+ it('should be able to read all values', function() {
+ const allValues = SettingsModel.getAll();
+
+ _.each(SUPPORTED_KEYS, function(supportedKey) {
+ m.chai.expect(allValues[supportedKey]).to.equal(SettingsModel.get(supportedKey));
+ });
+ });
+
+ });
+
+ });
+});