1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { mount, configure } from "enzyme";
7 import * as Adapter from "enzyme-adapter-react-16";
8 import DataTable from "./data-table";
9 import { DataColumn } from "./data-column";
10 import { TableHead, TableCell, Typography, TableBody, Button } from "@material-ui/core";
12 configure({ adapter: new Adapter() });
14 describe("<DataTable />", () => {
15 it("shows only selected columns", () => {
16 const columns: Array<DataColumn<string>> = [
19 render: () => <span />,
24 render: () => <span />,
29 render: () => <span />,
33 const dataTable = mount(<DataTable columns={columns} items={["item 1"]}/>);
34 expect(dataTable.find(TableHead).find(TableCell)).toHaveLength(2);
37 it("renders column name", () => {
38 const columns: Array<DataColumn<string>> = [
41 render: () => <span />,
45 const dataTable = mount(<DataTable columns={columns} items={["item 1"]}/>);
46 expect(dataTable.find(TableHead).find(TableCell).text()).toBe("Column 1");
49 it("uses renderHeader instead of name prop", () => {
50 const columns: Array<DataColumn<string>> = [
53 renderHeader: () => <span>Column Header</span>,
54 render: () => <span />,
58 const dataTable = mount(<DataTable columns={columns} items={["item 1"]}/>);
59 expect(dataTable.find(TableHead).find(TableCell).text()).toBe("Column Header");
62 it("passes column key prop to corresponding cells", () => {
63 const columns: Array<DataColumn<string>> = [
67 render: () => <span />,
71 const dataTable = mount(<DataTable columns={columns} items={["item 1"]}/>);
72 expect(dataTable.find(TableHead).find(TableCell).key()).toBe("column-1-key");
73 expect(dataTable.find(TableBody).find(TableCell).key()).toBe("column-1-key");
76 it("shows information that items array is empty", () => {
77 const columns: Array<DataColumn<string>> = [
80 render: () => <span />,
84 const dataTable = mount(<DataTable columns={columns} items={[]}/>);
85 expect(dataTable.find(Typography).text()).toBe("No items");
88 it("renders items", () => {
89 const columns: Array<DataColumn<string>> = [
92 render: (item) => <Typography>{item}</Typography>,
97 render: (item) => <Button>{item}</Button>,
101 const dataTable = mount(<DataTable columns={columns} items={["item 1"]}/>);
102 expect(dataTable.find(TableBody).find(Typography).text()).toBe("item 1");
103 expect(dataTable.find(TableBody).find(Button).text()).toBe("item 1");