| 1 |
import React from "react"; |
| 2 |
import { render, screen } from "@testing-library/react"; |
| 3 |
import { expect, test, describe } from "vitest"; |
| 4 |
// Component |
| 5 |
import TableLayout from "./TableLayout"; |
| 6 |
|
| 7 |
const tableBody = [ |
| 8 |
<div key="1">Table Body Item</div>, |
| 9 |
<div key="2">Table Body Item</div>, |
| 10 |
]; |
| 11 |
|
| 12 |
describe("TableLayout Component", () => { |
| 13 |
test("should display the TableLayout with required props with table body", () => { |
| 14 |
render( |
| 15 |
<TableLayout |
| 16 |
ariaLabel="test-table" |
| 17 |
variant="compact" |
| 18 |
hasBorders={true} |
| 19 |
tableId="test-table" |
| 20 |
isStickyHeader={true} |
| 21 |
tableBody={tableBody} |
| 22 |
/> |
| 23 |
); |
| 24 |
expect(screen.getByLabelText("test-table")).toBeInTheDocument(); |
| 25 |
expect(screen.getAllByText("Table Body Item")).toHaveLength(2); |
| 26 |
}); |
| 27 |
|
| 28 |
test("should display the EmptyBodyTable when there is no table body", () => { |
| 29 |
render( |
| 30 |
<TableLayout |
| 31 |
ariaLabel="test-table2" |
| 32 |
variant="compact" |
| 33 |
hasBorders={true} |
| 34 |
tableId="test-table2" |
| 35 |
isStickyHeader={true} |
| 36 |
tableBody={[]} |
| 37 |
/> |
| 38 |
); |
| 39 |
|
| 40 |
expect(screen.getByLabelText("test-table2")).toBeInTheDocument(); |
| 41 |
expect(screen.getByText("No results found")).toBeInTheDocument(); |
| 42 |
expect( |
| 43 |
screen.getByText("Clear all filters and try again.") |
| 44 |
).toBeInTheDocument(); |
| 45 |
}); |
| 46 |
}); |