Merge pull request #649 from ueokande/help-page

Add :help command to show help page
jh-changes
Shin'ya Ueoka 5 years ago committed by GitHub
commit 620d4bc03e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      e2e/command_help.test.ts
  2. 2
      e2e/completion.test.ts
  3. 3
      src/background/controllers/CommandController.ts
  4. 1
      src/background/domains/CommandDocs.ts
  5. 10
      src/background/presenters/HelpPresenter.ts
  6. 8
      src/background/usecases/CommandUseCase.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/')
});
});
});

@ -40,7 +40,7 @@ describe("general completion test", () => {
let console = await page.showConsole(); let console = await page.showConsole();
let items = await console.getCompletions(); 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.deepStrictEqual(items[0], { type: 'title', text: 'Console Command' });
assert.ok(items[1].text.startsWith('set')) assert.ok(items[1].text.startsWith('set'))
assert.ok(items[2].text.startsWith('open')) assert.ok(items[2].text.startsWith('open'))

@ -96,6 +96,9 @@ export default class CommandController {
return this.commandIndicator.quitAll(); return this.commandIndicator.quitAll();
case 'set': case 'set':
return this.commandIndicator.set(keywords); return this.commandIndicator.set(keywords);
case 'h':
case 'help':
return this.commandIndicator.help();
} }
throw new Error(words[0] + ' command is not defined'); throw new Error(words[0] + ' command is not defined');
} }

@ -8,4 +8,5 @@ export default {
bdeletes: 'Close all tabs matched by keywords', bdeletes: 'Close all tabs matched by keywords',
quit: 'Close the current tab', quit: 'Close the current tab',
quitall: 'Close all tabs', quitall: 'Close all tabs',
help: 'Open Vim Vixen help in new tab',
} as {[key: string]: string}; } as {[key: string]: string};

@ -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 });
}
}

@ -4,6 +4,7 @@ import * as parsers from './parsers';
import * as urls from '../../shared/urls'; import * as urls from '../../shared/urls';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
import WindowPresenter from '../presenters/WindowPresenter'; import WindowPresenter from '../presenters/WindowPresenter';
import HelpPresenter from '../presenters/HelpPresenter';
import SettingRepository from '../repositories/SettingRepository'; import SettingRepository from '../repositories/SettingRepository';
import BookmarkRepository from '../repositories/BookmarkRepository'; import BookmarkRepository from '../repositories/BookmarkRepository';
import ConsoleClient from '../infrastructures/ConsoleClient'; import ConsoleClient from '../infrastructures/ConsoleClient';
@ -15,6 +16,7 @@ export default class CommandIndicator {
constructor( constructor(
private tabPresenter: TabPresenter, private tabPresenter: TabPresenter,
private windowPresenter: WindowPresenter, private windowPresenter: WindowPresenter,
private helpPresenter: HelpPresenter,
private settingRepository: SettingRepository, private settingRepository: SettingRepository,
private bookmarkRepository: BookmarkRepository, private bookmarkRepository: BookmarkRepository,
private consoleClient: ConsoleClient, private consoleClient: ConsoleClient,
@ -136,7 +138,11 @@ export default class CommandIndicator {
return this.contentMessageClient.broadcastSettingsChanged(); 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(); let settings = await this.settingRepository.get();
return urls.searchUrl(keywords, settings.search); return urls.searchUrl(keywords, settings.search);
} }