17782: Fixes almost all tests (4 left) mostly by fixing namespace-type imports.
[arvados-workbench2.git] / src / components / data-explorer / data-explorer.test.tsx
index eff4992311135dbad8d3fb04d8c767e6524a7f7a..dc7e8725793524b57bf7cfb76aadd5c466577274 100644 (file)
@@ -2,44 +2,31 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from "react";
+import React from "react";
 import { configure, mount } from "enzyme";
-import * as Adapter from 'enzyme-adapter-react-16';
+import Adapter from 'enzyme-adapter-react-16';
 
-import DataExplorer from "./data-explorer";
-import ContextMenu from "../context-menu/context-menu";
-import ColumnSelector from "../column-selector/column-selector";
-import DataTable from "../data-table/data-table";
-import SearchInput from "../search-input/search-input";
+import { DataExplorer } from "./data-explorer";
+import { ColumnSelector } from "../column-selector/column-selector";
+import { DataTable, DataTableFetchMode } from "../data-table/data-table";
+import { SearchInput } from "../search-input/search-input";
 import { TablePagination } from "@material-ui/core";
+import { ProjectIcon } from '../icon/icon';
+import { SortDirection } from '../data-table/data-column';
 
 configure({ adapter: new Adapter() });
 
 describe("<DataExplorer />", () => {
 
-    it("communicates with <ContextMenu/>", () => {
-        const onContextAction = jest.fn();
-        const dataExplorer = mount(<DataExplorer
-            {...mockDataExplorerProps()}
-            contextActions={[]}
-            onContextAction={onContextAction}
-            items={["Item 1"]}
-            columns={[{ name: "Column 1", render: jest.fn(), selected: true }]} />);
-        expect(dataExplorer.find(ContextMenu).prop("actions")).toEqual([]);
-        dataExplorer.find(DataTable).prop("onRowContextMenu")({
-            preventDefault: jest.fn()
-        }, "Item 1");
-        dataExplorer.find(ContextMenu).prop("onActionClick")({ name: "Action 1", icon: "" });
-        expect(onContextAction).toHaveBeenCalledWith({ name: "Action 1", icon: "" }, "Item 1");
-    });
-
     it("communicates with <SearchInput/>", () => {
         const onSearch = jest.fn();
+        const onSetColumns = jest.fn();
         const dataExplorer = mount(<DataExplorer
             {...mockDataExplorerProps()}
-            items={["item 1"]}
+            items={[{ name: "item 1" }]}
             searchValue="search value"
-            onSearch={onSearch} />);
+            onSearch={onSearch}
+            onSetColumns={onSetColumns} />);
         expect(dataExplorer.find(SearchInput).prop("value")).toEqual("search value");
         dataExplorer.find(SearchInput).prop("onSearch")("new value");
         expect(onSearch).toHaveBeenCalledWith("new value");
@@ -47,13 +34,14 @@ describe("<DataExplorer />", () => {
 
     it("communicates with <ColumnSelector/>", () => {
         const onColumnToggle = jest.fn();
-        const columns = [{ name: "Column 1", render: jest.fn(), selected: true }];
+        const onSetColumns = jest.fn();
+        const columns = [{ name: "Column 1", render: jest.fn(), selected: true, configurable: true, sortDirection: SortDirection.ASC, filters: {} }];
         const dataExplorer = mount(<DataExplorer
             {...mockDataExplorerProps()}
             columns={columns}
             onColumnToggle={onColumnToggle}
-            contextActions={[]}
-            items={["Item 1"]} />);
+            items={[{ name: "item 1" }]}
+            onSetColumns={onSetColumns} />);
         expect(dataExplorer.find(ColumnSelector).prop("columns")).toBe(columns);
         dataExplorer.find(ColumnSelector).prop("onColumnToggle")("columns");
         expect(onColumnToggle).toHaveBeenCalledWith("columns");
@@ -63,16 +51,18 @@ describe("<DataExplorer />", () => {
         const onFiltersChange = jest.fn();
         const onSortToggle = jest.fn();
         const onRowClick = jest.fn();
-        const columns = [{ name: "Column 1", render: jest.fn(), selected: true }];
-        const items = ["Item 1"];
+        const onSetColumns = jest.fn();
+        const columns = [{ name: "Column 1", render: jest.fn(), selected: true, configurable: true, sortDirection: SortDirection.ASC, filters: {} }];
+        const items = [{ name: "item 1" }];
         const dataExplorer = mount(<DataExplorer
             {...mockDataExplorerProps()}
             columns={columns}
             items={items}
             onFiltersChange={onFiltersChange}
             onSortToggle={onSortToggle}
-            onRowClick={onRowClick} />);
-        expect(dataExplorer.find(DataTable).prop("columns")).toBe(columns);
+            onRowClick={onRowClick}
+            onSetColumns={onSetColumns} />);
+        expect(dataExplorer.find(DataTable).prop("columns").slice(0, -1)).toEqual(columns);
         expect(dataExplorer.find(DataTable).prop("items")).toBe(items);
         dataExplorer.find(DataTable).prop("onRowClick")("event", "rowClick");
         dataExplorer.find(DataTable).prop("onFiltersChange")("filtersChange");
@@ -82,27 +72,18 @@ describe("<DataExplorer />", () => {
         expect(onRowClick).toHaveBeenCalledWith("rowClick");
     });
 
-    it("does not render <SearchInput/>, <ColumnSelector/> and <TablePagination/> if there is no items", () => {
-        const dataExplorer = mount(<DataExplorer
-            {...mockDataExplorerProps()}
-            items={[]}
-        />);
-        expect(dataExplorer.find(SearchInput)).toHaveLength(0);
-        expect(dataExplorer.find(ColumnSelector)).toHaveLength(0);
-        expect(dataExplorer.find(TablePagination)).toHaveLength(0);
-    });
-
     it("communicates with <TablePagination/>", () => {
         const onChangePage = jest.fn();
         const onChangeRowsPerPage = jest.fn();
+        const onSetColumns = jest.fn();
         const dataExplorer = mount(<DataExplorer
             {...mockDataExplorerProps()}
-            items={["Item 1"]}
+            items={[{ name: "item 1" }]}
             page={10}
             rowsPerPage={50}
             onChangePage={onChangePage}
             onChangeRowsPerPage={onChangeRowsPerPage}
-        />);
+            onSetColumns={onSetColumns} />);
         expect(dataExplorer.find(TablePagination).prop("page")).toEqual(10);
         expect(dataExplorer.find(TablePagination).prop("rowsPerPage")).toEqual(50);
         dataExplorer.find(TablePagination).prop("onChangePage")(undefined, 6);
@@ -113,18 +94,27 @@ describe("<DataExplorer />", () => {
 });
 
 const mockDataExplorerProps = () => ({
+    fetchMode: DataTableFetchMode.PAGINATED,
     columns: [],
     items: [],
+    itemsAvailable: 0,
     contextActions: [],
     searchValue: "",
     page: 0,
     rowsPerPage: 0,
+    rowsPerPageOptions: [0],
     onSearch: jest.fn(),
     onFiltersChange: jest.fn(),
     onSortToggle: jest.fn(),
     onRowClick: jest.fn(),
+    onRowDoubleClick: jest.fn(),
     onColumnToggle: jest.fn(),
-    onContextAction: jest.fn(),
     onChangePage: jest.fn(),
-    onChangeRowsPerPage: jest.fn()
-});
\ No newline at end of file
+    onChangeRowsPerPage: jest.fn(),
+    onContextMenu: jest.fn(),
+    defaultIcon: ProjectIcon,
+    onSetColumns: jest.fn(),
+    onLoadMore: jest.fn(),
+    defaultMessages: ['testing'],
+    contextMenuColumn: true
+});