diff options
Diffstat (limited to 'test/background/usecases')
-rw-r--r-- | test/background/usecases/NavigateUseCase.test.ts | 94 | ||||
-rw-r--r-- | test/background/usecases/SettingUseCase.test.ts | 73 | ||||
-rw-r--r-- | test/background/usecases/parsers.test.ts | 48 |
3 files changed, 127 insertions, 88 deletions
diff --git a/test/background/usecases/NavigateUseCase.test.ts b/test/background/usecases/NavigateUseCase.test.ts index 7ad0e4f..7263627 100644 --- a/test/background/usecases/NavigateUseCase.test.ts +++ b/test/background/usecases/NavigateUseCase.test.ts @@ -1,8 +1,8 @@ import "reflect-metadata"; -import TabPresenter from '../../../src/background/presenters/TabPresenter'; -import NavigateUseCase from '../../../src/background/usecases/NavigateUseCase'; -import NavigateClient from '../../../src/background/clients/NavigateClient'; -import * as sinon from 'sinon'; +import TabPresenter from "../../../src/background/presenters/TabPresenter"; +import NavigateUseCase from "../../../src/background/usecases/NavigateUseCase"; +import NavigateClient from "../../../src/background/clients/NavigateClient"; +import * as sinon from "sinon"; class MockTabPresenter implements TabPresenter { create(_url: string, _opts?: object): Promise<browser.tabs.Tab> { @@ -17,7 +17,10 @@ class MockTabPresenter implements TabPresenter { throw new Error("not implemented"); } - getByKeyword(_keyword: string, _excludePinned: boolean): Promise<browser.tabs.Tab[]> { + getByKeyword( + _keyword: string, + _excludePinned: boolean + ): Promise<browser.tabs.Tab[]> { throw new Error("not implemented"); } @@ -33,7 +36,9 @@ class MockTabPresenter implements TabPresenter { throw new Error("not implemented"); } - onSelected(_listener: (arg: { tabId: number; windowId: number }) => void): void { + onSelected( + _listener: (arg: { tabId: number; windowId: number }) => void + ): void { throw new Error("not implemented"); } @@ -66,7 +71,7 @@ class MockTabPresenter implements TabPresenter { } } -describe('NavigateUseCase', () => { +describe("NavigateUseCase", () => { let sut: NavigateUseCase; let tabPresenter: TabPresenter; let navigateClient: NavigateClient; @@ -80,7 +85,7 @@ describe('NavigateUseCase', () => { const newTab = (url: string): browser.tabs.Tab => { return { index: 0, - title: 'dummy title', + title: "dummy title", url: url, active: true, hidden: false, @@ -91,53 +96,67 @@ describe('NavigateUseCase', () => { lastAccessed: 1585446733000, pinned: false, selected: false, - windowId: 0 + windowId: 0, }; }; - describe('#openParent()', async () => { - it('opens parent directory of file', async() => { - sinon.stub(tabPresenter, 'getCurrent') - .returns(Promise.resolve(newTab('https://google.com/fruits/yellow/banana'))); + describe("#openParent()", async () => { + it("opens parent directory of file", async () => { + sinon + .stub(tabPresenter, "getCurrent") + .returns( + Promise.resolve(newTab("https://google.com/fruits/yellow/banana")) + ); - const mock = sinon.mock(tabPresenter) - .expects('open').withArgs('https://google.com/fruits/yellow/'); + const mock = sinon + .mock(tabPresenter) + .expects("open") + .withArgs("https://google.com/fruits/yellow/"); await sut.openParent(); mock.verify(); }); - it('opens parent directory of directory', async() => { - sinon.stub(tabPresenter, 'getCurrent') - .returns(Promise.resolve(newTab('https://google.com/fruits/yellow/'))); + it("opens parent directory of directory", async () => { + sinon + .stub(tabPresenter, "getCurrent") + .returns(Promise.resolve(newTab("https://google.com/fruits/yellow/"))); - const mock = sinon.mock(tabPresenter) - .expects('open').withArgs('https://google.com/fruits/'); + const mock = sinon + .mock(tabPresenter) + .expects("open") + .withArgs("https://google.com/fruits/"); await sut.openParent(); mock.verify(); }); - it('removes hash', async() => { - sinon.stub(tabPresenter, 'getCurrent') - .returns(Promise.resolve(newTab('https://google.com/#top'))); + it("removes hash", async () => { + sinon + .stub(tabPresenter, "getCurrent") + .returns(Promise.resolve(newTab("https://google.com/#top"))); - const mock = sinon.mock(tabPresenter) - .expects('open').withArgs('https://google.com/'); + const mock = sinon + .mock(tabPresenter) + .expects("open") + .withArgs("https://google.com/"); await sut.openParent(); mock.verify(); }); - it('removes search query', async() => { - sinon.stub(tabPresenter, 'getCurrent') - .returns(Promise.resolve(newTab('https://google.com/search?q=apple'))); + it("removes search query", async () => { + sinon + .stub(tabPresenter, "getCurrent") + .returns(Promise.resolve(newTab("https://google.com/search?q=apple"))); - const mock = sinon.mock(tabPresenter) - .expects('open').withArgs('https://google.com/search'); + const mock = sinon + .mock(tabPresenter) + .expects("open") + .withArgs("https://google.com/search"); await sut.openParent(); @@ -145,13 +164,16 @@ describe('NavigateUseCase', () => { }); }); - describe('#openRoot()', () => { - it('opens root direectory', async() => { - sinon.stub(tabPresenter, 'getCurrent') - .returns(Promise.resolve(newTab('https://google.com/seach?q=apple'))); + describe("#openRoot()", () => { + it("opens root direectory", async () => { + sinon + .stub(tabPresenter, "getCurrent") + .returns(Promise.resolve(newTab("https://google.com/seach?q=apple"))); - const mock = sinon.mock(tabPresenter) - .expects('open').withArgs('https://google.com'); + const mock = sinon + .mock(tabPresenter) + .expects("open") + .withArgs("https://google.com"); await sut.openRoot(); diff --git a/test/background/usecases/SettingUseCase.test.ts b/test/background/usecases/SettingUseCase.test.ts index bfa599c..c604e91 100644 --- a/test/background/usecases/SettingUseCase.test.ts +++ b/test/background/usecases/SettingUseCase.test.ts @@ -1,21 +1,22 @@ import "reflect-metadata"; import SettingUseCase from "../../../src/background/usecases/SettingUseCase"; import SettingRepository from "../../../src/background/repositories/SettingRepository"; -import SettingData, {JSONTextSettings} from "../../../src/shared/SettingData"; +import SettingData, { JSONTextSettings } from "../../../src/shared/SettingData"; import CachedSettingRepository from "../../../src/background/repositories/CachedSettingRepository"; -import Settings, {DefaultSetting} from "../../../src/shared/settings/Settings"; +import Settings, { + DefaultSetting, +} from "../../../src/shared/settings/Settings"; import Notifier from "../../../src/background/presenters/Notifier"; -import {expect} from "chai"; +import { expect } from "chai"; import Properties from "../../../src/shared/settings/Properties"; -import sinon from 'sinon'; +import sinon from "sinon"; class MockSettingRepository implements SettingRepository { load(): Promise<SettingData | null> { throw new Error("not implemented"); } - onChange(_: () => void): void { - } + onChange(_: () => void): void {} } class MockCachedSettingRepository implements CachedSettingRepository { @@ -46,12 +47,12 @@ class NopNotifier implements Notifier { } } -describe('SettingUseCase', () => { - let localSettingRepository : SettingRepository; - let syncSettingRepository : SettingRepository; - let cachedSettingRepository : CachedSettingRepository; +describe("SettingUseCase", () => { + let localSettingRepository: SettingRepository; + let syncSettingRepository: SettingRepository; + let cachedSettingRepository: CachedSettingRepository; let notifier: Notifier; - let sut : SettingUseCase; + let sut: SettingUseCase; beforeEach(() => { localSettingRepository = new MockSettingRepository(); @@ -66,34 +67,34 @@ describe('SettingUseCase', () => { ); }); - describe('getCached', () => { + describe("getCached", () => { it("returns cached settings", async () => { const settings = new Settings({ keymaps: DefaultSetting.keymaps, search: DefaultSetting.search, blacklist: DefaultSetting.blacklist, properties: new Properties({ - hintchars: "abcd1234" + hintchars: "abcd1234", }), }); - sinon.stub(cachedSettingRepository, "get") + sinon + .stub(cachedSettingRepository, "get") .returns(Promise.resolve(settings)); const got = await sut.getCached(); expect(got.properties.hintchars).to.equal("abcd1234"); - }); }); describe("reload", () => { context("when sync is not set", () => { - it("loads settings from local storage", async() => { + it("loads settings from local storage", async () => { const settings = new Settings({ keymaps: DefaultSetting.keymaps, search: DefaultSetting.search, blacklist: DefaultSetting.blacklist, properties: new Properties({ - hintchars: "abcd1234" + hintchars: "abcd1234", }), }); const settingData = SettingData.fromJSON({ @@ -101,9 +102,11 @@ describe('SettingUseCase', () => { json: JSONTextSettings.fromSettings(settings).toJSONText(), }); - sinon.stub(syncSettingRepository, "load") + sinon + .stub(syncSettingRepository, "load") .returns(Promise.resolve(null)); - sinon.stub(localSettingRepository, "load") + sinon + .stub(localSettingRepository, "load") .returns(Promise.resolve(settingData)); await sut.reload(); @@ -114,13 +117,13 @@ describe('SettingUseCase', () => { }); context("when local is not set", () => { - it("loads settings from sync storage", async() => { + it("loads settings from sync storage", async () => { const settings = new Settings({ keymaps: DefaultSetting.keymaps, search: DefaultSetting.search, blacklist: DefaultSetting.blacklist, properties: new Properties({ - hintchars: "aaaa1111" + hintchars: "aaaa1111", }), }); const settingData = SettingData.fromJSON({ @@ -128,9 +131,11 @@ describe('SettingUseCase', () => { json: JSONTextSettings.fromSettings(settings).toJSONText(), }); - sinon.stub(syncSettingRepository, "load") + sinon + .stub(syncSettingRepository, "load") .returns(Promise.resolve(settingData)); - sinon.stub(localSettingRepository, "load") + sinon + .stub(localSettingRepository, "load") .returns(Promise.resolve(null)); await sut.reload(); @@ -141,21 +146,23 @@ describe('SettingUseCase', () => { }); context("neither local nor sync not set", () => { - it("loads default settings", async() => { - it("loads settings from sync storage", async() => { - sinon.stub(syncSettingRepository, "load") + it("loads default settings", async () => { + it("loads settings from sync storage", async () => { + sinon + .stub(syncSettingRepository, "load") .returns(Promise.resolve(null)); - sinon.stub(localSettingRepository, "load") + sinon + .stub(localSettingRepository, "load") .returns(Promise.resolve(null)); await sut.reload(); const current = await cachedSettingRepository.get(); - expect(current.properties.hintchars).to.equal(DefaultSetting.properties.hintchars); + expect(current.properties.hintchars).to.equal( + DefaultSetting.properties.hintchars + ); }); - - }) - }) - }) + }); + }); + }); }); - diff --git a/test/background/usecases/parsers.test.ts b/test/background/usecases/parsers.test.ts index d08de0d..019b56e 100644 --- a/test/background/usecases/parsers.test.ts +++ b/test/background/usecases/parsers.test.ts @@ -1,34 +1,44 @@ -import * as parsers from 'background/usecases/parsers'; +import * as parsers from "../../../src/background/usecases/parsers"; +import { expect } from "chai"; describe("shared/commands/parsers", () => { describe("#parsers.parseSetOption", () => { - it('parse set string', () => { - const [key, value] = parsers.parseSetOption('hintchars=abcdefgh'); - expect(key).to.equal('hintchars'); - expect(value).to.equal('abcdefgh'); + it("parse set string", () => { + const [key, value] = parsers.parseSetOption("hintchars=abcdefgh"); + expect(key).to.equal("hintchars"); + expect(value).to.equal("abcdefgh"); }); - it('parse set empty string', () => { - const [key, value] = parsers.parseSetOption('hintchars='); - expect(key).to.equal('hintchars'); - expect(value).to.equal(''); + it("parse set empty string", () => { + const [key, value] = parsers.parseSetOption("hintchars="); + expect(key).to.equal("hintchars"); + expect(value).to.equal(""); }); - it('parse set boolean', () => { - let [key, value] = parsers.parseSetOption('smoothscroll'); - expect(key).to.equal('smoothscroll'); + it("parse set boolean", () => { + let [key, value] = parsers.parseSetOption("smoothscroll"); + expect(key).to.equal("smoothscroll"); expect(value).to.be.true; - [key, value] = parsers.parseSetOption('nosmoothscroll'); - expect(key).to.equal('smoothscroll'); + [key, value] = parsers.parseSetOption("nosmoothscroll"); + expect(key).to.equal("smoothscroll"); expect(value).to.be.false; }); - it('throws error on unknown property', () => { - expect(() => parsers.parseSetOption('encoding=utf-8')).to.throw(Error, 'Unknown'); - expect(() => parsers.parseSetOption('paste')).to.throw(Error, 'Unknown'); - expect(() => parsers.parseSetOption('nopaste')).to.throw(Error, 'Unknown'); - expect(() => parsers.parseSetOption('smoothscroll=yes')).to.throw(Error, 'Invalid argument'); + it("throws error on unknown property", () => { + expect(() => parsers.parseSetOption("encoding=utf-8")).to.throw( + Error, + "Unknown" + ); + expect(() => parsers.parseSetOption("paste")).to.throw(Error, "Unknown"); + expect(() => parsers.parseSetOption("nopaste")).to.throw( + Error, + "Unknown" + ); + expect(() => parsers.parseSetOption("smoothscroll=yes")).to.throw( + Error, + "Invalid argument" + ); }); }); }); |