-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62c7d96
commit 35752b3
Showing
4 changed files
with
217 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { fireEvent } from "@testing-library/react"; | ||
import { Table, TableProps } from "./Table"; | ||
import { renderCUI } from "@/utils/test-utils"; | ||
|
||
const headers = [{ label: "Company" }, { label: "Contact" }, { label: "Country" }]; | ||
|
||
const rows = [ | ||
{ | ||
id: "row-1", | ||
cells: [ | ||
{ label: "Alfreds Futterkiste" }, | ||
{ label: "Maria Anders" }, | ||
{ label: "Germany" }, | ||
], | ||
}, | ||
{ | ||
id: "row-2", | ||
cells: [ | ||
{ label: "Centro comercial Moctezuma" }, | ||
{ label: "Francisco Chang" }, | ||
{ label: "Mexico" }, | ||
], | ||
}, | ||
]; | ||
|
||
describe("Table", () => { | ||
const renderTable = (props: Omit<TableProps, "headers" | "rows">) => | ||
renderCUI( | ||
<Table | ||
headers={headers} | ||
rows={rows} | ||
data-testid="table" | ||
{...props} | ||
/> | ||
); | ||
|
||
it("should render the Table", () => { | ||
const { queryByTestId } = renderTable({}); | ||
expect(queryByTestId("table")).not.toBeNull(); | ||
expect(queryByTestId("checkbox")).toBeNull(); | ||
}); | ||
|
||
it("should show checkbox on isSelectable", () => { | ||
const { queryByTestId, queryAllByTestId } = renderTable({ | ||
isSelectable: true, | ||
selectedIndices: [], | ||
}); | ||
expect(queryByTestId("table")).not.toBeNull(); | ||
expect(queryAllByTestId("checkbox")[0]).not.toBeNull(); | ||
expect(queryAllByTestId("checkbox")[1]).not.toBeNull(); | ||
}); | ||
|
||
it("should trigger onSelect on clicking checkbox", () => { | ||
const onSelect = jest.fn(); | ||
const { queryByTestId, queryAllByTestId } = renderTable({ | ||
isSelectable: true, | ||
selectedIndices: [], | ||
onSelect, | ||
}); | ||
expect(queryByTestId("table")).not.toBeNull(); | ||
expect(queryAllByTestId("checkbox")).toHaveLength(4); | ||
const selectAllCheckbox = queryAllByTestId("checkbox")[1]; | ||
const rowCheckbox = queryAllByTestId("checkbox")[2]; | ||
expect(selectAllCheckbox).not.toBeNull(); | ||
fireEvent.click(selectAllCheckbox); | ||
expect(onSelect).toBeCalledTimes(1); | ||
expect(rowCheckbox).not.toBeNull(); | ||
fireEvent.click(selectAllCheckbox); | ||
expect(onSelect).toBeCalledTimes(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters