X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f0c4e703bd7bdcf90265c96d6f714bf831f6947a..f14b66751cfaf92a2bc28331d8878789d4040e8f:/src/components/data-explorer/data-explorer.test.tsx diff --git a/src/components/data-explorer/data-explorer.test.tsx b/src/components/data-explorer/data-explorer.test.tsx index 88481ce6..33899c00 100644 --- a/src/components/data-explorer/data-explorer.test.tsx +++ b/src/components/data-explorer/data-explorer.test.tsx @@ -3,70 +3,78 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from "react"; -import { mount, configure } from "enzyme"; +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 { TablePagination } from "@material-ui/core"; +import { MockItem } from "../data-table/data-table.test"; configure({ adapter: new Adapter() }); describe("", () => { + it("communicates with ", () => { const onContextAction = jest.fn(); const dataExplorer = mount(); - + items={[{ key: "1", name: "item 1" }] as MockItem[]} + 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(), + 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 ", () => { + const onSearch = jest.fn(); + const dataExplorer = mount(); + expect(dataExplorer.find(SearchInput).prop("value")).toEqual("search value"); + dataExplorer.find(SearchInput).prop("onSearch")("new value"); + expect(onSearch).toHaveBeenCalledWith("new value"); + }); + it("communicates with ", () => { const onColumnToggle = jest.fn(); const columns = [{ name: "Column 1", render: jest.fn(), selected: true }]; const dataExplorer = mount(); - + items={[{ key: "1", name: "item 1" }] as MockItem[]} />); expect(dataExplorer.find(ColumnSelector).prop("columns")).toBe(columns); dataExplorer.find(ColumnSelector).prop("onColumnToggle")("columns"); expect(onColumnToggle).toHaveBeenCalledWith("columns"); }); - + it("communicates with ", () => { 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 items = [{ key: "1", name: "item 1" }] as MockItem[]; const dataExplorer = mount(); - - expect(dataExplorer.find(DataTable).prop("columns")).toBe(columns); + onRowClick={onRowClick} />); + 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"); @@ -75,4 +83,49 @@ describe("", () => { expect(onSortToggle).toHaveBeenCalledWith("sortToggle"); expect(onRowClick).toHaveBeenCalledWith("rowClick"); }); + + it("does not render if there is no items", () => { + const dataExplorer = mount(); + expect(dataExplorer.find(TablePagination)).toHaveLength(0); + }); + + it("communicates with ", () => { + const onChangePage = jest.fn(); + const onChangeRowsPerPage = jest.fn(); + const dataExplorer = mount(); + expect(dataExplorer.find(TablePagination).prop("page")).toEqual(10); + expect(dataExplorer.find(TablePagination).prop("rowsPerPage")).toEqual(50); + dataExplorer.find(TablePagination).prop("onChangePage")(undefined, 6); + dataExplorer.find(TablePagination).prop("onChangeRowsPerPage")({ target: { value: 10 } }); + expect(onChangePage).toHaveBeenCalledWith(6); + expect(onChangeRowsPerPage).toHaveBeenCalledWith(10); + }); +}); + +const mockDataExplorerProps = () => ({ + columns: [], + items: [], + itemsAvailable: 0, + contextActions: [], + searchValue: "", + page: 0, + rowsPerPage: 0, + onSearch: jest.fn(), + onFiltersChange: jest.fn(), + onSortToggle: jest.fn(), + onRowClick: jest.fn(), + onColumnToggle: jest.fn(), + onContextAction: jest.fn(), + onChangePage: jest.fn(), + onChangeRowsPerPage: jest.fn() }); \ No newline at end of file