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 { ColumnSelector, ColumnSelectorTrigger } from "./column-selector";
9 import { ListItem, Checkbox } from "@material-ui/core";
10 import { DataColumns } from "../data-table/data-table";
12 configure({ adapter: new Adapter() });
14 describe("<ColumnSelector />", () => {
15 it("shows only configurable columns", () => {
16 const columns: DataColumns<void> = [
19 render: () => <span />,
25 render: () => <span />,
31 render: () => <span />,
36 const columnsConfigurator = mount(<ColumnSelector columns={columns} onColumnToggle={jest.fn()} />);
37 columnsConfigurator.find(ColumnSelectorTrigger).simulate("click");
38 expect(columnsConfigurator.find(ListItem)).toHaveLength(2);
41 it("renders checked checkboxes next to selected columns", () => {
42 const columns: DataColumns<void> = [
45 render: () => <span />,
51 render: () => <span />,
57 render: () => <span />,
62 const columnsConfigurator = mount(<ColumnSelector columns={columns} onColumnToggle={jest.fn()} />);
63 columnsConfigurator.find(ColumnSelectorTrigger).simulate("click");
64 expect(columnsConfigurator.find(Checkbox).at(0).prop("checked")).toBe(true);
65 expect(columnsConfigurator.find(Checkbox).at(1).prop("checked")).toBe(false);
66 expect(columnsConfigurator.find(Checkbox).at(2).prop("checked")).toBe(true);
69 it("calls onColumnToggle with clicked column", () => {
70 const columns: DataColumns<void> = [
73 render: () => <span />,
78 const onColumnToggle = jest.fn();
79 const columnsConfigurator = mount(<ColumnSelector columns={columns} onColumnToggle={onColumnToggle} />);
80 columnsConfigurator.find(ColumnSelectorTrigger).simulate("click");
81 columnsConfigurator.find(ListItem).simulate("click");
82 expect(onColumnToggle).toHaveBeenCalledWith(columns[0]);