mirror of
https://github.com/nianzhibai/91.git
synced 2026-06-25 21:22:40 +08:00
33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
|
|
const modalSource = readFileSync(
|
|
new URL("../src/admin/Modal.tsx", import.meta.url),
|
|
"utf8"
|
|
);
|
|
|
|
test("admin modal does not reset focus when close handler identity changes", () => {
|
|
assert.match(modalSource, /const onCloseRef = useRef\(onClose\);/);
|
|
assert.match(modalSource, /onCloseRef\.current = onClose;/);
|
|
assert.match(modalSource, /onCloseRef\.current\(\);/);
|
|
assert.match(modalSource, /window\.clearTimeout\(focusTimer\);/);
|
|
assert.match(modalSource, /\}, \[open\]\);/);
|
|
assert.doesNotMatch(modalSource, /\}, \[open, onClose\]\);/);
|
|
});
|
|
|
|
test("admin modal backdrop clicks do not close dialogs", () => {
|
|
assert.match(modalSource, /className="admin-modal-backdrop"/);
|
|
assert.doesNotMatch(modalSource, /onMouseDown=\{\(e\) =>/);
|
|
assert.doesNotMatch(modalSource, /e\.target === e\.currentTarget/);
|
|
});
|
|
|
|
test("admin modal supports titleless dialogs with aria labels", () => {
|
|
assert.match(modalSource, /title\?: string;/);
|
|
assert.match(modalSource, /ariaLabel\?: string;/);
|
|
assert.match(modalSource, /aria-labelledby=\{title \? titleId : undefined\}/);
|
|
assert.match(modalSource, /aria-label=\{title \? undefined : ariaLabel \?\? "对话框"\}/);
|
|
assert.match(modalSource, /admin-modal__header\$\{title \? "" : " is-titleless"\}/);
|
|
assert.match(modalSource, /\{title && <span id=\{titleId\}>\{title\}<\/span>\}/);
|
|
});
|