33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import test from "node:test";
|
|
|
|
const homePageSource = await readFile(
|
|
new URL("../src/pages/HomePage.tsx", import.meta.url),
|
|
"utf8",
|
|
);
|
|
|
|
test("shares the four history columns between records and the loading state", () => {
|
|
const columns = sourceForFunction("HistoryTableColumns");
|
|
const skeleton = sourceForFunction("HistoryRecordsSkeleton");
|
|
const records = sourceForFunction("HistoryRecords");
|
|
|
|
assert.equal(columns.match(/<col(?:\s|\/|>)/g)?.length, 4);
|
|
assert.deepEqual(
|
|
Array.from(columns.matchAll(/<th\b[^>]*>\s*([^<]+?)\s*<\/th>/g), (match) => match[1]),
|
|
["일정", "내전", "결과", "참가"],
|
|
);
|
|
assert.match(skeleton, /<HistoryTableColumns\s*\/>/);
|
|
assert.match(records, /<HistoryTableColumns\s*\/>/);
|
|
assert.doesNotMatch(skeleton, /<HistoryResult\b/);
|
|
});
|
|
|
|
function sourceForFunction(name: string): string {
|
|
const start = homePageSource.indexOf(`function ${name}(`);
|
|
assert.notEqual(start, -1, `${name} should exist`);
|
|
|
|
const nextFunction = homePageSource.indexOf("\nfunction ", start + 1);
|
|
assert.notEqual(nextFunction, -1, `${name} should have a following function`);
|
|
return homePageSource.slice(start, nextFunction);
|
|
}
|