Skip to content

Commit c7887ba

Browse files
Merge branch 'master' into 88307-use-dataset-is-prefix
2 parents 0367454 + 4a1946b commit c7887ba

13 files changed

Lines changed: 1160 additions & 4 deletions

src/plugins/vis_type_table/public/components/__snapshots__/table_vis_basic.test.tsx.snap

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/vis_type_table/public/components/__snapshots__/table_vis_cell.test.tsx.snap

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import React from 'react';
10+
import { shallow } from 'enzyme';
11+
import { TableVisBasic } from './table_vis_basic';
12+
import { FormattedColumn, TableVisConfig, TableVisUiState } from '../types';
13+
import { DatatableColumn } from 'src/plugins/expressions';
14+
import { createTableVisCell } from './table_vis_cell';
15+
import { createGridColumns } from './table_vis_columns';
16+
17+
jest.mock('./table_vis_columns', () => ({
18+
createGridColumns: jest.fn(() => []),
19+
}));
20+
jest.mock('./table_vis_cell', () => ({
21+
createTableVisCell: jest.fn(() => () => {}),
22+
}));
23+
24+
describe('TableVisBasic', () => {
25+
const props = {
26+
fireEvent: jest.fn(),
27+
table: {
28+
columns: [],
29+
rows: [],
30+
formattedColumns: {
31+
test: {
32+
formattedTotal: 100,
33+
} as FormattedColumn,
34+
},
35+
},
36+
visConfig: {} as TableVisConfig,
37+
uiStateProps: {
38+
sort: {
39+
columnIndex: null,
40+
direction: null,
41+
},
42+
columnsWidth: [],
43+
setColumnsWidth: jest.fn(),
44+
setSort: jest.fn(),
45+
},
46+
};
47+
48+
it('should init data grid', () => {
49+
const comp = shallow(<TableVisBasic {...props} />);
50+
expect(comp).toMatchSnapshot();
51+
});
52+
53+
it('should init data grid with title provided - for split mode', () => {
54+
const title = 'My data table';
55+
const comp = shallow(<TableVisBasic {...props} title={title} />);
56+
expect(comp).toMatchSnapshot();
57+
});
58+
59+
it('should render the toolbar', () => {
60+
const comp = shallow(
61+
<TableVisBasic
62+
{...props}
63+
visConfig={{ ...props.visConfig, title: 'My saved vis', showToolbar: true }}
64+
/>
65+
);
66+
expect(comp).toMatchSnapshot();
67+
});
68+
69+
it('should sort rows by column and pass the sorted rows for consumers', () => {
70+
const uiStateProps = {
71+
...props.uiStateProps,
72+
sort: {
73+
columnIndex: 1,
74+
direction: 'desc',
75+
} as TableVisUiState['sort'],
76+
};
77+
const table = {
78+
columns: [{ id: 'first' }, { id: 'second' }] as DatatableColumn[],
79+
rows: [
80+
{ first: 1, second: 2 },
81+
{ first: 3, second: 4 },
82+
{ first: 5, second: 6 },
83+
],
84+
formattedColumns: {},
85+
};
86+
const sortedRows = [
87+
{ first: 5, second: 6 },
88+
{ first: 3, second: 4 },
89+
{ first: 1, second: 2 },
90+
];
91+
const comp = shallow(
92+
<TableVisBasic
93+
{...props}
94+
table={table}
95+
uiStateProps={uiStateProps}
96+
visConfig={{ ...props.visConfig, showToolbar: true }}
97+
/>
98+
);
99+
expect(createTableVisCell).toHaveBeenCalledWith(sortedRows, table.formattedColumns);
100+
expect(createGridColumns).toHaveBeenCalledWith(
101+
table.columns,
102+
sortedRows,
103+
table.formattedColumns,
104+
uiStateProps.columnsWidth,
105+
props.fireEvent
106+
);
107+
108+
const { onSort } = comp.find('EuiDataGrid').prop('sorting');
109+
// sort the first column
110+
onSort([{ id: 'first', direction: 'asc' }]);
111+
expect(uiStateProps.setSort).toHaveBeenCalledWith({ columnIndex: 0, direction: 'asc' });
112+
// sort the second column - should erase the first column sorting since there is only one level sorting available
113+
onSort([
114+
{ id: 'first', direction: 'asc' },
115+
{ id: 'second', direction: 'desc' },
116+
]);
117+
expect(uiStateProps.setSort).toHaveBeenCalledWith({ columnIndex: 1, direction: 'desc' });
118+
});
119+
120+
it('should pass renderFooterCellValue for the total row', () => {
121+
const comp = shallow(
122+
<TableVisBasic {...props} visConfig={{ ...props.visConfig, showTotal: true }} />
123+
);
124+
const renderFooterCellValue: (props: any) => void = comp
125+
.find('EuiDataGrid')
126+
.prop('renderFooterCellValue');
127+
expect(renderFooterCellValue).toEqual(expect.any(Function));
128+
expect(renderFooterCellValue({ columnId: 'test' })).toEqual(100);
129+
});
130+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import React from 'react';
10+
import { shallow } from 'enzyme';
11+
import { EuiDataGridCellValueElementProps } from '@elastic/eui';
12+
import { createTableVisCell } from './table_vis_cell';
13+
import { FormattedColumns } from '../types';
14+
15+
describe('table vis cell', () => {
16+
it('should return a cell component with data in scope', () => {
17+
const rows = [{ first: 1, second: 2 }];
18+
const formattedColumns = ({
19+
second: {
20+
formatter: {
21+
convert: jest.fn(),
22+
},
23+
},
24+
} as unknown) as FormattedColumns;
25+
const Cell = createTableVisCell(rows, formattedColumns);
26+
const cellProps = {
27+
rowIndex: 0,
28+
columnId: 'second',
29+
} as EuiDataGridCellValueElementProps;
30+
31+
const comp = shallow(<Cell {...cellProps} />);
32+
33+
expect(comp).toMatchSnapshot();
34+
expect(formattedColumns.second.formatter.convert).toHaveBeenLastCalledWith(2, 'html');
35+
});
36+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
jest.mock('../utils', () => ({
10+
useUiState: jest.fn(() => 'uiState'),
11+
}));
12+
13+
import React from 'react';
14+
import { shallow } from 'enzyme';
15+
import { IInterpreterRenderHandlers } from 'src/plugins/expressions';
16+
import { coreMock } from '../../../../core/public/mocks';
17+
import { TableVisConfig, TableVisData } from '../types';
18+
import TableVisualizationComponent from './table_visualization';
19+
import { useUiState } from '../utils';
20+
21+
describe('TableVisualizationComponent', () => {
22+
const coreStartMock = coreMock.createStart();
23+
const handlers = ({
24+
done: jest.fn(),
25+
uiState: 'uiState',
26+
event: 'event',
27+
} as unknown) as IInterpreterRenderHandlers;
28+
const visData: TableVisData = {
29+
table: {
30+
columns: [],
31+
rows: [],
32+
formattedColumns: {},
33+
},
34+
tables: [],
35+
};
36+
const visConfig = ({} as unknown) as TableVisConfig;
37+
38+
it('should render the basic table', () => {
39+
const comp = shallow(
40+
<TableVisualizationComponent
41+
core={coreStartMock}
42+
handlers={handlers}
43+
visData={visData}
44+
visConfig={visConfig}
45+
/>
46+
);
47+
expect(useUiState).toHaveBeenLastCalledWith(handlers.uiState);
48+
expect(comp.find('.tbvChart__splitColumns').exists()).toBeFalsy();
49+
expect(comp.find('.tbvChart__split').exists()).toBeTruthy();
50+
});
51+
52+
it('should render split table', () => {
53+
const comp = shallow(
54+
<TableVisualizationComponent
55+
core={coreStartMock}
56+
handlers={handlers}
57+
visData={{
58+
direction: 'column',
59+
tables: [],
60+
}}
61+
visConfig={visConfig}
62+
/>
63+
);
64+
expect(useUiState).toHaveBeenLastCalledWith(handlers.uiState);
65+
expect(comp.find('.tbvChart__splitColumns').exists()).toBeTruthy();
66+
expect(comp.find('.tbvChart__split').exists()).toBeFalsy();
67+
expect(comp.find('[data-test-subj="tbvChart"]').children().prop('tables')).toEqual([]);
68+
});
69+
});

0 commit comments

Comments
 (0)