fix(webui): keep DataGrid actions out of form submission
This commit is contained in:
32
webui/tests/data-grid-actions.test.tsx
Normal file
32
webui/tests/data-grid-actions.test.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
function assertEqual<T>(actual: T, expected: T, message: string): void {
|
||||
if (actual !== expected) throw new Error(`${message}: expected ${String(expected)}, got ${String(actual)}`);
|
||||
}
|
||||
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { DataGridEmptyAction, DataGridRowActions } from "../src/components/table/DataGrid";
|
||||
|
||||
function noop() {}
|
||||
|
||||
function buttonCount(markup: string): number {
|
||||
return markup.match(/<button\b/g)?.length ?? 0;
|
||||
}
|
||||
|
||||
function nonSubmittingButtonCount(markup: string): number {
|
||||
return markup.match(/<button\b[^>]*\btype="button"/g)?.length ?? 0;
|
||||
}
|
||||
|
||||
const rowActions = renderToStaticMarkup(
|
||||
<form>
|
||||
<DataGridRowActions onAddBelow={noop} onRemove={noop} onMoveUp={noop} onMoveDown={noop} />
|
||||
</form>
|
||||
);
|
||||
assertEqual(buttonCount(rowActions), 4, "row actions render the expected controls");
|
||||
assertEqual(nonSubmittingButtonCount(rowActions), 4, "row actions do not submit an enclosing form");
|
||||
|
||||
const emptyAction = renderToStaticMarkup(
|
||||
<form>
|
||||
<DataGridEmptyAction onAdd={noop} />
|
||||
</form>
|
||||
);
|
||||
assertEqual(buttonCount(emptyAction), 1, "empty action renders the expected control");
|
||||
assertEqual(nonSubmittingButtonCount(emptyAction), 1, "empty action does not submit an enclosing form");
|
||||
Reference in New Issue
Block a user