aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-10-01 13:37:09 +0000
committerGitHub <noreply@github.com>2019-10-01 13:37:09 +0000
commit620d4bc03e11ae88e2162cb4acdf88b6bded50e5 (patch)
tree6d1ed59cde68ff0cb721e6ac0d3c9554a07bc2bf
parent1afdb51feaa860c6dd0542b362925fb553eabf4c (diff)
parentcb08141a55e9f067f73f3d9c387c6af5bb05b608 (diff)
Merge pull request #649 from ueokande/help-page
Add :help command to show help page
-rw-r--r--e2e/command_help.test.ts49
-rw-r--r--e2e/completion.test.ts2
-rw-r--r--src/background/controllers/CommandController.ts3
-rw-r--r--src/background/domains/CommandDocs.ts1
-rw-r--r--src/background/presenters/HelpPresenter.ts10
-rw-r--r--src/background/usecases/CommandUseCase.ts8
6 files changed, 71 insertions, 2 deletions
diff --git a/e2e/command_help.test.ts b/e2e/command_help.test.ts
new file mode 100644
index 0000000..9269d49
--- /dev/null
+++ b/e2e/command_help.test.ts
@@ -0,0 +1,49 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+import TestServer from './lib/TestServer';
+import eventually from './eventually';
+import { Builder, Lanthan } from 'lanthan';
+import { WebDriver } from 'selenium-webdriver';
+import Page from './lib/Page';
+
+describe("help command test", () => {
+ let server = new TestServer();
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let browser: any;
+ let page: Page;
+
+ before(async() => {
+ lanthan = await Builder
+ .forBrowser('firefox')
+ .spyAddon(path.join(__dirname, '..'))
+ .build();
+ webdriver = lanthan.getWebDriver();
+ browser = lanthan.getWebExtBrowser();
+
+ await server.start();
+ });
+
+ after(async() => {
+ await server.stop();
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ beforeEach(async() => {
+ page = await Page.navigateTo(webdriver, server.url());
+ })
+
+ it('should open help page by help command ', async() => {
+ let console = await page.showConsole();
+ await console.execCommand('help');
+
+ await eventually(async() => {
+ let tabs = await browser.tabs.query({ active: true });
+ assert.strictEqual(tabs[0].url, 'https://ueokande.github.io/vim-vixen/')
+ });
+ });
+});
+
diff --git a/e2e/completion.test.ts b/e2e/completion.test.ts
index 28c1913..afa4432 100644
--- a/e2e/completion.test.ts
+++ b/e2e/completion.test.ts
@@ -40,7 +40,7 @@ describe("general completion test", () => {
let console = await page.showConsole();
let items = await console.getCompletions();
- assert.strictEqual(items.length, 10);
+ assert.strictEqual(items.length, 11);
assert.deepStrictEqual(items[0], { type: 'title', text: 'Console Command' });
assert.ok(items[1].text.startsWith('set'))
assert.ok(items[2].text.startsWith('open'))
diff --git a/src/background/controllers/CommandController.ts b/src/background/controllers/CommandController.ts
index 2ad1683..11fed01 100644
--- a/src/background/controllers/CommandController.ts
+++ b/src/background/controllers/CommandController.ts
@@ -96,6 +96,9 @@ export default class CommandController {
return this.commandIndicator.quitAll();
case 'set':
return this.commandIndicator.set(keywords);
+ case 'h':
+ case 'help':
+ return this.commandIndicator.help();
}
throw new Error(words[0] + ' command is not defined');
}
diff --git a/src/background/domains/CommandDocs.ts b/src/background/domains/CommandDocs.ts
index 25ea62a..e926851 100644
--- a/src/background/domains/CommandDocs.ts
+++ b/src/background/domains/CommandDocs.ts
@@ -8,4 +8,5 @@ export default {
bdeletes: 'Close all tabs matched by keywords',
quit: 'Close the current tab',
quitall: 'Close all tabs',
+ help: 'Open Vim Vixen help in new tab',
} as {[key: string]: string};
diff --git a/src/background/presenters/HelpPresenter.ts b/src/background/presenters/HelpPresenter.ts
new file mode 100644
index 0000000..f5c3a6b
--- /dev/null
+++ b/src/background/presenters/HelpPresenter.ts
@@ -0,0 +1,10 @@
+import { injectable } from 'tsyringe';
+
+const url = 'https://ueokande.github.io/vim-vixen/';
+
+@injectable()
+export default class HelpPresenter {
+ async open(): Promise<void> {
+ await browser.tabs.create({ url, active: true });
+ }
+}
diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts
index a526cfc..d757215 100644
--- a/src/background/usecases/CommandUseCase.ts
+++ b/src/background/usecases/CommandUseCase.ts
@@ -4,6 +4,7 @@ import * as parsers from './parsers';
import * as urls from '../../shared/urls';
import TabPresenter from '../presenters/TabPresenter';
import WindowPresenter from '../presenters/WindowPresenter';
+import HelpPresenter from '../presenters/HelpPresenter';
import SettingRepository from '../repositories/SettingRepository';
import BookmarkRepository from '../repositories/BookmarkRepository';
import ConsoleClient from '../infrastructures/ConsoleClient';
@@ -15,6 +16,7 @@ export default class CommandIndicator {
constructor(
private tabPresenter: TabPresenter,
private windowPresenter: WindowPresenter,
+ private helpPresenter: HelpPresenter,
private settingRepository: SettingRepository,
private bookmarkRepository: BookmarkRepository,
private consoleClient: ConsoleClient,
@@ -136,7 +138,11 @@ export default class CommandIndicator {
return this.contentMessageClient.broadcastSettingsChanged();
}
- async urlOrSearch(keywords: string): Promise<any> {
+ help(): Promise<void> {
+ return this.helpPresenter.open();
+ }
+
+ private async urlOrSearch(keywords: string): Promise<any> {
let settings = await this.settingRepository.get();
return urls.searchUrl(keywords, settings.search);
}