Skip to content

Commit

Permalink
test for draggable re-renders
Browse files Browse the repository at this point in the history
  • Loading branch information
bsholmes committed Jan 5, 2024
1 parent 3b2ac9c commit 7a8fbb4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/components/Table/GridTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const rows: GridDataRow<Row>[] = [
{ kind: "data", id: "1", data: { name: "foo", value: 1 } },
{ kind: "data", id: "2", data: { name: "bar", value: 2 } },
];
const draggableRows: GridDataRow<Row>[] = [
simpleHeader,
{ kind: "data", id: "1", data: { name: "foo", value: 1 }, draggable: true },
{ kind: "data", id: "2", data: { name: "bar", value: 2 }, draggable: true },
];

// Make a `NestedRow` ADT for a table with a header + 3 levels of nesting
type TotalsRow = { kind: "totals"; id: string; data: undefined };
Expand Down Expand Up @@ -2462,6 +2467,33 @@ describe("GridTable", () => {
expect(row(r, 2).getAttribute("data-render")).toEqual("1");
});

it("memoizes draggable rows based on the data attribute", async () => {
const [header, row1, row2] = draggableRows;
const columns = [nameColumn];
function onDropRow () {};
// Given a table is initially rendered with 2 rows
const r = await render(
<GridTable
key="a"
columns={columns}
rows={[header, row1, row2]}
onRowDrop={onDropRow}
/>,
);
// When we render with new rows but unchanged data values
r.rerender(
<GridTable
key="a"
columns={columns}
rows={[header, { ...row1 }, { ...row2 }]}
onRowDrop={onDropRow}
/>,
);
// Then neither row was re-rendered
expect(row(r, 1).getAttribute("data-render")).toEqual("1");
expect(row(r, 2).getAttribute("data-render")).toEqual("1");
});

it("reacts to setting activeRowId", async () => {
const activeRowIdRowStyles: RowStyles<Row> = {
data: {
Expand Down

0 comments on commit 7a8fbb4

Please sign in to comment.