Skip to content

Commit 48563ae

Browse files
Merge branch 'master' into misc/ignore-unknown-keys
2 parents 9812671 + b9cc3e9 commit 48563ae

80 files changed

Lines changed: 4505 additions & 7425 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

x-pack/legacy/plugins/lens/public/_config_panel.scss

Lines changed: 0 additions & 21 deletions
This file was deleted.

x-pack/legacy/plugins/lens/public/datatable_visualization/visualization.test.tsx

Lines changed: 80 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,9 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React from 'react';
87
import { createMockDatasource } from '../editor_frame_service/mocks';
9-
import {
10-
DatatableVisualizationState,
11-
datatableVisualization,
12-
DataTableLayer,
13-
} from './visualization';
14-
import { mount } from 'enzyme';
8+
import { DatatableVisualizationState, datatableVisualization } from './visualization';
159
import { Operation, DataType, FramePublicAPI, TableSuggestionColumn } from '../types';
16-
import { generateId } from '../id_generator';
17-
18-
jest.mock('../id_generator');
1910

2011
function mockFrame(): FramePublicAPI {
2112
return {
@@ -34,12 +25,11 @@ function mockFrame(): FramePublicAPI {
3425
describe('Datatable Visualization', () => {
3526
describe('#initialize', () => {
3627
it('should initialize from the empty state', () => {
37-
(generateId as jest.Mock).mockReturnValueOnce('id');
3828
expect(datatableVisualization.initialize(mockFrame(), undefined)).toEqual({
3929
layers: [
4030
{
4131
layerId: 'aaa',
42-
columns: ['id'],
32+
columns: [],
4333
},
4434
],
4535
});
@@ -88,7 +78,6 @@ describe('Datatable Visualization', () => {
8878

8979
describe('#clearLayer', () => {
9080
it('should reset the layer', () => {
91-
(generateId as jest.Mock).mockReturnValueOnce('testid');
9281
const state: DatatableVisualizationState = {
9382
layers: [
9483
{
@@ -101,7 +90,7 @@ describe('Datatable Visualization', () => {
10190
layers: [
10291
{
10392
layerId: 'baz',
104-
columns: ['testid'],
93+
columns: [],
10594
},
10695
],
10796
});
@@ -214,29 +203,35 @@ describe('Datatable Visualization', () => {
214203
});
215204
});
216205

217-
describe('DataTableLayer', () => {
218-
it('allows all kinds of operations', () => {
219-
const setState = jest.fn();
220-
const datasource = createMockDatasource();
221-
const layer = { layerId: 'a', columns: ['b', 'c'] };
206+
describe('#getConfiguration', () => {
207+
it('returns a single layer option', () => {
208+
const datasource = createMockDatasource('test');
222209
const frame = mockFrame();
223-
frame.datasourceLayers = { a: datasource.publicAPIMock };
210+
frame.datasourceLayers = { first: datasource.publicAPIMock };
224211

225-
mount(
226-
<DataTableLayer
227-
layerId="layer1"
228-
dragDropContext={{ dragging: undefined, setDragging: () => {} }}
229-
frame={frame}
230-
layer={layer}
231-
setState={setState}
232-
state={{ layers: [layer] }}
233-
/>
234-
);
212+
expect(
213+
datatableVisualization.getConfiguration({
214+
layerId: 'first',
215+
state: {
216+
layers: [{ layerId: 'first', columns: [] }],
217+
},
218+
frame,
219+
}).groups
220+
).toHaveLength(1);
221+
});
235222

236-
expect(datasource.publicAPIMock.renderDimensionPanel).toHaveBeenCalled();
223+
it('allows all kinds of operations', () => {
224+
const datasource = createMockDatasource('test');
225+
const frame = mockFrame();
226+
frame.datasourceLayers = { first: datasource.publicAPIMock };
237227

238-
const filterOperations =
239-
datasource.publicAPIMock.renderDimensionPanel.mock.calls[0][1].filterOperations;
228+
const filterOperations = datatableVisualization.getConfiguration({
229+
layerId: 'first',
230+
state: {
231+
layers: [{ layerId: 'first', columns: [] }],
232+
},
233+
frame,
234+
}).groups[0].filterOperations;
240235

241236
const baseOperation: Operation = {
242237
dataType: 'string',
@@ -253,108 +248,80 @@ describe('Datatable Visualization', () => {
253248
);
254249
});
255250

256-
it('allows columns to be removed', () => {
257-
const setState = jest.fn();
258-
const datasource = createMockDatasource();
251+
it('reorders the rendered colums based on the order from the datasource', () => {
252+
const datasource = createMockDatasource('test');
259253
const layer = { layerId: 'a', columns: ['b', 'c'] };
260254
const frame = mockFrame();
261255
frame.datasourceLayers = { a: datasource.publicAPIMock };
262-
const component = mount(
263-
<DataTableLayer
264-
layerId="layer1"
265-
dragDropContext={{ dragging: undefined, setDragging: () => {} }}
266-
frame={frame}
267-
layer={layer}
268-
setState={setState}
269-
state={{ layers: [layer] }}
270-
/>
271-
);
272-
273-
const onRemove = component
274-
.find('[data-test-subj="datatable_multicolumnEditor"]')
275-
.first()
276-
.prop('onRemove') as (k: string) => {};
277-
278-
onRemove('b');
256+
datasource.publicAPIMock.getTableSpec.mockReturnValue([{ columnId: 'c' }, { columnId: 'b' }]);
257+
258+
expect(
259+
datatableVisualization.getConfiguration({
260+
layerId: 'a',
261+
state: { layers: [layer] },
262+
frame,
263+
}).groups[0].accessors
264+
).toEqual(['c', 'b']);
265+
});
266+
});
279267

280-
expect(setState).toHaveBeenCalledWith({
268+
describe('#removeDimension', () => {
269+
it('allows columns to be removed', () => {
270+
const layer = { layerId: 'layer1', columns: ['b', 'c'] };
271+
expect(
272+
datatableVisualization.removeDimension({
273+
prevState: { layers: [layer] },
274+
layerId: 'layer1',
275+
columnId: 'b',
276+
})
277+
).toEqual({
281278
layers: [
282279
{
283-
layerId: 'a',
280+
layerId: 'layer1',
284281
columns: ['c'],
285282
},
286283
],
287284
});
288285
});
286+
});
289287

288+
describe('#setDimension', () => {
290289
it('allows columns to be added', () => {
291-
(generateId as jest.Mock).mockReturnValueOnce('d');
292-
const setState = jest.fn();
293-
const datasource = createMockDatasource();
294-
const layer = { layerId: 'a', columns: ['b', 'c'] };
295-
const frame = mockFrame();
296-
frame.datasourceLayers = { a: datasource.publicAPIMock };
297-
const component = mount(
298-
<DataTableLayer
299-
layerId="layer1"
300-
dragDropContext={{ dragging: undefined, setDragging: () => {} }}
301-
frame={frame}
302-
layer={layer}
303-
setState={setState}
304-
state={{ layers: [layer] }}
305-
/>
306-
);
307-
308-
const onAdd = component
309-
.find('[data-test-subj="datatable_multicolumnEditor"]')
310-
.first()
311-
.prop('onAdd') as () => {};
312-
313-
onAdd();
314-
315-
expect(setState).toHaveBeenCalledWith({
290+
const layer = { layerId: 'layer1', columns: ['b', 'c'] };
291+
expect(
292+
datatableVisualization.setDimension({
293+
prevState: { layers: [layer] },
294+
layerId: 'layer1',
295+
columnId: 'd',
296+
groupId: '',
297+
})
298+
).toEqual({
316299
layers: [
317300
{
318-
layerId: 'a',
301+
layerId: 'layer1',
319302
columns: ['b', 'c', 'd'],
320303
},
321304
],
322305
});
323306
});
324307

325-
it('reorders the rendered colums based on the order from the datasource', () => {
326-
const datasource = createMockDatasource();
327-
const layer = { layerId: 'a', columns: ['b', 'c'] };
328-
const frame = mockFrame();
329-
frame.datasourceLayers = { a: datasource.publicAPIMock };
330-
const component = mount(
331-
<DataTableLayer
332-
layerId="layer1"
333-
dragDropContext={{ dragging: undefined, setDragging: () => {} }}
334-
frame={frame}
335-
layer={layer}
336-
setState={jest.fn()}
337-
state={{ layers: [layer] }}
338-
/>
339-
);
340-
341-
const accessors = component
342-
.find('[data-test-subj="datatable_multicolumnEditor"]')
343-
.first()
344-
.prop('accessors') as string[];
345-
346-
expect(accessors).toEqual(['b', 'c']);
347-
348-
component.setProps({
349-
layer: { layerId: 'a', columns: ['c', 'b'] },
308+
it('does not set a duplicate dimension', () => {
309+
const layer = { layerId: 'layer1', columns: ['b', 'c'] };
310+
expect(
311+
datatableVisualization.setDimension({
312+
prevState: { layers: [layer] },
313+
layerId: 'layer1',
314+
columnId: 'b',
315+
groupId: '',
316+
})
317+
).toEqual({
318+
layers: [
319+
{
320+
layerId: 'layer1',
321+
columns: ['b', 'c'],
322+
},
323+
],
350324
});
351-
352-
const newAccessors = component
353-
.find('[data-test-subj="datatable_multicolumnEditor"]')
354-
.first()
355-
.prop('accessors') as string[];
356-
357-
expect(newAccessors).toEqual(['c', 'b']);
358325
});
359326
});
360327
});

0 commit comments

Comments
 (0)