46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import operationControlsSource from "./OperationControls.tsx?raw";
|
|
import { ConfirmDialog, ManagementDialog } from "./OperationControls";
|
|
|
|
describe("shared operation dialogs", () => {
|
|
it("renders labelled, busy-aware confirmation semantics", () => {
|
|
const html = renderToStaticMarkup(
|
|
<ConfirmDialog
|
|
open
|
|
title="确认停用"
|
|
description="会保留审计记录"
|
|
confirmLabel="停用"
|
|
busy
|
|
onConfirm={() => undefined}
|
|
onCancel={() => undefined}
|
|
/>
|
|
);
|
|
|
|
expect(html).toContain('role="dialog"');
|
|
expect(html).toContain('aria-labelledby=');
|
|
expect(html).toContain('aria-describedby=');
|
|
expect(html).toContain('aria-busy="true"');
|
|
expect(html).toContain("关闭确认停用");
|
|
expect(operationControlsSource).toContain('event.key === "Escape"');
|
|
expect(operationControlsSource).toContain('document.body.style.overflow = "hidden"');
|
|
expect(operationControlsSource).toContain("previousFocus?.focus()");
|
|
expect(operationControlsSource).toContain("const onCloseRef = useRef(onClose)");
|
|
expect(operationControlsSource).toContain('querySelector<HTMLElement>("input:not([disabled]), select:not([disabled]), textarea:not([disabled])")');
|
|
expect(operationControlsSource).toContain("}, [open]);");
|
|
});
|
|
|
|
it("keeps management forms in a dialog surface", () => {
|
|
const html = renderToStaticMarkup(
|
|
<ManagementDialog open title="编辑资源" onClose={() => undefined}>
|
|
<p>内容</p>
|
|
</ManagementDialog>
|
|
);
|
|
|
|
expect(html).toContain('role="dialog"');
|
|
expect(html).toContain("编辑资源");
|
|
expect(html).toContain('aria-modal="true"');
|
|
});
|
|
});
|