fix(webui): enforce full-result DataGrid queries
This commit is contained in:
@@ -4,7 +4,7 @@ function assertEqual<T>(actual: T, expected: T, message: string): void {
|
||||
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import Button from "../src/components/Button";
|
||||
import { DataGridEmptyAction, DataGridRowActions } from "../src/components/table/DataGrid";
|
||||
import DataGrid, { DataGridEmptyAction, DataGridRowActions, type DataGridColumn } from "../src/components/table/DataGrid";
|
||||
import TableActionGroup, { runTableAction } from "../src/components/table/TableActionGroup";
|
||||
|
||||
function noop() {}
|
||||
@@ -77,3 +77,43 @@ const reasonedButton = renderToStaticMarkup(<Button disabledReason="Permission d
|
||||
assertEqual(reasonedButton.includes("disabled=\"\""), true, "a disabled reason disables the central button");
|
||||
assertEqual(reasonedButton.includes("disabled-action-tooltip"), true, "a disabled reason remains keyboard discoverable");
|
||||
assertEqual(reasonedButton.includes("disabledReason"), false, "the central-only disabled reason is not passed to the DOM");
|
||||
|
||||
type FilterRow = { id: string; name: string };
|
||||
const filterRows: FilterRow[] = [
|
||||
{ id: "first-non-match", name: "Ordinary row" },
|
||||
{ id: "second-non-match", name: "Another row" },
|
||||
{ id: "first-match", name: "Target alpha" },
|
||||
{ id: "third-non-match", name: "Unrelated row" },
|
||||
{ id: "second-match", name: "Target beta" },
|
||||
{ id: "third-match", name: "Target gamma" }
|
||||
];
|
||||
const filterColumns: DataGridColumn<FilterRow>[] = [
|
||||
{ id: "name", header: "Name", filterable: true, value: (row) => row.name }
|
||||
];
|
||||
const fullResultFilterMarkup = renderToStaticMarkup(
|
||||
<DataGrid
|
||||
id="full-result-filter-regression"
|
||||
rows={filterRows}
|
||||
columns={filterColumns}
|
||||
getRowKey={(row) => row.id}
|
||||
initialFilters={{ name: "target" }}
|
||||
pagination={{ page: 1, pageSize: 2, onPageChange: noop }}
|
||||
/>
|
||||
);
|
||||
assertEqual(fullResultFilterMarkup.includes("Target alpha"), true, "client filtering finds matches beyond the unfiltered first page");
|
||||
assertEqual(fullResultFilterMarkup.includes("Target beta"), true, "client filtering happens before the first page is sliced");
|
||||
assertEqual(fullResultFilterMarkup.includes("Target gamma"), false, "client pagination still limits the filtered page size");
|
||||
assertEqual(fullResultFilterMarkup.includes("1\u20132"), true, "pagination counts describe the filtered result set");
|
||||
assertEqual(/of(?:<!-- -->)?\s*(?:<!-- -->)?3/.test(fullResultFilterMarkup), true, "the filtered total includes matches from every source row");
|
||||
|
||||
const clearedFilterMarkup = renderToStaticMarkup(
|
||||
<DataGrid
|
||||
id="cleared-full-result-filter-regression"
|
||||
rows={filterRows}
|
||||
columns={filterColumns}
|
||||
getRowKey={(row) => row.id}
|
||||
pagination={{ page: 1, pageSize: 2, onPageChange: noop }}
|
||||
/>
|
||||
);
|
||||
assertEqual(clearedFilterMarkup.includes("Ordinary row"), true, "clearing filters restores the first unfiltered row");
|
||||
assertEqual(/of(?:<!-- -->)?\s*(?:<!-- -->)?6/.test(clearedFilterMarkup), true, "clearing filters restores the full pagination total");
|
||||
|
||||
Reference in New Issue
Block a user