X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f0d519637c997df11d5b1a1b32b3d9e4a2872325..b5b6d3dd22b597c9626a396b6449c4f7c9557794:/src/components/data-table/data-table.test.tsx diff --git a/src/components/data-table/data-table.test.tsx b/src/components/data-table/data-table.test.tsx index 77c7825b..16957b40 100644 --- a/src/components/data-table/data-table.test.tsx +++ b/src/components/data-table/data-table.test.tsx @@ -8,31 +8,32 @@ import { TableHead, TableCell, Typography, TableBody, Button, TableSortLabel } f import * as Adapter from "enzyme-adapter-react-16"; import { DataTable, DataColumns } from "./data-table"; import { DataTableFilters } from "../data-table-filters/data-table-filters"; -import { SortDirection } from "./data-column"; +import { SortDirection, createDataColumn } from "./data-column"; +import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view'; configure({ adapter: new Adapter() }); describe("", () => { it("shows only selected columns", () => { const columns: DataColumns = [ - { + createDataColumn({ name: "Column 1", render: () => , selected: true, configurable: true - }, - { + }), + createDataColumn({ name: "Column 2", render: () => , selected: true, configurable: true - }, - { + }), + createDataColumn({ name: "Column 3", render: () => , selected: false, configurable: true - } + }), ]; const dataTable = mount(", () => { it("renders column name", () => { const columns: DataColumns = [ - { + createDataColumn({ name: "Column 1", render: () => , selected: true, configurable: true - } + }), ]; const dataTable = mount(", () => { it("uses renderHeader instead of name prop", () => { const columns: DataColumns = [ - { + createDataColumn({ name: "Column 1", renderHeader: () => Column Header, render: () => , selected: true, configurable: true - } + }), ]; const dataTable = mount(", () => { it("passes column key prop to corresponding cells", () => { const columns: DataColumns = [ - { + createDataColumn({ name: "Column 1", key: "column-1-key", render: () => , selected: true, configurable: true - } + }) ]; const dataTable = mount(", () => { it("renders items", () => { const columns: DataColumns = [ - { + createDataColumn({ name: "Column 1", render: (item) => {item}, selected: true, configurable: true - }, - { + }), + createDataColumn({ name: "Column 2", render: (item) => , selected: true, configurable: true - } + }) ]; const dataTable = mount(", () => { }); it("passes sorting props to ", () => { - const columns: DataColumns = [{ + const columns: DataColumns = [ + createDataColumn({ name: "Column 1", sortDirection: SortDirection.ASC, selected: true, configurable: true, render: (item) => {item} - }]; + })]; const onSortToggle = jest.fn(); const dataTable = mount(", () => { expect(onSortToggle).toHaveBeenCalledWith(columns[0]); }); + it("does not display if there is no filters provided", () => { + const columns: DataColumns = [{ + name: "Column 1", + sortDirection: SortDirection.ASC, + selected: true, + configurable: true, + filters: [], + render: (item) => {item} + }]; + const onFiltersChange = jest.fn(); + const dataTable = mount(); + expect(dataTable.find(DataTableFilters)).toHaveLength(0); + }); + it("passes filter props to ", () => { const columns: DataColumns = [{ name: "Column 1", @@ -179,4 +202,24 @@ describe("", () => { dataTable.find(DataTableFilters).prop("onChange")([]); expect(onFiltersChange).toHaveBeenCalledWith([], columns[0]); }); + + it("shows default view if there is no items", () => { + const columns: DataColumns = [ + createDataColumn({ + name: "Column 1", + render: () => , + selected: true, + configurable: true + }), + ]; + const dataTable = mount(); + expect(dataTable.find(DataTableDefaultView)).toHaveLength(1); + }); });