1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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 });
});
});
|