diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/main.js | 4 | ||||
-rw-r--r-- | test/shared/versions/index.test.js | 55 | ||||
-rw-r--r-- | test/shared/versions/storage.test.js | 39 |
3 files changed, 98 insertions, 0 deletions
diff --git a/test/main.js b/test/main.js index d923aaa..3aeae69 100644 --- a/test/main.js +++ b/test/main.js @@ -1,2 +1,6 @@ import chai from 'chai'; +const browserFake = require('webextensions-api-fake'); +const browser = browserFake(); + global.expect = chai.expect; +global.browser = browser; diff --git a/test/shared/versions/index.test.js b/test/shared/versions/index.test.js new file mode 100644 index 0000000..3bb307a --- /dev/null +++ b/test/shared/versions/index.test.js @@ -0,0 +1,55 @@ +import * as versions from 'shared/versions'; +import manifest from '../../../manifest.json'; + +describe("shared/versions/storage", () => { + describe('#checkUpdated', () => { + beforeEach(() => { + return browser.storage.local.remove('version'); + }); + + it('return true if no previous versions', () => { + return Promise.resolve().then(() => { + return versions.checkUpdated(); + }).then((updated) => { + expect(updated).to.be.true; + }); + }); + + it('return true if updated', () => { + return Promise.resolve().then(() => { + return browser.storage.local.set({ version: '0.001' }); + }).then(() => { + return versions.checkUpdated(); + }).then((updated) => { + expect(updated).to.be.true; + }); + }); + + it('return false if not updated', () => { + return Promise.resolve().then(() => { + return browser.storage.local.set({ version: manifest.version }); + }).then(() => { + return versions.checkUpdated(); + }).then((updated) => { + expect(updated).to.be.false; + }); + }); + }); + + describe('#commit', () => { + beforeEach(() => { + return browser.storage.local.remove('version'); + }); + + it('saves current version from manifest.json', () => { + return Promise.resolve().then(() => { + return versions.commit(); + }).then(() => { + return browser.storage.local.get('version'); + }).then(({version}) => { + expect(version).to.be.a('string'); + expect(version).to.equal(manifest.version); + }); + }); + }); +}); diff --git a/test/shared/versions/storage.test.js b/test/shared/versions/storage.test.js new file mode 100644 index 0000000..bcfa259 --- /dev/null +++ b/test/shared/versions/storage.test.js @@ -0,0 +1,39 @@ +import * as storage from 'shared/versions/storage'; + +describe("shared/versions/storage", () => { + describe('#load', () => { + beforeEach(() => { + return browser.storage.local.remove('version'); + }); + + it('loads saved version', () => { + return Promise.resolve().then(() => { + return browser.storage.local.set({ version: '1.2.3' }); + }).then(() => { + return storage.load(); + }).then((version) => { + expect(version).to.equal('1.2.3'); + }); + }); + + it('returns undefined if no versions in storage', () => { + return Promise.resolve().then(() => { + return storage.load(); + }).then((version) => { + expect(version).to.be.a('undefined'); + }); + }); + }); + + describe('#save', () => { + it('saves version string', () => { + return Promise.resolve().then(() => { + return storage.save('2.3.4'); + }).then(() => { + return browser.storage.local.get('version'); + }).then(({version}) => { + expect(version).to.equal('2.3.4'); + }); + }); + }); +}); |