forked from ueokande/vimmatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfollow_properties.test.ts
102 lines (84 loc) · 2.93 KB
/
follow_properties.test.ts
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
import { test, expect } from "./lib/fixture";
import { newSingleContentServer } from "./lib/servers";
import SettingRepository from "./lib/SettingRepository";
const setupHintchars = async (api: typeof browser) => {
await new SettingRepository(api).save({
keymaps: {
":": { type: "command.show" },
f: { type: "follow.start", newTab: false },
F: { type: "follow.start", newTab: true, background: false },
"<C-F>": { type: "follow.start", newTab: true, background: true },
},
properties: {
hintchars: "jk",
},
});
};
const resetSettings = async (api: typeof browser) => {
await new SettingRepository(api).save({});
};
const server = newSingleContentServer(`
<!DOCTYPE html>
<html lang="en"><body>
<a href="/">link1</a>
<a href="/">link2</a>
<a href="/">link3</a>
<a href="/">link4</a>
<a href="/">link5</a>
</body></html>
`);
test.beforeAll(async () => {
await server.start();
});
test.afterEach(async ({ api }) => {
await resetSettings(api);
});
test.afterAll(async () => {
await server.stop();
});
test("should show hints with hintchars by settings", async ({ page, api }) => {
await setupHintchars(api);
await page.goto(server.url());
await page.keyboard.press("f");
await expect
.poll(() => page.locator("[data-vimmatic-hint]:visible").allInnerTexts())
.toEqual(["J", "K", "JJ", "JK", "KJ"]);
await page.keyboard.press("j");
await expect
.poll(() => page.locator("[data-vimmatic-hint]:visible").allInnerTexts())
.toEqual(["J", "JJ", "JK"]);
});
test("should open link into a new tab", async ({ page, api }) => {
const { id: windowId } = await api.windows.getCurrent();
await setupHintchars(api);
await page.goto(server.url());
await page.keyboard.press("Shift+F");
await page.locator("[data-vimmatic-hint]:visible").first().waitFor();
await new Promise((resolve) => setTimeout(resolve, 1000));
await page.keyboard.press("j");
await page.keyboard.press("j");
await expect
.poll(() => api.tabs.query({ windowId }))
.toMatchObject([{ active: false }, { active: true }]);
});
test("should open link into new tab in background", async ({ page, api }) => {
const { id: windowId } = await api.windows.getCurrent();
await setupHintchars(api);
await page.goto(server.url());
await page.keyboard.press("Control+f");
await page.locator("[data-vimmatic-hint]:visible").first().waitFor();
await page.keyboard.press("j");
await page.keyboard.press("j");
await expect
.poll(() => api.tabs.query({ windowId }))
.toMatchObject([{ active: true }, { active: false }]);
});
test("should show hints with set hintchars", async ({ page }) => {
await page.goto(server.url());
await page.keyboard.type(":set hintchars=abc");
await page.keyboard.press("Enter");
await page.keyboard.press("f");
await expect
.poll(() => page.locator("[data-vimmatic-hint]:visible").allInnerTexts())
.toEqual(["A", "B", "C", "AA", "AB"]);
});