diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-06-07 05:05:13 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-06-07 05:05:13 +0800 |
commit | d5c378b09aff6e56585f9d05779d72c4e7919d5b (patch) | |
tree | 7e0fb017321c486273a67ae9a000ae8ed735d4bb /test/unit | |
parent | 8dcba9a606f6d3593a5eedbc96452b9828179262 (diff) | |
download | tangerine-wallet-browser-d5c378b09aff6e56585f9d05779d72c4e7919d5b.tar tangerine-wallet-browser-d5c378b09aff6e56585f9d05779d72c4e7919d5b.tar.gz tangerine-wallet-browser-d5c378b09aff6e56585f9d05779d72c4e7919d5b.tar.bz2 tangerine-wallet-browser-d5c378b09aff6e56585f9d05779d72c4e7919d5b.tar.lz tangerine-wallet-browser-d5c378b09aff6e56585f9d05779d72c4e7919d5b.tar.xz tangerine-wallet-browser-d5c378b09aff6e56585f9d05779d72c4e7919d5b.tar.zst tangerine-wallet-browser-d5c378b09aff6e56585f9d05779d72c4e7919d5b.zip |
Cache identicons
Fixes #197
Also as a side effect, by creating this `iconFactory.cache` object, we have a convenient place for specifying stock icons for known contracts!
We can just hard-code image addresses in the `ui/lib/icon-factory.js` cache instantiation, and those values will be injected into the identicon image tag `src` attributes.
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/lib/icon-factory-test.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/unit/lib/icon-factory-test.js b/test/unit/lib/icon-factory-test.js new file mode 100644 index 000000000..2f24d408c --- /dev/null +++ b/test/unit/lib/icon-factory-test.js @@ -0,0 +1,31 @@ +const assert = require('assert') +const sinon = require('sinon') + +const path = require('path') +const IconFactoryGen = require(path.join(__dirname, '..', '..', '..', 'ui', 'lib', 'icon-factory.js')) + +describe('icon-factory', function() { + let iconFactory, address, diameter + + beforeEach(function() { + iconFactory = IconFactoryGen((d,n) => 'stubicon') + address = '0x012345671234567890' + diameter = 50 + }) + + it('should return a data-uri string for any address and diameter', function() { + const output = iconFactory.iconForAddress(address, diameter) + assert.ok(output.indexOf('data:image/svg') === 0) + assert.equal(output, iconFactory.cache[address][diameter]) + }) + + it('should default to cache first', function() { + const testOutput = 'foo' + const mockSizeCache = {} + mockSizeCache[diameter] = testOutput + iconFactory.cache[address] = mockSizeCache + + const output = iconFactory.iconForAddress(address, diameter) + assert.equal(output, testOutput) + }) +}) |