aboutsummaryrefslogtreecommitdiff
path: root/e2e
diff options
context:
space:
mode:
Diffstat (limited to 'e2e')
-rw-r--r--e2e/find.test.ts113
-rw-r--r--e2e/lib/Console.ts5
-rw-r--r--e2e/lib/Page.ts18
3 files changed, 136 insertions, 0 deletions
diff --git a/e2e/find.test.ts b/e2e/find.test.ts
new file mode 100644
index 0000000..74097ab
--- /dev/null
+++ b/e2e/find.test.ts
@@ -0,0 +1,113 @@
+import * as path from 'path';
+import * as assert from 'assert';
+
+import eventually from './eventually';
+import TestServer from './lib/TestServer';
+import { Builder, Lanthan } from 'lanthan';
+import { Key, WebDriver } from 'selenium-webdriver';
+import Page from './lib/Page';
+
+describe("find test", () => {
+ const server = new TestServer().receiveContent('/',
+ `<!DOCTYPE html><html lang="en"><body>--hello--hello--hello--</body></html>`,
+ );
+ let lanthan: Lanthan;
+ let webdriver: WebDriver;
+ let page: Page;
+
+ before(async() => {
+ lanthan = await Builder
+ .forBrowser('firefox')
+ .spyAddon(path.join(__dirname, '..'))
+ .build();
+ webdriver = lanthan.getWebDriver();
+ await server.start();
+ });
+
+ after(async() => {
+ await server.stop();
+ if (lanthan) {
+ await lanthan.quit();
+ }
+ });
+
+ beforeEach(async() => {
+ page = await Page.navigateTo(webdriver, server.url());
+ });
+
+ it('starts searching', async() => {
+ await page.sendKeys('/');
+ const console = await page.getConsole();
+ await console.execCommand("hello");
+ await page.switchToTop();
+
+ let selection = await page.getSelection();
+ assert.deepStrictEqual(selection, { from: 2, to: 7 });
+
+ // search next keyword
+ await page.sendKeys("n");
+ selection = await page.getSelection();
+ assert.deepStrictEqual(selection, { from: 9, to: 14 });
+
+ // search previous keyword
+ await page.sendKeys(Key.SHIFT, "N");
+ selection = await page.getSelection();
+ assert.deepStrictEqual(selection, { from: 2, to: 7 });
+
+ // search previous keyword by wrap-search
+ await page.sendKeys(Key.SHIFT, "N");
+ selection = await page.getSelection();
+ assert.deepStrictEqual(selection, { from: 16, to: 21 });
+ });
+
+ it('shows error if pattern not found', async() => {
+ await page.sendKeys('/');
+ let console = await page.getConsole();
+ await console.execCommand('world');
+
+ await page.switchToTop();
+ const selection = await page.getSelection();
+ assert.deepStrictEqual(selection, { from: 0, to: 0 });
+
+ await eventually(async() => {
+ console = await page.getConsole();
+ const message = await console.getErrorMessage();
+ assert.strictEqual(message, 'Pattern not found: world');
+ });
+ });
+
+ it('search with last keyword if keyword is empty', async() => {
+ await page.sendKeys('/');
+ let console = await page.getConsole();
+ await console.execCommand('hello');
+ await page.switchToTop();
+
+ await page.clearSelection();
+ let selection = await page.getSelection();
+ assert.deepStrictEqual(selection, { from: 0, to: 0 });
+
+ await page.sendKeys('/');
+ console = await page.getConsole();
+ await console.execCommand('');
+ await page.switchToTop();
+
+ selection = await page.getSelection();
+ assert.deepStrictEqual(selection, { from: 2, to: 7 });
+ });
+
+ it('search with last keyword on new page', async() => {
+ await page.sendKeys('/');
+ const console = await page.getConsole();
+ await console.execCommand('hello');
+
+ await page.switchToTop();
+ await page.sendKeys('n');
+ let selection = await page.getSelection();
+ assert.deepStrictEqual(selection, { from: 9, to: 14 });
+
+ page = await Page.navigateTo(webdriver, server.url());
+ await page.sendKeys('n');
+ selection = await page.getSelection();
+ assert.deepStrictEqual(selection, { from: 2, to: 7 });
+ });
+});
diff --git a/e2e/lib/Console.ts b/e2e/lib/Console.ts
index 6a82387..e3bd2d6 100644
--- a/e2e/lib/Console.ts
+++ b/e2e/lib/Console.ts
@@ -35,6 +35,11 @@ export class Console {
return p.getText();
}
+ async getInformationMessage(): Promise<string> {
+ const p = await this.webdriver.findElement(By.css('.vimvixen-console-info'));
+ return p.getText();
+ }
+
async inputKeys(...keys: string[]) {
const input = await this.webdriver.findElement(By.css('input'));
await input.sendKeys(...keys);
diff --git a/e2e/lib/Page.ts b/e2e/lib/Page.ts
index ad3f454..31605cb 100644
--- a/e2e/lib/Page.ts
+++ b/e2e/lib/Page.ts
@@ -6,6 +6,11 @@ type Hint = {
text: string,
};
+type Selection = {
+ from: number,
+ to: number,
+};
+
export default class Page {
private constructor(private webdriver: WebDriver) {
}
@@ -66,6 +71,19 @@ export default class Page {
return this.webdriver.executeScript(() => window.document.documentElement.clientHeight);
}
+ async getSelection(): Promise<Selection> {
+ const obj = await this.webdriver.executeScript(`return window.getSelection();`) as any;
+ return { from: obj.anchorOffset, to: obj.focusOffset };
+ }
+
+ async clearSelection(): Promise<void> {
+ await this.webdriver.executeScript(`window.getSelection().removeAllRanges()`);
+ }
+
+ async switchToTop(): Promise<void> {
+ await this.webdriver.switchTo().defaultContent();
+ }
+
async waitAndGetHints(): Promise<Hint[]> {
await this.webdriver.wait(until.elementsLocated(By.css('.vimvixen-hint')));