-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
384 additions
and
37 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...ns/lens/public/datatable_visualization/components/__snapshots__/table_basic.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
x-pack/plugins/lens/public/datatable_visualization/components/cell_value.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { mountWithIntl } from '@kbn/test/jest'; | ||
import React from 'react'; | ||
import { DataContext } from './table_basic'; | ||
import { createGridCell } from './cell_value'; | ||
import { FieldFormat } from 'src/plugins/data/public'; | ||
import { Datatable } from 'src/plugins/expressions/public'; | ||
|
||
describe('datatable cell renderer', () => { | ||
const table: Datatable = { | ||
type: 'datatable', | ||
columns: [ | ||
{ | ||
id: 'a', | ||
name: 'a', | ||
meta: { | ||
type: 'number', | ||
}, | ||
}, | ||
], | ||
rows: [{ a: 123 }], | ||
}; | ||
const CellRenderer = createGridCell( | ||
{ | ||
a: { convert: (x) => `formatted ${x}` } as FieldFormat, | ||
}, | ||
DataContext | ||
); | ||
|
||
it('renders formatted value', () => { | ||
const instance = mountWithIntl( | ||
<DataContext.Provider | ||
value={{ | ||
table, | ||
alignments: { | ||
a: 'right', | ||
}, | ||
}} | ||
> | ||
<CellRenderer | ||
rowIndex={0} | ||
columnId="a" | ||
setCellProps={() => {}} | ||
isExpandable={false} | ||
isDetails={false} | ||
isExpanded={false} | ||
/> | ||
</DataContext.Provider> | ||
); | ||
expect(instance.text()).toEqual('formatted 123'); | ||
}); | ||
|
||
it('set class with text alignment', () => { | ||
const cell = mountWithIntl( | ||
<DataContext.Provider | ||
value={{ | ||
table, | ||
alignments: { | ||
a: 'right', | ||
}, | ||
}} | ||
> | ||
<CellRenderer | ||
rowIndex={0} | ||
columnId="a" | ||
setCellProps={() => {}} | ||
isExpandable={false} | ||
isDetails={false} | ||
isExpanded={false} | ||
/> | ||
</DataContext.Provider> | ||
); | ||
expect(cell.find('.lnsTableCell').prop('className')).toContain('--right'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
x-pack/plugins/lens/public/datatable_visualization/components/dimension_editor.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiButtonGroup } from '@elastic/eui'; | ||
import { FramePublicAPI, VisualizationDimensionEditorProps } from '../../types'; | ||
import { DatatableVisualizationState } from '../visualization'; | ||
import { createMockDatasource, createMockFramePublicAPI } from '../../editor_frame_service/mocks'; | ||
import { mountWithIntl } from '@kbn/test/jest'; | ||
import { TableDimensionEditor } from './dimension_editor'; | ||
|
||
describe('data table dimension editor', () => { | ||
let frame: FramePublicAPI; | ||
let state: DatatableVisualizationState; | ||
let setState: (newState: DatatableVisualizationState) => void; | ||
let props: VisualizationDimensionEditorProps<DatatableVisualizationState>; | ||
|
||
function testState(): DatatableVisualizationState { | ||
return { | ||
layerId: 'first', | ||
columns: [ | ||
{ | ||
columnId: 'foo', | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
beforeEach(() => { | ||
state = testState(); | ||
frame = createMockFramePublicAPI(); | ||
frame.datasourceLayers = { | ||
first: createMockDatasource('test').publicAPIMock, | ||
}; | ||
frame.activeData = { | ||
first: { | ||
type: 'datatable', | ||
columns: [ | ||
{ | ||
id: 'foo', | ||
name: 'foo', | ||
meta: { | ||
type: 'string', | ||
}, | ||
}, | ||
], | ||
rows: [], | ||
}, | ||
}; | ||
setState = jest.fn(); | ||
props = { | ||
accessor: 'foo', | ||
frame, | ||
groupId: 'columns', | ||
layerId: 'first', | ||
state, | ||
setState, | ||
}; | ||
}); | ||
|
||
it('should render default alignment', () => { | ||
const instance = mountWithIntl(<TableDimensionEditor {...props} />); | ||
expect(instance.find(EuiButtonGroup).prop('idSelected')).toEqual( | ||
expect.stringContaining('left') | ||
); | ||
}); | ||
|
||
it('should render default alignment for number', () => { | ||
frame.activeData!.first.columns[0].meta.type = 'number'; | ||
const instance = mountWithIntl(<TableDimensionEditor {...props} />); | ||
expect(instance.find(EuiButtonGroup).prop('idSelected')).toEqual( | ||
expect.stringContaining('right') | ||
); | ||
}); | ||
|
||
it('should render specific alignment', () => { | ||
state.columns[0].alignment = 'center'; | ||
const instance = mountWithIntl(<TableDimensionEditor {...props} />); | ||
expect(instance.find(EuiButtonGroup).prop('idSelected')).toEqual( | ||
expect.stringContaining('center') | ||
); | ||
}); | ||
|
||
it('should set state for the right column', () => { | ||
state.columns = [ | ||
{ | ||
columnId: 'foo', | ||
}, | ||
{ | ||
columnId: 'bar', | ||
}, | ||
]; | ||
const instance = mountWithIntl(<TableDimensionEditor {...props} />); | ||
instance.find(EuiButtonGroup).prop('onChange')('center'); | ||
expect(setState).toHaveBeenCalledWith({ | ||
...state, | ||
columns: [ | ||
{ | ||
columnId: 'foo', | ||
alignment: 'center', | ||
}, | ||
{ | ||
columnId: 'bar', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.