-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathserver_test.ts
More file actions
196 lines (182 loc) · 6.17 KB
/
server_test.ts
File metadata and controls
196 lines (182 loc) · 6.17 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { assert, assertEquals } from "@std/assert";
import { browserTest } from "./test_utils.ts";
Deno.test({
name: "basic md table with dollar signs",
sanitizeResources: false,
sanitizeOps: false,
}, async () => {
await browserTest("basicMarkdownTable", async (page) => {
await page.waitForSelector("table", { timeout: 1000 });
const tableExists = await page.evaluate(() => {
const table = document.querySelector("table");
return table !== null;
});
assert(tableExists, "Table should be rendered");
const getCellText = (row: number, col: number) => {
return page.evaluate(
(row, col) => {
const cell = document.querySelector(
`table tr:nth-child(${row}) td:nth-child(${col})`,
);
return cell ? cell.textContent?.trim() : null;
},
row,
col,
);
};
assert(
await getCellText(1, 1) === "Apple",
"First row, first column should be 'Apple'",
);
assert(
await getCellText(2, 2) === "2",
"Second row, second column should be '2'",
);
assert(
await getCellText(2, 3) === "$2.00",
"Second row, third column should be '$2.00'",
);
assert(
await getCellText(5, 4) === "$16.00",
"Fifth row, fourth column should be '$16.00'",
);
const getComputedStyle = (
selector: string,
property: keyof CSSStyleDeclaration,
) => {
return page.evaluate(
(selector, property) => {
const element = document.querySelector(selector);
if (!element) {
return null;
}
const style = globalThis.getComputedStyle(element);
return style[property];
},
selector,
property,
);
};
const firstRowBgColor = await getComputedStyle(
"body > main > table > tbody > tr:nth-child(1)",
"backgroundColor",
);
assert(
firstRowBgColor === "rgb(255, 255, 255)",
"Table background color should be white",
);
const secondRowBgColor = await getComputedStyle(
"body > main > table > tbody > tr:nth-child(2)",
"backgroundColor",
);
assert(
secondRowBgColor === "rgb(246, 248, 250)",
"Table background color should be white",
);
});
});
Deno.test(
{ name: "footnote with style", sanitizeResources: false, sanitizeOps: false },
async () => {
await browserTest("footnotes", async (page) => {
// 1. Test page jump on clicking footnote links
const scrollPositionBefore = await page.evaluate(() =>
globalThis.scrollY
);
await page.click("#footnote-ref-1"); // click the first footnote link. note that we select by id, not href
const scrollPositionAfter = await page.evaluate(() => globalThis.scrollY);
assert(scrollPositionAfter > scrollPositionBefore);
await page.click("#footnote-ref-bignote");
const scrollPositionAfter2 = await page.evaluate(() =>
globalThis.scrollY
);
assert(scrollPositionAfter2 === scrollPositionAfter);
await page.click("#footnote-1 > p > a");
const scrollPositionAfter3 = await page.evaluate(() =>
globalThis.scrollY
);
assert(scrollPositionAfter3 < scrollPositionAfter2);
assert(scrollPositionAfter3 > scrollPositionBefore);
// 2. Verify footnote link styling
const beforeContent = await page.evaluate(() => {
const element = document.querySelector("#footnote-ref-1");
if (element) {
return globalThis.getComputedStyle(element, "::before").content;
}
return null;
});
const afterContent = await page.evaluate(() => {
const element = document.querySelector("#footnote-ref-1");
if (element) {
return globalThis.getComputedStyle(element, "::after").content;
}
return null;
});
assertEquals(beforeContent, '"["');
assertEquals(afterContent, '"]"');
// 3. Check Visibility of "Footnotes" H2
const h2Style = await page.evaluate(() => {
const element = document.querySelector("#footnote-label");
if (element) {
const computedStyle = globalThis.getComputedStyle(element);
return {
position: computedStyle.position,
width: computedStyle.width,
height: computedStyle.height,
overflow: computedStyle.overflow,
clip: computedStyle.clip,
wordWrap: computedStyle.wordWrap,
border: computedStyle.border,
};
}
return null;
});
assert(h2Style);
assertEquals(h2Style.position, "absolute");
assertEquals(h2Style.width, "1px");
assertEquals(h2Style.height, "1px");
assertEquals(h2Style.overflow, "hidden");
assertEquals(h2Style.clip, "rect(0px, 0px, 0px, 0px)");
assertEquals(h2Style.wordWrap, "normal");
assertEquals(h2Style.border, "");
// 4. Verify blue box around the footnote after clicking
await page.click("#footnote-ref-1");
const footnoteStyle = await page.evaluate(() => {
const element = document.querySelector("#footnote-1");
if (element) {
return globalThis.getComputedStyle(element)
.outlineColor;
}
return null;
});
assertEquals(footnoteStyle, "rgb(31, 35, 40)");
});
},
);
Deno.test(
{ name: "yaml style", sanitizeResources: false, sanitizeOps: false },
async () => {
await browserTest("yaml", async (page) => {
const nameStyle = await page.evaluate(() => {
const element = document.querySelector(
"body > main > div > pre > span:nth-child(1)", // doe in the first line
);
if (element) {
return globalThis.getComputedStyle(element).color;
}
return null;
});
assertEquals(nameStyle, "rgb(207, 34, 46)");
const colonStyle = await page.evaluate(() => {
const element = document.querySelector(
"body > main > div > pre > span:nth-child(2)", // : in the first line
);
if (element) {
return globalThis.getComputedStyle(element).color;
}
return null;
});
assertEquals(colonStyle, "rgb(102, 57, 186)");
});
},
);