Create util for mocking resource services, create tests for FavoriteService
[arvados-workbench2.git] / src / components / data-explorer / data-explorer.test.tsx
index 94c7be6dab933ff6991edda0a56ebf4b1edc0d2d..616a9c122e751cdf72746b4e58838c6d6c3d41ca 100644 (file)
@@ -6,39 +6,21 @@ import * as React from "react";
 import { configure, mount } from "enzyme";
 import * as 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 } from "../data-table/data-table";
+import { SearchInput } from "../search-input/search-input";
 import { TablePagination } from "@material-ui/core";
 
 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(),
-            stopPropagation: 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 dataExplorer = mount(<DataExplorer
             {...mockDataExplorerProps()}
-            items={["item 1"]}
+            items={[{ name: "item 1" }]}
             searchValue="search value"
             onSearch={onSearch} />);
         expect(dataExplorer.find(SearchInput).prop("value")).toEqual("search value");
@@ -53,8 +35,7 @@ describe("<DataExplorer />", () => {
             {...mockDataExplorerProps()}
             columns={columns}
             onColumnToggle={onColumnToggle}
-            contextActions={[]}
-            items={["Item 1"]} />);
+            items={[{ name: "item 1" }]} />);
         expect(dataExplorer.find(ColumnSelector).prop("columns")).toBe(columns);
         dataExplorer.find(ColumnSelector).prop("onColumnToggle")("columns");
         expect(onColumnToggle).toHaveBeenCalledWith("columns");
@@ -65,7 +46,7 @@ describe("<DataExplorer />", () => {
         const onSortToggle = jest.fn();
         const onRowClick = jest.fn();
         const columns = [{ name: "Column 1", render: jest.fn(), selected: true }];
-        const items = ["Item 1"];
+        const items = [{ name: "item 1" }];
         const dataExplorer = mount(<DataExplorer
             {...mockDataExplorerProps()}
             columns={columns}
@@ -83,12 +64,11 @@ describe("<DataExplorer />", () => {
         expect(onRowClick).toHaveBeenCalledWith("rowClick");
     });
 
-    it("does not render <SearchInput/>, <ColumnSelector/> and <TablePagination/> if there is no items", () => {
+    it("does not render <TablePagination/> if there is no items", () => {
         const dataExplorer = mount(<DataExplorer
             {...mockDataExplorerProps()}
             items={[]}
         />);
-        expect(dataExplorer.find(SearchInput)).toHaveLength(0);
         expect(dataExplorer.find(TablePagination)).toHaveLength(0);
     });
 
@@ -97,7 +77,7 @@ describe("<DataExplorer />", () => {
         const onChangeRowsPerPage = jest.fn();
         const dataExplorer = mount(<DataExplorer
             {...mockDataExplorerProps()}
-            items={["Item 1"]}
+            items={[{ name: "item 1" }]}
             page={10}
             rowsPerPage={50}
             onChangePage={onChangePage}
@@ -115,6 +95,7 @@ describe("<DataExplorer />", () => {
 const mockDataExplorerProps = () => ({
     columns: [],
     items: [],
+    itemsAvailable: 0,
     contextActions: [],
     searchValue: "",
     page: 0,
@@ -123,8 +104,9 @@ const mockDataExplorerProps = () => ({
     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()
+});