69 lines
2.5 KiB
TypeScript
69 lines
2.5 KiB
TypeScript
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import operationControlsSource from "./OperationControls.tsx?raw";
|
|
import { ConfirmDialog, ManagementDialog, UsageMeter } 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"');
|
|
});
|
|
|
|
it("renders resource meters with meaningful known, pending, and missing states", () => {
|
|
const html = renderToStaticMarkup(
|
|
<>
|
|
<UsageMeter label="磁盘" percent={78} />
|
|
<UsageMeter label="CPU" pending />
|
|
<UsageMeter label="内存" />
|
|
</>
|
|
);
|
|
|
|
expect(html).toContain("磁盘");
|
|
expect(html).toContain("78%");
|
|
expect(html).toContain("偏高");
|
|
expect(html).toContain('role="meter"');
|
|
expect(html).toContain('aria-valuenow="78"');
|
|
expect(html).toContain("CPU");
|
|
expect(html).toContain("读取中");
|
|
expect(html).toContain("等待指标");
|
|
expect(html).toContain("内存");
|
|
expect(html).toContain("未上报");
|
|
expect(html).toContain("等待 Run");
|
|
expect(html).not.toContain("--");
|
|
});
|
|
});
|