X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/a21b35b41a8e69a4a1e287ce069dbc65c5c534f2..02fa1acae263e5cf28e95a36801cb578be941307:/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 439e6c27..1201dcb0 100644
--- a/src/components/data-table/data-table.test.tsx
+++ b/src/components/data-table/data-table.test.tsx
@@ -6,180 +6,199 @@ import * as React from "react";
 import { mount, configure } from "enzyme";
 import { TableHead, TableCell, Typography, TableBody, Button, TableSortLabel } from "@material-ui/core";
 import * as Adapter from "enzyme-adapter-react-16";
-import DataTable from "./data-table";
-import { DataColumn } from "./data-column";
-import DataTableFilters from "../data-table-filters/data-table-filters";
+import { DataTable, DataColumns } from "./data-table";
+import { DataTableFilters } from "../data-table-filters/data-table-filters";
+import { SortDirection, createDataColumn } from "./data-column";
 
 configure({ adapter: new Adapter() });
 
 describe("<DataTable />", () => {
     it("shows only selected columns", () => {
-        const columns: Array<DataColumn<string>> = [
-            {
+        const columns: DataColumns<string> = [
+            createDataColumn({
                 name: "Column 1",
                 render: () => <span />,
-                selected: true
-            },
-            {
+                selected: true,
+                configurable: true
+            }),
+            createDataColumn({
                 name: "Column 2",
                 render: () => <span />,
-                selected: true
-            },
-            {
+                selected: true,
+                configurable: true
+            }),
+            createDataColumn({
                 name: "Column 3",
                 render: () => <span />,
-                selected: false
-            }
+                selected: false,
+                configurable: true
+            }),
         ];
         const dataTable = mount(<DataTable
             columns={columns}
-            items={["item 1"]}
+            items={[{ key: "1", name: "item 1" }]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
+            onRowDoubleClick={jest.fn()}
+            onContextMenu={jest.fn()}
             onSortToggle={jest.fn()} />);
         expect(dataTable.find(TableHead).find(TableCell)).toHaveLength(2);
     });
 
     it("renders column name", () => {
-        const columns: Array<DataColumn<string>> = [
-            {
+        const columns: DataColumns<string> = [
+            createDataColumn({
                 name: "Column 1",
                 render: () => <span />,
-                selected: true
-            }
+                selected: true,
+                configurable: true
+            }),
         ];
         const dataTable = mount(<DataTable
             columns={columns}
             items={["item 1"]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
+            onRowDoubleClick={jest.fn()}
+            onContextMenu={jest.fn()}
             onSortToggle={jest.fn()} />);
         expect(dataTable.find(TableHead).find(TableCell).text()).toBe("Column 1");
     });
 
     it("uses renderHeader instead of name prop", () => {
-        const columns: Array<DataColumn<string>> = [
-            {
+        const columns: DataColumns<string> = [
+            createDataColumn({
                 name: "Column 1",
                 renderHeader: () => <span>Column Header</span>,
                 render: () => <span />,
-                selected: true
-            }
+                selected: true,
+                configurable: true
+            }),
         ];
         const dataTable = mount(<DataTable
             columns={columns}
-            items={["item 1"]}
+            items={[]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
+            onRowDoubleClick={jest.fn()}
+            onContextMenu={jest.fn()}
             onSortToggle={jest.fn()} />);
         expect(dataTable.find(TableHead).find(TableCell).text()).toBe("Column Header");
     });
 
     it("passes column key prop to corresponding cells", () => {
-        const columns: Array<DataColumn<string>> = [
-            {
+        const columns: DataColumns<string> = [
+            createDataColumn({
                 name: "Column 1",
                 key: "column-1-key",
                 render: () => <span />,
-                selected: true
-            }
+                selected: true,
+                configurable: true
+            })
         ];
         const dataTable = mount(<DataTable
             columns={columns}
             items={["item 1"]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
+            onRowDoubleClick={jest.fn()}
+            onContextMenu={jest.fn()}
             onSortToggle={jest.fn()} />);
         expect(dataTable.find(TableHead).find(TableCell).key()).toBe("column-1-key");
         expect(dataTable.find(TableBody).find(TableCell).key()).toBe("column-1-key");
     });
 
-    it("shows information that items array is empty", () => {
-        const columns: Array<DataColumn<string>> = [
-            {
-                name: "Column 1",
-                render: () => <span />,
-                selected: true
-            }
-        ];
-        const dataTable = mount(<DataTable
-            columns={columns}
-            items={[]}
-            onFiltersChange={jest.fn()}
-            onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
-            onSortToggle={jest.fn()} />);
-        expect(dataTable.find(Typography).text()).toBe("No items");
-    });
-
     it("renders items", () => {
-        const columns: Array<DataColumn<string>> = [
-            {
+        const columns: DataColumns<string> = [
+            createDataColumn({
                 name: "Column 1",
                 render: (item) => <Typography>{item}</Typography>,
-                selected: true
-            },
-            {
+                selected: true,
+                configurable: true
+            }),
+            createDataColumn({
                 name: "Column 2",
                 render: (item) => <Button>{item}</Button>,
-                selected: true
-            }
+                selected: true,
+                configurable: true
+            })
         ];
-        const dataTable = mount(<DataTable 
-            columns={columns} 
+        const dataTable = mount(<DataTable
+            columns={columns}
             items={["item 1"]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
+            onRowDoubleClick={jest.fn()}
+            onContextMenu={jest.fn()}
             onSortToggle={jest.fn()} />);
         expect(dataTable.find(TableBody).find(Typography).text()).toBe("item 1");
         expect(dataTable.find(TableBody).find(Button).text()).toBe("item 1");
     });
 
     it("passes sorting props to <TableSortLabel />", () => {
-        const columns: Array<DataColumn<string>> = [{
+        const columns: DataColumns<string> = [
+            createDataColumn({
             name: "Column 1",
-            sortDirection: "asc",
+            sortDirection: SortDirection.ASC,
             selected: true,
+            configurable: true,
             render: (item) => <Typography>{item}</Typography>
-        }];
+        })];
         const onSortToggle = jest.fn();
-        const dataTable = mount(<DataTable 
-            columns={columns} 
-            items={["item 1"]} 
+        const dataTable = mount(<DataTable
+            columns={columns}
+            items={["item 1"]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
-            onSortToggle={onSortToggle}/>);
+            onRowDoubleClick={jest.fn()}
+            onContextMenu={jest.fn()}
+            onSortToggle={onSortToggle} />);
         expect(dataTable.find(TableSortLabel).prop("active")).toBeTruthy();
         dataTable.find(TableSortLabel).at(0).simulate("click");
         expect(onSortToggle).toHaveBeenCalledWith(columns[0]);
     });
 
+    it("does not display <DataTableFilter /> if there is no filters provided", () => {
+        const columns: DataColumns<string> = [{
+            name: "Column 1",
+            sortDirection: SortDirection.ASC,
+            selected: true,
+            configurable: true,
+            filters: [],
+            render: (item) => <Typography>{item}</Typography>
+        }];
+        const onFiltersChange = jest.fn();
+        const dataTable = mount(<DataTable
+            columns={columns}
+            items={[]}
+            onFiltersChange={onFiltersChange}
+            onRowClick={jest.fn()}
+            onRowDoubleClick={jest.fn()}
+            onSortToggle={jest.fn()}
+            onContextMenu={jest.fn()} />);
+        expect(dataTable.find(DataTableFilters)).toHaveLength(0);
+    });
+
     it("passes filter props to <DataTableFilter />", () => {
-        const columns: Array<DataColumn<string>> = [{
+        const columns: DataColumns<string> = [{
             name: "Column 1",
-            sortDirection: "asc",
+            sortDirection: SortDirection.ASC,
             selected: true,
-            filters: [{name: "Filter 1", selected: true}],
+            configurable: true,
+            filters: [{ name: "Filter 1", selected: true }],
             render: (item) => <Typography>{item}</Typography>
         }];
         const onFiltersChange = jest.fn();
-        const dataTable = mount(<DataTable 
-            columns={columns} 
-            items={["item 1"]} 
+        const dataTable = mount(<DataTable
+            columns={columns}
+            items={[]}
             onFiltersChange={onFiltersChange}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
-            onSortToggle={jest.fn()}/>);
+            onRowDoubleClick={jest.fn()}
+            onSortToggle={jest.fn()}
+            onContextMenu={jest.fn()} />);
         expect(dataTable.find(DataTableFilters).prop("filters")).toBe(columns[0].filters);
         dataTable.find(DataTableFilters).prop("onChange")([]);
         expect(onFiltersChange).toHaveBeenCalledWith([], columns[0]);
     });
-
-
-});
\ No newline at end of file
+});
