feat(webui): centralize contextual table actions
This commit is contained in:
@@ -4,6 +4,7 @@ function assertEqual<T>(actual: T, expected: T, message: string): void {
|
||||
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { DataGridEmptyAction, DataGridRowActions } from "../src/components/table/DataGrid";
|
||||
import TableActionGroup, { runTableAction } from "../src/components/table/TableActionGroup";
|
||||
|
||||
function noop() {}
|
||||
|
||||
@@ -30,3 +31,32 @@ const emptyAction = renderToStaticMarkup(
|
||||
);
|
||||
assertEqual(buttonCount(emptyAction), 1, "empty action renders the expected control");
|
||||
assertEqual(nonSubmittingButtonCount(emptyAction), 1, "empty action does not submit an enclosing form");
|
||||
|
||||
const contextActions = renderToStaticMarkup(
|
||||
<TableActionGroup
|
||||
actions={[
|
||||
{ id: "inspect", label: "Inspect", icon: <span>I</span>, onClick: noop },
|
||||
{ id: "edit", label: "Edit", icon: <span>E</span>, applicable: false, onClick: noop },
|
||||
{ id: "remove", label: "Remove", icon: <span>R</span>, disabled: true, onClick: noop }
|
||||
]}
|
||||
/>
|
||||
);
|
||||
assertEqual(buttonCount(contextActions), 2, "table action groups omit actions that do not apply");
|
||||
assertEqual(nonSubmittingButtonCount(contextActions), 2, "table action groups do not submit an enclosing form");
|
||||
assertEqual(contextActions.includes('aria-label="Inspect"'), true, "table actions expose an accessible label");
|
||||
assertEqual(contextActions.includes('title="Inspect"'), true, "table actions expose a native tooltip");
|
||||
assertEqual(contextActions.includes('aria-hidden="true"'), true, "table action icons stay decorative");
|
||||
|
||||
let propagationStopped = false;
|
||||
let actionCalled = false;
|
||||
runTableAction(
|
||||
{ stopPropagation: () => { propagationStopped = true; } },
|
||||
() => { actionCalled = true; }
|
||||
);
|
||||
assertEqual(propagationStopped, true, "table actions do not trigger clickable row handlers");
|
||||
assertEqual(actionCalled, true, "table actions still invoke their handler");
|
||||
|
||||
const noReorderActions = renderToStaticMarkup(
|
||||
<DataGridRowActions onAddBelow={noop} onRemove={noop} />
|
||||
);
|
||||
assertEqual(buttonCount(noReorderActions), 2, "row actions omit reorder controls when ordering does not apply");
|
||||
|
||||
Reference in New Issue
Block a user