aboutsummaryrefslogtreecommitdiff
path: root/test/content
diff options
context:
space:
mode:
Diffstat (limited to 'test/content')
-rw-r--r--test/content/usecases/ClipboardUseCase.test.ts76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/content/usecases/ClipboardUseCase.test.ts b/test/content/usecases/ClipboardUseCase.test.ts
new file mode 100644
index 0000000..862ee8a
--- /dev/null
+++ b/test/content/usecases/ClipboardUseCase.test.ts
@@ -0,0 +1,76 @@
+import ClipboardRepository from '../../../src/content/repositories/ClipboardRepository';
+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 = '';
+ }
+
+ openUrl(url: string, _newTab: boolean): Promise<void> {
+ this.last = url;
+ return Promise.resolve();
+ }
+}
+
+describe('ClipboardUseCase', () => {
+ let repository: MockClipboardRepository;
+ let client: MockTabsClient;
+ let consoleClient: MockConsoleClient;
+ let sut: ClipboardUseCase;
+
+ beforeEach(() => {
+ repository = new MockClipboardRepository();
+ client = new MockTabsClient();
+ consoleClient = new MockConsoleClient();
+ sut = new ClipboardUseCase({ repository, client: client, consoleClient });
+ });
+
+ describe('#yankCurrentURL', () => {
+ it('yanks current url', async () => {
+ 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);
+ });
+ });
+
+ describe('#openOrSearch', () => {
+ it('opens url from the clipboard', async () => {
+ let url = 'https://github.com/ueokande/vim-vixen'
+ repository.clipboard = url;
+ await sut.openOrSearch(true);
+
+ expect(client.last).to.equal(url);
+ });
+
+ it('opens search results from the clipboard', async () => {
+ repository.clipboard = 'banana';
+ await sut.openOrSearch(true);
+
+ expect(client.last).to.equal('https://google.com/search?q=banana');
+ });
+ });
+});
+