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 />,
24 render: () => <span />,
30 render: () => <span />,
35 const columnsConfigurator = mount(<ColumnSelector columns={columns} onColumnToggle={jest.fn()} />);
36 columnsConfigurator.find(ColumnSelectorTrigger).simulate("click");
37 expect(columnsConfigurator.find(ListItem)).toHaveLength(2);
40 it("renders checked checkboxes next to selected columns", () => {
41 const columns: DataColumns<void> = [
44 render: () => <span />,
49 render: () => <span />,
54 render: () => <span />,
58 const columnsConfigurator = mount(<ColumnSelector columns={columns} onColumnToggle={jest.fn()} />);
59 columnsConfigurator.find(ColumnSelectorTrigger).simulate("click");
60 expect(columnsConfigurator.find(Checkbox).at(0).prop("checked")).toBe(true);
61 expect(columnsConfigurator.find(Checkbox).at(1).prop("checked")).toBe(false);
62 expect(columnsConfigurator.find(Checkbox).at(2).prop("checked")).toBe(true);
65 it("calls onColumnToggle with clicked column", () => {
66 const columns: DataColumns<void> = [
69 render: () => <span />,
73 const onColumnToggle = jest.fn();
74 const columnsConfigurator = mount(<ColumnSelector columns={columns} onColumnToggle={onColumnToggle} />);
75 columnsConfigurator.find(ColumnSelectorTrigger).simulate("click");
76 columnsConfigurator.find(ListItem).simulate("click");
77 expect(onColumnToggle).toHaveBeenCalledWith(columns[0]);