[ARVADOS-WORKBENCH2] created: 1.2.0-122-g7d8ec25
Git user
git at public.curoverse.com
Wed Aug 22 05:03:05 EDT 2018
at 7d8ec252adacdae04d5ee9d4c1b79e64267b1288 (commit)
commit 7d8ec252adacdae04d5ee9d4c1b79e64267b1288
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Wed Aug 22 11:02:55 2018 +0200
Update data-table tests
Feature #14095
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/src/components/data-table/data-column.ts b/src/components/data-table/data-column.ts
index d4e23ab..90e87a8 100644
--- a/src/components/data-table/data-column.ts
+++ b/src/components/data-table/data-column.ts
@@ -2,8 +2,8 @@
//
// SPDX-License-Identifier: AGPL-3.0
-import { DataTableFilterItem } from "../data-table-filters/data-table-filters";
import * as React from "react";
+import { DataTableFilterItem } from "../data-table-filters/data-table-filters";
export interface DataColumn<T, F extends DataTableFilterItem = DataTableFilterItem> {
key?: React.Key;
@@ -34,3 +34,14 @@ export const toggleSortDirection = <T>(column: DataColumn<T>): DataColumn<T> =>
export const resetSortDirection = <T>(column: DataColumn<T>): DataColumn<T> => {
return column.sortDirection ? { ...column, sortDirection: SortDirection.NONE } : column;
};
+
+export const createDataColumn = <T, F extends DataTableFilterItem>(dataColumn: Partial<DataColumn<T, F>>): DataColumn<T, F> => ({
+ key: '',
+ name: '',
+ selected: true,
+ configurable: true,
+ sortDirection: SortDirection.NONE,
+ filters: [],
+ render: () => React.createElement('span'),
+ ...dataColumn,
+});
diff --git a/src/components/data-table/data-table.test.tsx b/src/components/data-table/data-table.test.tsx
index 77c7825..1201dcb 100644
--- a/src/components/data-table/data-table.test.tsx
+++ b/src/components/data-table/data-table.test.tsx
@@ -8,31 +8,31 @@ import { TableHead, TableCell, Typography, TableBody, Button, TableSortLabel } f
import * as Adapter from "enzyme-adapter-react-16";
import { DataTable, DataColumns } from "./data-table";
import { DataTableFilters } from "../data-table-filters/data-table-filters";
-import { SortDirection } from "./data-column";
+import { SortDirection, createDataColumn } from "./data-column";
configure({ adapter: new Adapter() });
describe("<DataTable />", () => {
it("shows only selected columns", () => {
const columns: DataColumns<string> = [
- {
+ createDataColumn({
name: "Column 1",
render: () => <span />,
selected: true,
configurable: true
- },
- {
+ }),
+ createDataColumn({
name: "Column 2",
render: () => <span />,
selected: true,
configurable: true
- },
- {
+ }),
+ createDataColumn({
name: "Column 3",
render: () => <span />,
selected: false,
configurable: true
- }
+ }),
];
const dataTable = mount(<DataTable
columns={columns}
@@ -47,12 +47,12 @@ describe("<DataTable />", () => {
it("renders column name", () => {
const columns: DataColumns<string> = [
- {
+ createDataColumn({
name: "Column 1",
render: () => <span />,
selected: true,
configurable: true
- }
+ }),
];
const dataTable = mount(<DataTable
columns={columns}
@@ -67,13 +67,13 @@ describe("<DataTable />", () => {
it("uses renderHeader instead of name prop", () => {
const columns: DataColumns<string> = [
- {
+ createDataColumn({
name: "Column 1",
renderHeader: () => <span>Column Header</span>,
render: () => <span />,
selected: true,
configurable: true
- }
+ }),
];
const dataTable = mount(<DataTable
columns={columns}
@@ -88,13 +88,13 @@ describe("<DataTable />", () => {
it("passes column key prop to corresponding cells", () => {
const columns: DataColumns<string> = [
- {
+ createDataColumn({
name: "Column 1",
key: "column-1-key",
render: () => <span />,
selected: true,
configurable: true
- }
+ })
];
const dataTable = mount(<DataTable
columns={columns}
@@ -110,18 +110,18 @@ describe("<DataTable />", () => {
it("renders items", () => {
const columns: DataColumns<string> = [
- {
+ createDataColumn({
name: "Column 1",
render: (item) => <Typography>{item}</Typography>,
selected: true,
configurable: true
- },
- {
+ }),
+ createDataColumn({
name: "Column 2",
render: (item) => <Button>{item}</Button>,
selected: true,
configurable: true
- }
+ })
];
const dataTable = mount(<DataTable
columns={columns}
@@ -136,13 +136,14 @@ describe("<DataTable />", () => {
});
it("passes sorting props to <TableSortLabel />", () => {
- const columns: DataColumns<string> = [{
+ const columns: DataColumns<string> = [
+ createDataColumn({
name: "Column 1",
sortDirection: SortDirection.ASC,
selected: true,
configurable: true,
render: (item) => <Typography>{item}</Typography>
- }];
+ })];
const onSortToggle = jest.fn();
const dataTable = mount(<DataTable
columns={columns}
@@ -157,6 +158,27 @@ describe("<DataTable />", () => {
expect(onSortToggle).toHaveBeenCalledWith(columns[0]);
});
+ it("does not display <DataTableFilter /> if there is no filters provided", () => {
+ const columns: DataColumns<string> = [{
+ name: "Column 1",
+ sortDirection: SortDirection.ASC,
+ selected: true,
+ configurable: true,
+ filters: [],
+ render: (item) => <Typography>{item}</Typography>
+ }];
+ const onFiltersChange = jest.fn();
+ const dataTable = mount(<DataTable
+ columns={columns}
+ items={[]}
+ onFiltersChange={onFiltersChange}
+ onRowClick={jest.fn()}
+ onRowDoubleClick={jest.fn()}
+ onSortToggle={jest.fn()}
+ onContextMenu={jest.fn()} />);
+ expect(dataTable.find(DataTableFilters)).toHaveLength(0);
+ });
+
it("passes filter props to <DataTableFilter />", () => {
const columns: DataColumns<string> = [{
name: "Column 1",
commit d0f49b7683fe607b6165c0232ff220080142eb57
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Wed Aug 22 11:02:40 2018 +0200
Update condition for displaying filters
Feature #14095
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/src/components/data-table/data-table.tsx b/src/components/data-table/data-table.tsx
index 34f8168..5a6f9e5 100644
--- a/src/components/data-table/data-table.tsx
+++ b/src/components/data-table/data-table.tsx
@@ -63,7 +63,7 @@ export const DataTable = withStyles(styles)(
return <TableCell key={key || index} style={{ width: column.width, minWidth: column.width }}>
{renderHeader ?
renderHeader() :
- filters
+ filters.length > 0
? <DataTableFilters
name={`${name} filters`}
onChange={filters =>
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list