From 067da88d06fbffca323ecdbaf8b1011f88225219 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 11 Jul 2018 21:01:48 +0900 Subject: Move versions to background --- test/background/shared/versions/index.test.js | 40 +++++++++++++++++++++++++ test/background/shared/versions/storage.test.js | 28 +++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 test/background/shared/versions/index.test.js create mode 100644 test/background/shared/versions/storage.test.js (limited to 'test/background/shared') diff --git a/test/background/shared/versions/index.test.js b/test/background/shared/versions/index.test.js new file mode 100644 index 0000000..d65dd9a --- /dev/null +++ b/test/background/shared/versions/index.test.js @@ -0,0 +1,40 @@ +import * as versions from 'background/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', async() => { + let updated = await versions.checkUpdated(); + expect(updated).to.be.true; + }); + + it('return true if updated', async() => { + await browser.storage.local.set({ version: '0.001' }); + let updated = await versions.checkUpdated(); + expect(updated).to.be.true; + }); + + it('return false if not updated', async() => { + await browser.storage.local.set({ version: manifest.version }); + let updated = await versions.checkUpdated(); + expect(updated).to.be.false; + }); + }); + + describe('#commit', () => { + beforeEach(() => { + return browser.storage.local.remove('version'); + }); + + it('saves current version from manifest.json', async() => { + await versions.commit(); + let { version } = await browser.storage.local.get('version'); + expect(version).to.be.a('string'); + expect(version).to.equal(manifest.version); + }); + }); +}); diff --git a/test/background/shared/versions/storage.test.js b/test/background/shared/versions/storage.test.js new file mode 100644 index 0000000..f452516 --- /dev/null +++ b/test/background/shared/versions/storage.test.js @@ -0,0 +1,28 @@ +import * as storage from 'background/shared/versions/storage'; + +describe("shared/versions/storage", () => { + describe('#load', () => { + beforeEach(() => { + return browser.storage.local.remove('version'); + }); + + it('loads saved version', async() => { + await browser.storage.local.set({ version: '1.2.3' }); + let version = await storage.load(); + expect(version).to.equal('1.2.3'); + }); + + it('returns undefined if no versions in storage', async() => { + let version = await storage.load(); + expect(version).to.be.a('undefined'); + }); + }); + + describe('#save', () => { + it('saves version string', async() => { + await storage.save('2.3.4'); + let { version } = await browser.storage.local.get('version'); + expect(version).to.equal('2.3.4'); + }); + }); +}); -- cgit v1.2.3