From 2019c02fc0fc33d4bd98416654370250d7aa0ca6 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 11 Jan 2017 19:26:56 -0800 Subject: test - fix tests from obs-store --- test/unit/metamask-controller-test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 414610404..e648ebd1d 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -10,9 +10,11 @@ describe('MetaMaskController', function() { showUnconfirmedMessage: noop, unlockAccountMessage: noop, showUnapprovedTx: noop, - setData, - loadData, + // initial state + initState: loadData(), }) + // setup state persistence + controller.store.subscribe(setData) beforeEach(function() { // sinon allows stubbing methods that are easily verified -- cgit From 3afd0ef27d69ed5d130f4ea37e3e856cadba34d9 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 27 Jan 2017 23:04:34 -0800 Subject: tests - remove persistence and start with initial state --- test/unit/metamask-controller-test.js | 68 +++++------------------------------ 1 file changed, 8 insertions(+), 60 deletions(-) (limited to 'test/unit/metamask-controller-test.js') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 24d9ddd67..78b9e9df7 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -1,7 +1,9 @@ -var assert = require('assert') -var MetaMaskController = require('../../app/scripts/metamask-controller') -var sinon = require('sinon') -var extend = require('xtend') +const assert = require('assert') +const sinon = require('sinon') +const clone = require('clone') +const MetaMaskController = require('../../app/scripts/metamask-controller') +const firstTimeState = require('../../app/scripts/first-time-state') + const STORAGE_KEY = 'metamask-config' describe('MetaMaskController', function() { @@ -11,15 +13,12 @@ describe('MetaMaskController', function() { unlockAccountMessage: noop, showUnapprovedTx: noop, // initial state - initState: loadData(), + initState: clone(firstTimeState), }) - // setup state persistence - controller.store.subscribe(setData) beforeEach(function() { // sinon allows stubbing methods that are easily verified this.sinon = sinon.sandbox.create() - window.localStorage = {} // Hacking localStorage support into JSDom }) afterEach(function() { @@ -27,55 +26,4 @@ describe('MetaMaskController', function() { this.sinon.restore() }) -}) - - -function loadData () { - var oldData = getOldStyleData() - var newData - try { - newData = JSON.parse(window.localStorage[STORAGE_KEY]) - } catch (e) {} - - var data = extend({ - meta: { - version: 0, - }, - data: { - config: { - provider: { - type: 'testnet', - }, - }, - }, - }, oldData || null, newData || null) - return data -} - -function getOldStyleData () { - var config, wallet, seedWords - - var result = { - meta: { version: 0 }, - data: {}, - } - - try { - config = JSON.parse(window.localStorage['config']) - result.data.config = config - } catch (e) {} - try { - wallet = JSON.parse(window.localStorage['lightwallet']) - result.data.wallet = wallet - } catch (e) {} - try { - seedWords = window.localStorage['seedWords'] - result.data.seedWords = seedWords - } catch (e) {} - - return result -} - -function setData (data) { - window.localStorage[STORAGE_KEY] = JSON.stringify(data) -} +}) \ No newline at end of file -- cgit