aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-04-19 11:33:51 +0800
committerWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-05-17 23:27:39 +0800
commit924cc1fcf7de1896ac09bbe7a400d5ff5df0b50d (patch)
tree2a0f33c2ccd450bdd620b59df5510e5bbb670a9a /test/unit
parent708422432c634ffbd4c73388f980c43f766b3355 (diff)
downloadtangerine-wallet-browser-924cc1fcf7de1896ac09bbe7a400d5ff5df0b50d.tar
tangerine-wallet-browser-924cc1fcf7de1896ac09bbe7a400d5ff5df0b50d.tar.gz
tangerine-wallet-browser-924cc1fcf7de1896ac09bbe7a400d5ff5df0b50d.tar.bz2
tangerine-wallet-browser-924cc1fcf7de1896ac09bbe7a400d5ff5df0b50d.tar.lz
tangerine-wallet-browser-924cc1fcf7de1896ac09bbe7a400d5ff5df0b50d.tar.xz
tangerine-wallet-browser-924cc1fcf7de1896ac09bbe7a400d5ff5df0b50d.tar.zst
tangerine-wallet-browser-924cc1fcf7de1896ac09bbe7a400d5ff5df0b50d.zip
Move setAccountLabel into PreferencesController
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/actions/save_account_label_test.js35
-rw-r--r--test/unit/actions/set_account_label_test.js34
-rw-r--r--test/unit/preferences-controller-test.js51
3 files changed, 84 insertions, 36 deletions
diff --git a/test/unit/actions/save_account_label_test.js b/test/unit/actions/save_account_label_test.js
deleted file mode 100644
index c5ffd6cbf..000000000
--- a/test/unit/actions/save_account_label_test.js
+++ /dev/null
@@ -1,35 +0,0 @@
-// var jsdom = require('mocha-jsdom')
-var assert = require('assert')
-var freeze = require('deep-freeze-strict')
-var path = require('path')
-
-var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
-var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
-
-describe('SAVE_ACCOUNT_LABEL', function () {
- it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function () {
- var initialState = {
- metamask: {
- identities: {
- foo: {
- name: 'bar',
- },
- },
- },
- }
- freeze(initialState)
-
- const action = {
- type: actions.SAVE_ACCOUNT_LABEL,
- value: {
- account: 'foo',
- label: 'baz',
- },
- }
- freeze(action)
-
- var resultingState = reducers(initialState, action)
- assert.equal(resultingState.metamask.identities.foo.name, action.value.label)
- })
-})
-
diff --git a/test/unit/actions/set_account_label_test.js b/test/unit/actions/set_account_label_test.js
new file mode 100644
index 000000000..53ea1d130
--- /dev/null
+++ b/test/unit/actions/set_account_label_test.js
@@ -0,0 +1,34 @@
+const assert = require('assert')
+const freeze = require('deep-freeze-strict')
+const path = require('path')
+
+const actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
+const reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
+
+describe('SET_ACCOUNT_LABEL', function () {
+ it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function () {
+ const initialState = {
+ metamask: {
+ identities: {
+ foo: {
+ name: 'bar',
+ },
+ },
+ },
+ }
+ freeze(initialState)
+
+ const action = {
+ type: actions.SET_ACCOUNT_LABEL,
+ value: {
+ account: 'foo',
+ label: 'baz',
+ },
+ }
+ freeze(action)
+
+ const resultingState = reducers(initialState, action)
+ assert.equal(resultingState.metamask.identities.foo.name, action.value.label)
+ })
+})
+
diff --git a/test/unit/preferences-controller-test.js b/test/unit/preferences-controller-test.js
index 9fb5e4251..8ff1c8648 100644
--- a/test/unit/preferences-controller-test.js
+++ b/test/unit/preferences-controller-test.js
@@ -4,16 +4,26 @@ const PreferencesController = require('../../app/scripts/controllers/preferences
describe('preferences controller', function () {
let preferencesController
- before(() => {
+ beforeEach(() => {
preferencesController = new PreferencesController()
})
+ describe('getTokens', function () {
+ it('should return an empty list initially', async function () {
+ await preferencesController.setSelectedAddress('0x7e57e2')
+
+ const tokens = preferencesController.getTokens()
+ assert.equal(tokens.length, 0, 'empty list of tokens')
+ })
+ })
+
describe('addToken', function () {
it('should add that token to its state', async function () {
const address = '0xabcdef1234567'
const symbol = 'ABBR'
const decimals = 5
+ await preferencesController.setSelectedAddress('0x7e57e2')
await preferencesController.addToken(address, symbol, decimals)
const tokens = preferencesController.getTokens()
@@ -30,6 +40,7 @@ describe('preferences controller', function () {
const symbol = 'ABBR'
const decimals = 5
+ await preferencesController.setSelectedAddress('0x7e57e2')
await preferencesController.addToken(address, symbol, decimals)
const newDecimals = 6
@@ -43,6 +54,44 @@ describe('preferences controller', function () {
assert.equal(added.symbol, symbol, 'set symbol correctly')
assert.equal(added.decimals, newDecimals, 'updated decimals correctly')
})
+
+ it('should allow adding tokens to two separate addresses', async function () {
+ const address = '0xabcdef1234567'
+ const symbol = 'ABBR'
+ const decimals = 5
+
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken(address, symbol, decimals)
+ assert.equal(preferencesController.getTokens().length, 1, 'one token added for 1st address')
+
+ await preferencesController.setSelectedAddress('0xda22le')
+ await preferencesController.addToken(address, symbol, decimals)
+ assert.equal(preferencesController.getTokens().length, 1, 'one token added for 2nd address')
+ })
+ })
+
+ describe('removeToken', function () {
+ it('should remove the only token from its state', async function () {
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken('0xa', 'A', 5)
+ await preferencesController.removeToken('0xa')
+
+ const tokens = preferencesController.getTokens()
+ assert.equal(tokens.length, 0, 'one token removed')
+ })
+
+ it('should remove a token from its state', async function () {
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ await preferencesController.removeToken('0xa')
+
+ const tokens = preferencesController.getTokens()
+ assert.equal(tokens.length, 1, 'one token removed')
+
+ const [token1] = tokens
+ assert.deepEqual(token1, {address: '0xb', symbol: 'B', decimals: 5})
+ })
})
})