|
| 1 | +import React from "react" |
| 2 | +import { renderWithProviders } from "testUtilities" |
| 3 | +import Table from "./table" |
| 4 | + |
| 5 | +const serverColumn = { id: "server", accessorKey: "server", header: "Server" } |
| 6 | +const alertsColumn = { id: "alerts", accessorKey: "alerts", header: "Alerts" } |
| 7 | +const cpuColumn = { id: "cpu", accessorKey: "cpu", header: "CPU" } |
| 8 | + |
| 9 | +it("renders drag handles only on leaf header cells when columns are grouped", async () => { |
| 10 | + const { container, findByText } = renderWithProviders( |
| 11 | + <Table |
| 12 | + data={[]} |
| 13 | + dataColumns={[ |
| 14 | + { id: "Device", header: "", headerString: () => "", columns: [serverColumn, alertsColumn] }, |
| 15 | + { id: "Metrics", header: "", headerString: () => "", columns: [cpuColumn] }, |
| 16 | + ]} |
| 17 | + enableColumnReordering |
| 18 | + /> |
| 19 | + ) |
| 20 | + |
| 21 | + await findByText("Server") |
| 22 | + |
| 23 | + expect(container.querySelectorAll(".drag-handle")).toHaveLength(3) |
| 24 | +}) |
| 25 | + |
| 26 | +it("renders no drag handle on placeholder header cells of ungrouped columns", async () => { |
| 27 | + const { container, findByText } = renderWithProviders( |
| 28 | + <Table |
| 29 | + data={[]} |
| 30 | + dataColumns={[ |
| 31 | + serverColumn, |
| 32 | + { id: "Metrics", header: "", headerString: () => "", columns: [cpuColumn, alertsColumn] }, |
| 33 | + ]} |
| 34 | + enableColumnReordering |
| 35 | + /> |
| 36 | + ) |
| 37 | + |
| 38 | + await findByText("CPU") |
| 39 | + |
| 40 | + expect(container.querySelectorAll(".drag-handle")).toHaveLength(3) |
| 41 | +}) |
0 commit comments