X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/750ece46ef69eec338523c63c834cd87901c1342..215d0b7a7e1f69765c5f2a1139e52d8c427066eb:/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 99ed2daf..866564ac 100644
--- a/src/components/data-table/data-table.test.tsx
+++ b/src/components/data-table/data-table.test.tsx
@@ -2,34 +2,40 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from "react";
+import React from "react";
 import { mount, configure } from "enzyme";
+import { pipe } from 'lodash/fp';
 import { TableHead, TableCell, Typography, TableBody, Button, TableSortLabel } from "@material-ui/core";
-import * as Adapter from "enzyme-adapter-react-16";
+import 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 { DataTableFiltersPopover } from 'components/data-table-filters/data-table-filters-popover';
+import { createTree, setNode, initTreeNode } from 'models/tree';
+import { DataTableFilterItem } from "components/data-table-filters/data-table-filters-tree";
 
 configure({ adapter: new Adapter() });
 
 describe("<DataTable />", () => {
     it("shows only selected columns", () => {
         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}
@@ -44,11 +50,12 @@ describe("<DataTable />", () => {
 
     it("renders column name", () => {
         const columns: DataColumns<string> = [
-            {
+            createDataColumn({
                 name: "Column 1",
                 render: () => <span />,
-                selected: true
-            }
+                selected: true,
+                configurable: true
+            }),
         ];
         const dataTable = mount(<DataTable
             columns={columns}
@@ -63,12 +70,13 @@ describe("<DataTable />", () => {
 
     it("uses renderHeader instead of name prop", () => {
         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}
@@ -83,15 +91,17 @@ describe("<DataTable />", () => {
 
     it("passes column key prop to corresponding cells", () => {
         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}
+            working={false}
             items={["item 1"]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
@@ -104,19 +114,22 @@ describe("<DataTable />", () => {
 
     it("renders items", () => {
         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}
+            working={false}
             items={["item 1"]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
@@ -128,12 +141,14 @@ describe("<DataTable />", () => {
     });
 
     it("passes sorting props to <TableSortLabel />", () => {
-        const columns: DataColumns<string> = [{
-            name: "Column 1",
-            sortDirection: SortDirection.ASC,
-            selected: true,
-            render: (item) => <Typography>{item}</Typography>
-        }];
+        const columns: DataColumns<string> = [
+            createDataColumn({
+                name: "Column 1",
+                sortDirection: SortDirection.ASC,
+                selected: true,
+                configurable: true,
+                render: (item) => <Typography>{item}</Typography>
+            })];
         const onSortToggle = jest.fn();
         const dataTable = mount(<DataTable
             columns={columns}
@@ -148,12 +163,38 @@ describe("<DataTable />", () => {
         expect(onSortToggle).toHaveBeenCalledWith(columns[0]);
     });
 
-    it("passes filter props to <DataTableFilter />", () => {
+    it("does not display <DataTableFiltersPopover /> 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(DataTableFiltersPopover)).toHaveLength(0);
+    });
+
+    it("passes filter props to <DataTableFiltersPopover />", () => {
+        const filters = pipe(
+            () => createTree<DataTableFilterItem>(),
+            setNode(initTreeNode({ id: 'filter', value: { name: 'filter' } }))
+        );
         const columns: DataColumns<string> = [{
             name: "Column 1",
             sortDirection: SortDirection.ASC,
             selected: true,
-            filters: [{ name: "Filter 1", selected: true }],
+            configurable: true,
+            filters: filters(),
             render: (item) => <Typography>{item}</Typography>
         }];
         const onFiltersChange = jest.fn();
@@ -165,8 +206,8 @@ describe("<DataTable />", () => {
             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(dataTable.find(DataTableFiltersPopover).prop("filters")).toBe(columns[0].filters);
+        dataTable.find(DataTableFiltersPopover).prop("onChange")([]);
         expect(onFiltersChange).toHaveBeenCalledWith([], columns[0]);
     });
 });
