aboutsummaryrefslogtreecommitdiff
path: root/test/background/completion
diff options
context:
space:
mode:
Diffstat (limited to 'test/background/completion')
-rw-r--r--test/background/completion/OpenCompletionUseCase.test.ts (renamed from test/background/completion/CompletionUseCase.test.ts)8
-rw-r--r--test/background/completion/TabCompletionUseCase.test.ts105
2 files changed, 109 insertions, 4 deletions
diff --git a/test/background/completion/CompletionUseCase.test.ts b/test/background/completion/OpenCompletionUseCase.test.ts
index 0d58e45..421ce69 100644
--- a/test/background/completion/CompletionUseCase.test.ts
+++ b/test/background/completion/OpenCompletionUseCase.test.ts
@@ -2,7 +2,7 @@ import "reflect-metadata";
import CompletionType from "../../../src/shared/CompletionType";
import BookmarkRepository, {BookmarkItem} from "../../../src/background/completion/BookmarkRepository";
import HistoryRepository, {HistoryItem} from "../../../src/background/completion/HistoryRepository";
-import CompletionUseCase from "../../../src/background/completion/CompletionUseCase";
+import OpenCompletionUseCase from "../../../src/background/completion/OpenCompletionUseCase";
import CachedSettingRepository from "../../../src/background/repositories/CachedSettingRepository";
import Settings, {DefaultSetting} from "../../../src/shared/settings/Settings";
import { expect } from 'chai';
@@ -36,17 +36,17 @@ class MockSettingRepository implements CachedSettingRepository {
}
}
-describe('CompletionUseCase', () => {
+describe('OpenCompletionUseCase', () => {
let bookmarkRepository: MockBookmarkRepository;
let historyRepository: MockHistoryRepository;
let settingRepository: MockSettingRepository;
- let sut: CompletionUseCase;
+ let sut: OpenCompletionUseCase;
beforeEach(() => {
bookmarkRepository = new MockBookmarkRepository();
historyRepository = new MockHistoryRepository();
settingRepository = new MockSettingRepository();
- sut = new CompletionUseCase(bookmarkRepository, historyRepository, settingRepository)
+ sut = new OpenCompletionUseCase(bookmarkRepository, historyRepository, settingRepository)
});
describe('#getCompletionTypes', () => {
diff --git a/test/background/completion/TabCompletionUseCase.test.ts b/test/background/completion/TabCompletionUseCase.test.ts
new file mode 100644
index 0000000..e2c7c19
--- /dev/null
+++ b/test/background/completion/TabCompletionUseCase.test.ts
@@ -0,0 +1,105 @@
+import "reflect-metadata"
+import TabRepositoryImpl from "../../../src/background/completion/impl/TabRepositoryImpl";
+import {Tab} from "../../../src/background/completion/TabRepository";
+import TabPresenter from "../../../src/background/presenters/TabPresenter";
+import TabCompletionUseCase from "../../../src/background/completion/TabCompletionUseCase";
+import sinon from 'sinon';
+import { expect } from 'chai';
+import TabFlag from "../../../src/shared/TabFlag";
+
+class MockTabRepository implements TabRepositoryImpl {
+ async queryTabs(_query: string, _excludePinned: boolean): Promise<Tab[]> {
+ throw new Error("not implemented")
+ }
+}
+
+class MockTabPresenter implements TabPresenter {
+ create(_url: string, _opts?: object): Promise<browser.tabs.Tab> {
+ throw new Error("not implemented")
+ }
+
+ duplicate(_id: number): Promise<browser.tabs.Tab> {
+ throw new Error("not implemented")
+ }
+
+ getAll(): Promise<browser.tabs.Tab[]> {
+ throw new Error("not implemented")
+ }
+
+ getByKeyword(_keyword: string, _excludePinned: boolean): Promise<browser.tabs.Tab[]> {
+ throw new Error("not implemented")
+ }
+
+ getCurrent(): Promise<browser.tabs.Tab> {
+ throw new Error("not implemented")
+ }
+
+ getLastSelectedId(): Promise<number | undefined> {
+ throw new Error("not implemented")
+ }
+
+ getZoom(_tabId: number): Promise<number> {
+ throw new Error("not implemented")
+ }
+
+ onSelected(_listener: (arg: { tabId: number; windowId: number }) => void): void {
+ throw new Error("not implemented")
+ }
+
+ open(_url: string, _tabId?: number): Promise<browser.tabs.Tab> {
+ throw new Error("not implemented")
+ }
+
+ reload(_tabId: number, _cache: boolean): Promise<void> {
+ throw new Error("not implemented")
+ }
+
+ remove(_ids: number[]): Promise<void> {
+ throw new Error("not implemented")
+ }
+
+ reopen(): Promise<any> {
+ throw new Error("not implemented")
+ }
+
+ select(_tabId: number): Promise<void> {
+ throw new Error("not implemented")
+ }
+
+ setPinned(_tabId: number, _pinned: boolean): Promise<void> {
+ throw new Error("not implemented")
+ }
+
+ setZoom(_tabId: number, _factor: number): Promise<void> {
+ throw new Error("not implemented")
+ }
+}
+
+describe('TabCompletionUseCase', () => {
+ let tabRepository: MockTabRepository;
+ let tabPresenter: TabPresenter;
+ let sut: TabCompletionUseCase;
+
+ beforeEach(() => {
+ tabRepository = new MockTabRepository();
+ tabPresenter = new MockTabPresenter();
+ sut = new TabCompletionUseCase(tabRepository, tabPresenter)
+ });
+
+ describe('#queryTabs', () => {
+ it("returns tab items", async () => {
+ sinon.stub(tabRepository, 'queryTabs').returns(Promise.resolve([
+ { id: 10, index: 0, title: 'Google', url: 'https://google.com/', faviconUrl: 'https://google.com/favicon.ico', active: true },
+ { id: 11, index: 1, title: 'Yahoo', url: 'https://yahoo.com/', faviconUrl: 'https://yahoo.com/favicon.ico', active: false },
+ { id: 12, index: 2, title: 'Bing', url: 'https://bing.com/', active: false },
+ ]));
+ sinon.stub(tabPresenter, 'getLastSelectedId').returns(Promise.resolve(11));
+
+ expect(await sut.queryTabs("", false)).to.deep.equal([
+ { index: 0, title: 'Google', url: 'https://google.com/', faviconUrl: 'https://google.com/favicon.ico', flag: TabFlag.CurrentTab },
+ { index: 1, title: 'Yahoo', url: 'https://yahoo.com/', faviconUrl: 'https://yahoo.com/favicon.ico', flag: TabFlag.LastTab },
+ { index: 2, title: 'Bing', url: 'https://bing.com/', faviconUrl: undefined, flag: TabFlag.None },
+ ]);
+ })
+ });
+}); \ No newline at end of file