From a26d8a8a1bed48a77e062914c120a23ace7bb8cf Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 24 Feb 2019 20:54:35 +0900 Subject: Capitalize background scripts --- test/background/domains/GlobalMark.test.js | 11 ++++++ test/background/domains/global-mark.test.js | 11 ------ .../infrastructures/MemoryStorage.test.js | 44 ++++++++++++++++++++++ .../infrastructures/memory-storage.test.js | 44 ---------------------- test/background/repositories/Mark.test.js | 26 +++++++++++++ test/background/repositories/Version.js | 34 +++++++++++++++++ test/background/repositories/mark.test.js | 26 ------------- test/background/repositories/version.js | 34 ----------------- 8 files changed, 115 insertions(+), 115 deletions(-) create mode 100644 test/background/domains/GlobalMark.test.js delete mode 100644 test/background/domains/global-mark.test.js create mode 100644 test/background/infrastructures/MemoryStorage.test.js delete mode 100644 test/background/infrastructures/memory-storage.test.js create mode 100644 test/background/repositories/Mark.test.js create mode 100644 test/background/repositories/Version.js delete mode 100644 test/background/repositories/mark.test.js delete mode 100644 test/background/repositories/version.js (limited to 'test/background') diff --git a/test/background/domains/GlobalMark.test.js b/test/background/domains/GlobalMark.test.js new file mode 100644 index 0000000..ed636e9 --- /dev/null +++ b/test/background/domains/GlobalMark.test.js @@ -0,0 +1,11 @@ +import GlobalMark from 'background/domains/GlobalMark'; + +describe('background/domains/global-mark', () => { + describe('constructor and getter', () => { + let mark = new GlobalMark(1, 'http://example.com', 10, 30); + expect(mark.tabId).to.equal(1); + expect(mark.url).to.equal('http://example.com'); + expect(mark.x).to.equal(10); + expect(mark.y).to.equal(30); + }); +}); diff --git a/test/background/domains/global-mark.test.js b/test/background/domains/global-mark.test.js deleted file mode 100644 index bdf1ea6..0000000 --- a/test/background/domains/global-mark.test.js +++ /dev/null @@ -1,11 +0,0 @@ -import GlobalMark from 'background/domains/global-mark'; - -describe('background/domains/global-mark', () => { - describe('constructor and getter', () => { - let mark = new GlobalMark(1, 'http://example.com', 10, 30); - expect(mark.tabId).to.equal(1); - expect(mark.url).to.equal('http://example.com'); - expect(mark.x).to.equal(10); - expect(mark.y).to.equal(30); - }); -}); diff --git a/test/background/infrastructures/MemoryStorage.test.js b/test/background/infrastructures/MemoryStorage.test.js new file mode 100644 index 0000000..95d3780 --- /dev/null +++ b/test/background/infrastructures/MemoryStorage.test.js @@ -0,0 +1,44 @@ +import MemoryStorage from 'background/infrastructures/MemoryStorage'; + +describe("background/infrastructures/memory-storage", () => { + it('stores values', () => { + let cache = new MemoryStorage(); + cache.set('number', 123); + expect(cache.get('number')).to.equal(123); + + cache.set('string', '123'); + expect(cache.get('string')).to.equal('123'); + + cache.set('object', { hello: '123' }); + expect(cache.get('object')).to.deep.equal({ hello: '123' }); + }); + + it('returns undefined if no keys', () => { + let cache = new MemoryStorage(); + expect(cache.get('no-keys')).to.be.undefined; + }) + + it('stored on shared memory', () => { + let cache = new MemoryStorage(); + cache.set('red', 'apple'); + + cache = new MemoryStorage(); + let got = cache.get('red'); + expect(got).to.equal('apple'); + }); + + it('stored cloned objects', () => { + let cache = new MemoryStorage(); + let recipe = { sugar: '300g' }; + cache.set('recipe', recipe); + + recipe.salt = '20g' + let got = cache.get('recipe', recipe); + expect(got).to.deep.equal({ sugar: '300g' }); + }); + + it('throws an error with unserializable objects', () => { + let cache = new MemoryStorage(); + expect(() => cache.set('fn', setTimeout)).to.throw(); + }) +}); diff --git a/test/background/infrastructures/memory-storage.test.js b/test/background/infrastructures/memory-storage.test.js deleted file mode 100644 index 8871749..0000000 --- a/test/background/infrastructures/memory-storage.test.js +++ /dev/null @@ -1,44 +0,0 @@ -import MemoryStorage from 'background/infrastructures/memory-storage'; - -describe("background/infrastructures/memory-storage", () => { - it('stores values', () => { - let cache = new MemoryStorage(); - cache.set('number', 123); - expect(cache.get('number')).to.equal(123); - - cache.set('string', '123'); - expect(cache.get('string')).to.equal('123'); - - cache.set('object', { hello: '123' }); - expect(cache.get('object')).to.deep.equal({ hello: '123' }); - }); - - it('returns undefined if no keys', () => { - let cache = new MemoryStorage(); - expect(cache.get('no-keys')).to.be.undefined; - }) - - it('stored on shared memory', () => { - let cache = new MemoryStorage(); - cache.set('red', 'apple'); - - cache = new MemoryStorage(); - let got = cache.get('red'); - expect(got).to.equal('apple'); - }); - - it('stored cloned objects', () => { - let cache = new MemoryStorage(); - let recipe = { sugar: '300g' }; - cache.set('recipe', recipe); - - recipe.salt = '20g' - let got = cache.get('recipe', recipe); - expect(got).to.deep.equal({ sugar: '300g' }); - }); - - it('throws an error with unserializable objects', () => { - let cache = new MemoryStorage(); - expect(() => cache.set('fn', setTimeout)).to.throw(); - }) -}); diff --git a/test/background/repositories/Mark.test.js b/test/background/repositories/Mark.test.js new file mode 100644 index 0000000..2a5b099 --- /dev/null +++ b/test/background/repositories/Mark.test.js @@ -0,0 +1,26 @@ +import MarkRepository from 'background/repositories/MarkRepository'; +import GlobalMark from 'background/domains/GlobalMark'; + +describe('background/repositories/mark', () => { + let repository; + + beforeEach(() => { + repository = new MarkRepository; + }); + + it('get and set', async() => { + let mark = new GlobalMark(1, 'http://example.com', 10, 30); + + repository.setMark('A', mark); + + let got = await repository.getMark('A'); + expect(got).to.be.a('object'); + expect(got.tabId).to.equal(1); + expect(got.url).to.equal('http://example.com'); + expect(got.x).to.equal(10); + expect(got.y).to.equal(30); + + got = await repository.getMark('B'); + expect(got).to.be.undefined; + }); +}); diff --git a/test/background/repositories/Version.js b/test/background/repositories/Version.js new file mode 100644 index 0000000..c7fa88b --- /dev/null +++ b/test/background/repositories/Version.js @@ -0,0 +1,34 @@ +import VersionRepository from 'background/repositories/Version'; + +describe("background/repositories/version", () => { + let versionRepository; + + beforeEach(() => { + versionRepository = new VersionRepository; + }); + + describe('#get', () => { + beforeEach(() => { + return browser.storage.local.remove('version'); + }); + + it('loads saved version', async() => { + await browser.storage.local.set({ version: '1.2.3' }); + let version = await this.versionRepository.get(); + 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('#update', () => { + it('saves version string', async() => { + await versionRepository.update('2.3.4'); + let { version } = await browser.storage.local.get('version'); + expect(version).to.equal('2.3.4'); + }); + }); +}); diff --git a/test/background/repositories/mark.test.js b/test/background/repositories/mark.test.js deleted file mode 100644 index 4f71f62..0000000 --- a/test/background/repositories/mark.test.js +++ /dev/null @@ -1,26 +0,0 @@ -import MarkRepository from 'background/repositories/mark'; -import GlobalMark from 'background/domains/global-mark'; - -describe('background/repositories/mark', () => { - let repository; - - beforeEach(() => { - repository = new MarkRepository; - }); - - it('get and set', async() => { - let mark = new GlobalMark(1, 'http://example.com', 10, 30); - - repository.setMark('A', mark); - - let got = await repository.getMark('A'); - expect(got).to.be.a('object'); - expect(got.tabId).to.equal(1); - expect(got.url).to.equal('http://example.com'); - expect(got.x).to.equal(10); - expect(got.y).to.equal(30); - - got = await repository.getMark('B'); - expect(got).to.be.undefined; - }); -}); diff --git a/test/background/repositories/version.js b/test/background/repositories/version.js deleted file mode 100644 index 8510ae6..0000000 --- a/test/background/repositories/version.js +++ /dev/null @@ -1,34 +0,0 @@ -import VersionRepository from 'background/repositories/version'; - -describe("background/repositories/version", () => { - let versionRepository; - - beforeEach(() => { - versionRepository = new VersionRepository; - }); - - describe('#get', () => { - beforeEach(() => { - return browser.storage.local.remove('version'); - }); - - it('loads saved version', async() => { - await browser.storage.local.set({ version: '1.2.3' }); - let version = await this.versionRepository.get(); - 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('#update', () => { - it('saves version string', async() => { - await versionRepository.update('2.3.4'); - let { version } = await browser.storage.local.get('version'); - expect(version).to.equal('2.3.4'); - }); - }); -}); -- cgit v1.2.3