Repository navigation
Expand file tree
/
Copy pathsample10.test.mjs
More file actions
100 lines (90 loc) · 4.04 KB
/
Copy pathsample10.test.mjs
File metadata and controls
100 lines (90 loc) · 4.04 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
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
// Sample 10, the WaynesWorld add-in that ships with the IDE, operated end to
// end: its toolbar buttons, its tool window, a message box answered twice, a
// notification and a DEBUG CONSOLE line. One of the two scenarios that finish
// Stage 1 of WIP.HelpAddin.md.
//
// Run it with addin-test.bat, which gives it a lane; on its own it is skipped.
import assert from "node:assert/strict";
import path from "node:path";
import { before, test } from "node:test";
import { fileURLToPath } from "node:url";
import { loadedAddins } from "../../scripts/lib/tb-ide-addins.mjs";
import { consoleMark, linesSince } from "../../scripts/lib/tb-ide-console.mjs";
import {
answerMessageBox,
click,
messageBoxes,
notifications,
toolWindow,
waitFor,
} from "../../scripts/lib/tb-operate.mjs";
import { scenario } from "./scenario.mjs";
const HOST = path.join(path.dirname(fileURLToPath(import.meta.url)), "host");
const W = "WaynesWindowData"; // the id Sample 10 gives ToolWindows.Add
// The message box on top, with its text trimmed, or undefined.
async function topBox(c) {
const b = (await messageBoxes(c)).at(-1);
return b && { ...b, text: b.text.trim() };
}
const noBoxes = (c) => waitFor(c, async (c) => (await messageBoxes(c)).length === 0);
scenario("Sample 10: WaynesWorld", (lane) => {
let c;
before(async () => {
await lane.addSample("Sample 10");
c = await lane.open(HOST);
});
test("the compiler loads the add-in, which reports the project", async () => {
const names = (await loadedAddins(c)).map((a) => a.name);
assert.ok(names.includes("WaynesWorld AddIn"), `loaded: ${JSON.stringify(names)}`);
const lines = (await linesSince(c)).filter((l) => l.startsWith("[WaynesWorldAddin]"));
assert.equal(lines.length, 5, `its OnProjectLoaded lines: ${JSON.stringify(lines)}`);
assert.ok(lines.includes("[WaynesWorldAddin] ProjectName: AddinHost"), JSON.stringify(lines));
});
test("its image button shows a message box", async () => {
await click(c, "addinButton-TestImageButton");
const box = await waitFor(c, topBox);
assert.deepEqual(box, { title: "News alert...", text: "You clicked the image button!", buttons: ["OK"] });
await answerMessageBox(c, "OK");
assert.ok(await noBoxes(c), "the message box did not close");
});
test("its other button opens its tool window", async () => {
await click(c, "addinButton-ShowToolWindow");
const w = await waitFor(c, async (c) => {
const t = await toolWindow(c, W);
return t?.visible && t;
});
assert.ok(w, "the tool window did not appear");
assert.match(w.text, /11\. ShowMessageBox/);
});
test("a three-button message box, answered with its second button", async () => {
await click(c, { toolWindow: W, css: "#myButton11" });
const first = await waitFor(c, topBox);
assert.deepEqual(first, {
title: "Choose an option",
text: "Hello there from WaynesWorldAddIn!",
buttons: ["button1", "button2", "button3"],
});
await answerMessageBox(c, "button2");
// The add-in's call returns the button's index, and it answers with a second box.
const second = await waitFor(c, async (c) => {
const b = await topBox(c);
return b?.title === "option" && b;
});
assert.deepEqual(second, { title: "option", text: "you selected button2", buttons: ["ok"] });
await answerMessageBox(c, "ok");
assert.ok(await noBoxes(c), "a message box is still open");
});
test("a notification", async () => {
await click(c, { toolWindow: W, css: "#myButton10" });
const shown = await waitFor(c, async (c) =>
(await notifications(c)).find((t) => t.trim() === "Hello there from WaynesWorldAddIn!"),
);
assert.ok(shown, `notifications: ${JSON.stringify(await notifications(c))}`);
});
test("a DEBUG CONSOLE line", async () => {
const mark = await consoleMark(c);
await click(c, { toolWindow: W, css: "#myButton7" });
const text = await waitFor(c, async (c) => (await linesSince(c, mark)).filter(Boolean).join("\n"));
assert.equal(text, "Hello there from WaynesWorldAddIn!");
});
});