-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
96 lines (78 loc) · 2.97 KB
/
test.js
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
// https://stackoverflow.com/questions/951021
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
docs.keydown = async function (e) {
console.log("Key down:" + e.key);
if (e.key == "r" && e.altKey) {
e.preventDefault();
e.stopPropagation();
docs.pressLetters("t");
docs.undo();
docs.pressLetters("T");
docs.undo();
docs.redo();
docs.pasteText("his line should start with only one 'T'.\n");
await sleep(500);
docs.pressLetters("Heytypo");
for (var i = 0; i < "typo".length; i++) {
docs.backspace();
}
docs.pasteText("\nThis doc's name is: " + docs.name +
" and the id is: " + docs.id + "\n" +
"There should be a blank line after this:\n" +
"\nAnd before this.");
await sleep(500);
docs.setColor("gray");
docs.pasteText("\nThis text should be in gray.");
await sleep(500);
docs.setColor("black");
docs.pasteText("\nThis should be back in black.\n");
await sleep(500);
docs.toggleSuperscript();
docs.pasteText("This should be superscript.");
await sleep(500);
docs.toggleSuperscript();
docs.pasteText("Back to normal.");
await sleep(500);
docs.toggleSubscript();
docs.pasteText("Subscript.");
await sleep(500);
docs.toggleSubscript();
docs.pasteText("Back to normal.");
await sleep(500);
docs.toggleBold();
docs.pasteText("\nThis should be bold.");
await sleep(500);
docs.toggleBold();
docs.pasteText("Back to normal.\n");
await sleep(500);
docs.insertLink("https://example.com/", "This should be a link to https://example.com/");
docs.pasteText("Back to normal.\n");
await sleep(500);
docs.pasteText("A few tests require user input:\n" +
"1) Select something (or not) and press alt+s to " +
"check the selection methods.\n" +
"2) Press alt+c to check the cursor method.\n" +
"Your cursor should be between these quotes: \"\"\n");
await sleep(500);
docs.pressKey(docs.codeFromKey("ArrowLeft"));
docs.pressKey(docs.codeFromKey("ArrowLeft"));
docs.getCurrentParagraphText(function (text) {
var truth = "Your cursor should be between these quotes: \"\"";
console.log("getCurrentParagraphText got: " + text.trim());
});
return false;
}
if (e.key == "s" && e.altKey) {
docs.getSelection(function (selection) {
alert("You had selected: \"" + selection + "\"");
});
}
if (e.key == "c" && e.altKey) {
docs.pasteText("\nMaking cursor 10px wide...\n");
docs.setCursorWidth("10px");
}
return true;
};
console.log("Press alt + r to begin the test.");