-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathlink_hints_test.js
More file actions
66 lines (58 loc) · 2 KB
/
Copy pathlink_hints_test.js
File metadata and controls
66 lines (58 loc) · 2 KB
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
import "./test_helper.js";
import "../../lib/keyboard_utils.js";
import "../../lib/settings.js";
import "../../content_scripts/mode.js";
import "../../content_scripts/link_hints.js";
context("activateModeToOpenInNewWindow", () => {
setup(async () => {
await Settings.onLoaded();
});
teardown(async () => {
await Settings.clear();
});
should("activate link hints with open-in-new-window mode", () => {
let capturedMode = null;
stub(LinkHints, "activateMode", (count, { mode }) => {
capturedMode = mode;
});
LinkHints.activateModeToOpenInNewWindow(3);
assert.equal("new-window", capturedMode.name);
assert.equal("Open link in new window", capturedMode.indicator);
});
should("linkActivator sends openUrlInNewWindow for links with href", () => {
let sentMessage = null;
stub(chrome.runtime, "sendMessage", (msg) => {
sentMessage = msg;
});
// Capture the mode object via the stub, then exercise its linkActivator.
let capturedMode = null;
stub(LinkHints, "activateMode", (_count, { mode }) => {
capturedMode = mode;
});
LinkHints.activateModeToOpenInNewWindow(1);
const mockLink = { href: "https://example.com" };
capturedMode.linkActivator(mockLink);
assert.equal("openUrlInNewWindow", sentMessage.handler);
assert.equal("https://example.com", sentMessage.url);
});
});
context("With insufficient link characters", () => {
setup(async () => {
await Settings.onLoaded();
});
teardown(async () => {
await Settings.clear();
});
should("throw error in AlphabetHints", async () => {
await Settings.set("linkHintCharacters", "ab");
new AlphabetHints();
await Settings.set("linkHintCharacters", "a");
assert.throwsError(() => new AlphabetHints(), "Error");
});
should("throw error in FilterHints", async () => {
await Settings.set("linkHintNumbers", "12");
new FilterHints();
await Settings.set("linkHintNumbers", "1");
assert.throwsError(() => new FilterHints(), "Error");
});
});