X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/78915a29d2911b1c442920b614f3e48da9e567c2..e8d0331277033fea37a9fd73ffc781ffca8759f0:/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 726972e028..2ee350724a 100644
--- a/src/components/data-table/data-table.test.tsx
+++ b/src/components/data-table/data-table.test.tsx
@@ -6,15 +6,19 @@ import * as React from "react";
 import { mount, configure } from "enzyme";
 import { TableHead, TableCell, Typography, TableBody, Button, TableSortLabel } from "@material-ui/core";
 import * as Adapter from "enzyme-adapter-react-16";
-import DataTable from "./data-table";
-import { DataColumn } from "./data-column";
+import DataTable, { DataColumns, DataItem } from "./data-table";
 import DataTableFilters from "../data-table-filters/data-table-filters";
+import { SortDirection } from "./data-column";
 
 configure({ adapter: new Adapter() });
 
+export interface MockItem extends DataItem {
+    name: string;
+}
+
 describe("<DataTable />", () => {
     it("shows only selected columns", () => {
-        const columns: Array<DataColumn<string>> = [
+        const columns: DataColumns<MockItem> = [
             {
                 name: "Column 1",
                 render: () => <span />,
@@ -33,16 +37,16 @@ describe("<DataTable />", () => {
         ];
         const dataTable = mount(<DataTable
             columns={columns}
-            items={["item 1"]}
+            items={[{ key: "1", name: "item 1" }] as MockItem[]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
+            onContextMenu={jest.fn()}
             onSortToggle={jest.fn()} />);
         expect(dataTable.find(TableHead).find(TableCell)).toHaveLength(2);
     });
 
     it("renders column name", () => {
-        const columns: Array<DataColumn<string>> = [
+        const columns: DataColumns<MockItem> = [
             {
                 name: "Column 1",
                 render: () => <span />,
@@ -51,16 +55,16 @@ describe("<DataTable />", () => {
         ];
         const dataTable = mount(<DataTable
             columns={columns}
-            items={["item 1"]}
+            items={[{ key: "1", name: "item 1" }] as MockItem[]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
+            onContextMenu={jest.fn()}
             onSortToggle={jest.fn()} />);
         expect(dataTable.find(TableHead).find(TableCell).text()).toBe("Column 1");
     });
 
     it("uses renderHeader instead of name prop", () => {
-        const columns: Array<DataColumn<string>> = [
+        const columns: DataColumns<MockItem> = [
             {
                 name: "Column 1",
                 renderHeader: () => <span>Column Header</span>,
@@ -70,16 +74,16 @@ describe("<DataTable />", () => {
         ];
         const dataTable = mount(<DataTable
             columns={columns}
-            items={["item 1"]}
+            items={[{ key: "1", name: "item 1" }] as MockItem[]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
+            onContextMenu={jest.fn()}
             onSortToggle={jest.fn()} />);
         expect(dataTable.find(TableHead).find(TableCell).text()).toBe("Column Header");
     });
 
     it("passes column key prop to corresponding cells", () => {
-        const columns: Array<DataColumn<string>> = [
+        const columns: DataColumns<MockItem> = [
             {
                 name: "Column 1",
                 key: "column-1-key",
@@ -89,75 +93,75 @@ describe("<DataTable />", () => {
         ];
         const dataTable = mount(<DataTable
             columns={columns}
-            items={["item 1"]}
+            items={[{ key: "1", name: "item 1" }] as MockItem[]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
+            onContextMenu={jest.fn()}
             onSortToggle={jest.fn()} />);
         expect(dataTable.find(TableHead).find(TableCell).key()).toBe("column-1-key");
         expect(dataTable.find(TableBody).find(TableCell).key()).toBe("column-1-key");
     });
 
     it("renders items", () => {
-        const columns: Array<DataColumn<string>> = [
+        const columns: DataColumns<MockItem> = [
             {
                 name: "Column 1",
-                render: (item) => <Typography>{item}</Typography>,
+                render: (item) => <Typography>{item.name}</Typography>,
                 selected: true
             },
             {
                 name: "Column 2",
-                render: (item) => <Button>{item}</Button>,
+                render: (item) => <Button>{item.name}</Button>,
                 selected: true
             }
         ];
-        const dataTable = mount(<DataTable 
-            columns={columns} 
-            items={["item 1"]}
+        const dataTable = mount(<DataTable
+            columns={columns}
+            items={[{ key: "1", name: "item 1" }] as MockItem[]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
+            onContextMenu={jest.fn()}
             onSortToggle={jest.fn()} />);
         expect(dataTable.find(TableBody).find(Typography).text()).toBe("item 1");
         expect(dataTable.find(TableBody).find(Button).text()).toBe("item 1");
     });
 
     it("passes sorting props to <TableSortLabel />", () => {
-        const columns: Array<DataColumn<string>> = [{
+        const columns: DataColumns<MockItem> = [{
             name: "Column 1",
-            sortDirection: "asc",
+            sortDirection: SortDirection.Asc,
             selected: true,
-            render: (item) => <Typography>{item}</Typography>
+            render: (item) => <Typography>{item.name}</Typography>
         }];
         const onSortToggle = jest.fn();
-        const dataTable = mount(<DataTable 
-            columns={columns} 
-            items={["item 1"]} 
+        const dataTable = mount(<DataTable
+            columns={columns}
+            items={[{ key: "1", name: "item 1" }] as MockItem[]}
             onFiltersChange={jest.fn()}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
-            onSortToggle={onSortToggle}/>);
+            onContextMenu={jest.fn()}
+            onSortToggle={onSortToggle} />);
         expect(dataTable.find(TableSortLabel).prop("active")).toBeTruthy();
         dataTable.find(TableSortLabel).at(0).simulate("click");
         expect(onSortToggle).toHaveBeenCalledWith(columns[0]);
     });
 
     it("passes filter props to <DataTableFilter />", () => {
-        const columns: Array<DataColumn<string>> = [{
+        const columns: DataColumns<MockItem> = [{
             name: "Column 1",
-            sortDirection: "asc",
+            sortDirection: SortDirection.Asc,
             selected: true,
-            filters: [{name: "Filter 1", selected: true}],
-            render: (item) => <Typography>{item}</Typography>
+            filters: [{ name: "Filter 1", selected: true }],
+            render: (item) => <Typography>{item.name}</Typography>
         }];
         const onFiltersChange = jest.fn();
-        const dataTable = mount(<DataTable 
-            columns={columns} 
-            items={["item 1"]} 
+        const dataTable = mount(<DataTable
+            columns={columns}
+            items={[{ key: "1", name: "item 1" }] as MockItem[]}
             onFiltersChange={onFiltersChange}
             onRowClick={jest.fn()}
-            onRowContextMenu={jest.fn()}
-            onSortToggle={jest.fn()}/>);
+            onSortToggle={jest.fn()}
+            onContextMenu={jest.fn()} />);
         expect(dataTable.find(DataTableFilters).prop("filters")).toBe(columns[0].filters);
         dataTable.find(DataTableFilters).prop("onChange")([]);
         expect(onFiltersChange).toHaveBeenCalledWith([], columns[0]);
