Add search input communication test, fix context menu communication test
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Thu, 21 Jun 2018 14:36:48 +0000 (16:36 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Thu, 21 Jun 2018 14:36:48 +0000 (16:36 +0200)
Feature #13633

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/components/data-explorer/data-explorer.test.tsx

index 88481ce6b704b37092628020614180fbf572d27c..8ced6cb32a6083beaf82dfc7ab838cc4b8d3f694 100644 (file)
@@ -10,6 +10,7 @@ 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";
 
 configure({ adapter: new Adapter() });
 
@@ -17,39 +18,44 @@ 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 }]}
-            onColumnToggle={jest.fn()}
-            onFiltersChange={jest.fn()}
-            onRowClick={jest.fn()}
-            onSortToggle={jest.fn()} />);
-
+            columns={[{ name: "Column 1", render: jest.fn(), selected: true }]} />);
         expect(dataExplorer.find(ContextMenu).prop("actions")).toEqual([]);
-        dataExplorer.setState({ contextMenu: { item: "Item 1" } });
+        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 dataExplorer = mount(<DataExplorer
+            {...mockDataExplorerProps()}
+            searchValue="search value"
+            onSearch={onSearch}/>);
+        expect(dataExplorer.find(SearchInput).prop("value")).toEqual("search value");
+        dataExplorer.find(SearchInput).prop("onSearch")("new value");
+        expect(onSearch).toHaveBeenCalledWith("new value");
+    });
+
     it("communicates with <ColumnSelector/>", () => {
         const onColumnToggle = jest.fn();
         const columns = [{ name: "Column 1", render: jest.fn(), selected: true }];
         const dataExplorer = mount(<DataExplorer
+            {...mockDataExplorerProps()}
             columns={columns}
             onColumnToggle={onColumnToggle}
             contextActions={[]}
-            onContextAction={jest.fn()}
-            items={["Item 1"]}
-            onFiltersChange={jest.fn()}
-            onRowClick={jest.fn()}
-            onSortToggle={jest.fn()} />);
-
+            items={["Item 1"]} />);
         expect(dataExplorer.find(ColumnSelector).prop("columns")).toBe(columns);
         dataExplorer.find(ColumnSelector).prop("onColumnToggle")("columns");
         expect(onColumnToggle).toHaveBeenCalledWith("columns");
     });
-    
+
     it("communicates with <DataTable/>", () => {
         const onFiltersChange = jest.fn();
         const onSortToggle = jest.fn();
@@ -57,15 +63,12 @@ describe("<DataExplorer />", () => {
         const columns = [{ name: "Column 1", render: jest.fn(), selected: true }];
         const items = ["Item 1"];
         const dataExplorer = mount(<DataExplorer
+            {...mockDataExplorerProps()}
             columns={columns}
             items={items}
             onFiltersChange={onFiltersChange}
             onSortToggle={onSortToggle}
-            onRowClick={onRowClick}
-            onColumnToggle={jest.fn()}
-            contextActions={[]}
-            onContextAction={jest.fn()} />);
-
+            onRowClick={onRowClick} />);
         expect(dataExplorer.find(DataTable).prop("columns")).toBe(columns);
         expect(dataExplorer.find(DataTable).prop("items")).toBe(items);
         dataExplorer.find(DataTable).prop("onRowClick")("event", "rowClick");
@@ -75,4 +78,17 @@ describe("<DataExplorer />", () => {
         expect(onSortToggle).toHaveBeenCalledWith("sortToggle");
         expect(onRowClick).toHaveBeenCalledWith("rowClick");
     });
+});
+
+const mockDataExplorerProps = () => ({
+    columns: [],
+    items: [],
+    contextActions: [],
+    searchValue: "",
+    onSearch: jest.fn(),
+    onFiltersChange: jest.fn(),
+    onSortToggle: jest.fn(),
+    onRowClick: jest.fn(),
+    onColumnToggle: jest.fn(),
+    onContextAction: jest.fn()
 });
\ No newline at end of file