From 0f564aa64dbeb70744de6249d88da3ed7ae2e487 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 16 Jun 2016 15:04:50 -0700 Subject: [PATCH] Add confirmation persisting to localStorage --- app/scripts/lib/config-manager.js | 11 +++++++++++ test/unit/config-manager-test.js | 32 ++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index f5e1cf38d..24571748f 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -270,6 +270,17 @@ ConfigManager.prototype._emitUpdates = function(state){ }) } +ConfigManager.prototype.setConfirmed = function(confirmed) { + var data = this.getData() + data.isConfirmed = confirmed + this.setData(data) +} + +ConfigManager.prototype.getConfirmed = function() { + var data = this.getData() + return ('isConfirmed' in data) && data.isConfirmed +} + function loadData() { diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index aa94dc385..130bde2ff 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -4,11 +4,41 @@ var configManager describe('config-manager', function() { - before(function() { + beforeEach(function() { window.localStorage = {} // Hacking localStorage support into JSDom configManager = new ConfigManager() }) + describe('confirmation', function() { + + describe('#getConfirmed', function() { + it('should return false if no previous key exists', function() { + var result = configManager.getConfirmed() + assert.ok(!result) + }) + }) + + describe('#setConfirmed', function() { + it('should make getConfirmed return true once set', function() { + configManager.setConfirmed(true) + var result = configManager.getConfirmed() + assert.equal(result, true) + }) + + it('should be able to set false', function() { + configManager.setConfirmed(false) + var result = configManager.getConfirmed() + assert.equal(result, false) + }) + + it('should persist to local storage', function() { + configManager.setConfirmed(true) + var data = configManager.getData() + assert.equal(data.isConfirmed, true) + }) + }) + }) + describe('#setConfig', function() { window.localStorage = {} // Hacking localStorage support into JSDom