From 8d0739463d970deae2ebdd88eedac29e9c4379ff Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 24 May 2019 21:51:18 +0900 Subject: Move open parent and open root to background --- test/background/usecases/NavigateUseCase.test.ts | 82 ++++++++++++++++++++++ .../content/presenters/NavigationPresenter.test.ts | 9 --- 2 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 test/background/usecases/NavigateUseCase.test.ts (limited to 'test') diff --git a/test/background/usecases/NavigateUseCase.test.ts b/test/background/usecases/NavigateUseCase.test.ts new file mode 100644 index 0000000..13f3e99 --- /dev/null +++ b/test/background/usecases/NavigateUseCase.test.ts @@ -0,0 +1,82 @@ +import TabPresenter from '../../../src/background/presenters/TabPresenter'; +import NavigateUseCase from '../../../src/background/usecases/NavigateUseCase'; +import NavigateClient from '../../../src/background/clients/NavigateClient'; +// import { expect } from 'chai'; +import * as sinon from 'sinon'; + +describe('NavigateUseCase', () => { + let sut: NavigateUseCase; + let tabPresenter: TabPresenter; + let navigateClient: NavigateClient; + beforeEach(() => { + tabPresenter = new TabPresenter(); + navigateClient = new NavigateClient(); + sut = new NavigateUseCase(tabPresenter, navigateClient); + }); + + describe('#openParent()', async () => { + it.only('opens parent directory of file', async() => { + var stub = sinon.stub(tabPresenter, 'getCurrent'); + stub.returns(Promise.resolve({ url: 'https://google.com/fruits/yellow/banana' })) + + var mock = sinon.mock(tabPresenter); + mock.expects('open').withArgs('https://google.com/fruits/yellow/'); + + await sut.openParent(); + + mock.verify(); + }); + + it.only('opens parent directory of directory', async() => { + var stub = sinon.stub(tabPresenter, 'getCurrent'); + stub.returns(Promise.resolve({ url: 'https://google.com/fruits/yellow/' })) + + var mock = sinon.mock(tabPresenter); + mock.expects('open').withArgs('https://google.com/fruits/'); + + await sut.openParent(); + + mock.verify(); + }); + + it.only('removes hash', async() => { + var stub = sinon.stub(tabPresenter, 'getCurrent'); + stub.returns(Promise.resolve({ url: 'https://google.com/#top' })) + + var mock = sinon.mock(tabPresenter); + mock.expects('open').withArgs('https://google.com/'); + + await sut.openParent(); + + mock.verify(); + }); + + it.only('removes search query', async() => { + var stub = sinon.stub(tabPresenter, 'getCurrent'); + stub.returns(Promise.resolve({ url: 'https://google.com/search?q=apple' })) + + var mock = sinon.mock(tabPresenter); + mock.expects('open').withArgs('https://google.com/search'); + + await sut.openParent(); + + mock.verify(); + }); + }); + + describe('#openRoot()', () => { + it.only('opens root direectory', async() => { + var stub = sinon.stub(tabPresenter, 'getCurrent'); + stub.returns(Promise.resolve({ + url: 'https://google.com/seach?q=apple', + })) + + var mock = sinon.mock(tabPresenter); + mock.expects('open').withArgs('https://google.com'); + + await sut.openRoot(); + + mock.verify(); + }); + }); +}); diff --git a/test/content/presenters/NavigationPresenter.test.ts b/test/content/presenters/NavigationPresenter.test.ts index c1aca9a..5b6a8ca 100644 --- a/test/content/presenters/NavigationPresenter.test.ts +++ b/test/content/presenters/NavigationPresenter.test.ts @@ -132,13 +132,4 @@ describe('NavigationPresenter', () => { 'next page' )); }); - - describe('#parent', () => { - // NOTE: not able to test location - it('removes hash', () => { - window.location.hash = '#section-1'; - sut.openParent(); - expect(document.location.hash).to.be.empty; - }); - }); }); -- cgit v1.2.3 From 45a10d93c741da285937e6d13401d39c65ee609d Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 24 May 2019 22:22:02 +0900 Subject: Fix NavigateUseCase test --- test/background/usecases/NavigateUseCase.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/background/usecases/NavigateUseCase.test.ts b/test/background/usecases/NavigateUseCase.test.ts index 13f3e99..ecbf888 100644 --- a/test/background/usecases/NavigateUseCase.test.ts +++ b/test/background/usecases/NavigateUseCase.test.ts @@ -15,7 +15,7 @@ describe('NavigateUseCase', () => { }); describe('#openParent()', async () => { - it.only('opens parent directory of file', async() => { + it('opens parent directory of file', async() => { var stub = sinon.stub(tabPresenter, 'getCurrent'); stub.returns(Promise.resolve({ url: 'https://google.com/fruits/yellow/banana' })) @@ -27,7 +27,7 @@ describe('NavigateUseCase', () => { mock.verify(); }); - it.only('opens parent directory of directory', async() => { + it('opens parent directory of directory', async() => { var stub = sinon.stub(tabPresenter, 'getCurrent'); stub.returns(Promise.resolve({ url: 'https://google.com/fruits/yellow/' })) @@ -39,7 +39,7 @@ describe('NavigateUseCase', () => { mock.verify(); }); - it.only('removes hash', async() => { + it('removes hash', async() => { var stub = sinon.stub(tabPresenter, 'getCurrent'); stub.returns(Promise.resolve({ url: 'https://google.com/#top' })) @@ -51,7 +51,7 @@ describe('NavigateUseCase', () => { mock.verify(); }); - it.only('removes search query', async() => { + it('removes search query', async() => { var stub = sinon.stub(tabPresenter, 'getCurrent'); stub.returns(Promise.resolve({ url: 'https://google.com/search?q=apple' })) @@ -65,7 +65,7 @@ describe('NavigateUseCase', () => { }); describe('#openRoot()', () => { - it.only('opens root direectory', async() => { + it('opens root direectory', async() => { var stub = sinon.stub(tabPresenter, 'getCurrent'); stub.returns(Promise.resolve({ url: 'https://google.com/seach?q=apple', -- cgit v1.2.3 From 5133705ddeb5f9d67768897b1c4a0778d436eb45 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 26 May 2019 12:35:38 +0900 Subject: Fix ClipboardUseCase.test --- test/content/usecases/ClipboardUseCase.test.ts | 83 +++++++++++--------------- 1 file changed, 35 insertions(+), 48 deletions(-) (limited to 'test') diff --git a/test/content/usecases/ClipboardUseCase.test.ts b/test/content/usecases/ClipboardUseCase.test.ts index 551c3f7..a863651 100644 --- a/test/content/usecases/ClipboardUseCase.test.ts +++ b/test/content/usecases/ClipboardUseCase.test.ts @@ -1,82 +1,69 @@ import ClipboardRepository from '../../../src/content/repositories/ClipboardRepository'; import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository'; -import TabsClient from '../../../src/content/client/TabsClient'; -import MockConsoleClient from '../mock/MockConsoleClient'; import ClipboardUseCase from '../../../src/content/usecases/ClipboardUseCase'; -import { expect } from 'chai'; - -class MockClipboardRepository implements ClipboardRepository { - public clipboard: string; - - constructor() { - this.clipboard = ''; - } - - read(): string { - return this.clipboard; - } - - write(text: string): void { - this.clipboard = text; - } -} - -class MockTabsClient implements TabsClient { - public last: string; - - constructor() { - this.last = ''; - } +import OperationClient from '../../../src/content/client/OperationClient'; +import ConsoleClient from '../../../src/content/client/ConsoleClient'; - openUrl(url: string, _newTab: boolean): Promise { - this.last = url; - return Promise.resolve(); - } -} +import * as sinon from 'sinon'; +import { expect } from 'chai'; describe('ClipboardUseCase', () => { - let repository: MockClipboardRepository; - let client: MockTabsClient; - let consoleClient: MockConsoleClient; + let clipboardRepository: ClipboardRepository; + let operationClient: OperationClient; + let consoleClient: ConsoleClient; let sut: ClipboardUseCase; beforeEach(() => { - repository = new MockClipboardRepository(); - client = new MockTabsClient(); - consoleClient = new MockConsoleClient(); + var modal = {}; + + clipboardRepository = { read() {}, write(_) {} }; + operationClient = { internalOpenUrl(_) {} }; + consoleClient = { info(_) {}}; sut = new ClipboardUseCase( - repository, + clipboardRepository, new SettingRepositoryImpl(), - client, - consoleClient + consoleClient, + operationClient, ); }); describe('#yankCurrentURL', () => { it('yanks current url', async () => { + let href = window.location.href; + var mockRepository = sinon.mock(clipboardRepository); + mockRepository.expects('write').withArgs(href); + var mockConsoleClient = sinon.mock(consoleClient); + mockConsoleClient.expects('info').withArgs('Yanked ' + href); + let yanked = await sut.yankCurrentURL(); - expect(yanked).to.equal(window.location.href); - expect(repository.clipboard).to.equal(yanked); - expect(consoleClient.text).to.equal('Yanked ' + yanked); + expect(yanked).to.equal(href); + mockRepository.verify(); + mockConsoleClient.verify(); }); }); describe('#openOrSearch', () => { it('opens url from the clipboard', async () => { let url = 'https://github.com/ueokande/vim-vixen' - repository.clipboard = url; + sinon.stub(clipboardRepository, 'read').returns(url); + let mockOperationClient = sinon.mock(operationClient); + mockOperationClient.expects('internalOpenUrl').withArgs(url, true); + await sut.openOrSearch(true); - expect(client.last).to.equal(url); + mockOperationClient.verify(); }); it('opens search results from the clipboard', async () => { - repository.clipboard = 'banana'; + let url = 'https://google.com/search?q=banana'; + sinon.stub(clipboardRepository, 'read').returns('banana'); + let mockOperationClient = sinon.mock(operationClient); + mockOperationClient.expects('internalOpenUrl').withArgs(url, true); + await sut.openOrSearch(true); - expect(client.last).to.equal('https://google.com/search?q=banana'); + mockOperationClient.verify(); }); }); }); - -- cgit v1.2.3