-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix legend issues in pie and XY, add some tests
- Loading branch information
1 parent
56edd05
commit 0e931b4
Showing
5 changed files
with
198 additions
and
15 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
x-pack/plugins/lens/public/pie_visualization/render_function.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,113 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Settings } from '@elastic/charts'; | ||
import { shallow } from 'enzyme'; | ||
import { LensMultiTable } from '../types'; | ||
import { PieComponent } from './render_function'; | ||
import { PieExpressionArgs } from './types'; | ||
|
||
describe('PieVisualization component', () => { | ||
let getFormatSpy: jest.Mock; | ||
let convertSpy: jest.Mock; | ||
|
||
beforeEach(() => { | ||
convertSpy = jest.fn(x => x); | ||
getFormatSpy = jest.fn(); | ||
getFormatSpy.mockReturnValue({ convert: convertSpy }); | ||
}); | ||
|
||
describe('legend options', () => { | ||
const data: LensMultiTable = { | ||
type: 'lens_multitable', | ||
tables: { | ||
first: { | ||
type: 'kibana_datatable', | ||
columns: [ | ||
{ id: 'a', name: 'a' }, | ||
{ id: 'b', name: 'b' }, | ||
{ id: 'c', name: 'c' }, | ||
], | ||
rows: [ | ||
{ a: 6, b: 2, c: 'I', d: 'Row 1' }, | ||
{ a: 1, b: 5, c: 'J', d: 'Row 2' }, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
const args: PieExpressionArgs = { | ||
shape: 'pie', | ||
groups: ['a', 'b'], | ||
metric: 'c', | ||
numberDisplay: 'hidden', | ||
categoryDisplay: 'default', | ||
legendDisplay: 'default', | ||
nestedLegend: false, | ||
percentDecimals: 3, | ||
hideLabels: false, | ||
}; | ||
|
||
function getDefaultArgs() { | ||
return { | ||
data, | ||
formatFactory: getFormatSpy, | ||
isDarkMode: false, | ||
chartTheme: {}, | ||
executeTriggerActions: jest.fn(), | ||
}; | ||
} | ||
|
||
test('it shows legend for 2 groups using default legendDisplay', () => { | ||
const component = shallow(<PieComponent args={args} {...getDefaultArgs()} />); | ||
expect(component.find(Settings).prop('showLegend')).toEqual(true); | ||
}); | ||
|
||
test('it hides legend for 1 group using default legendDisplay', () => { | ||
const component = shallow( | ||
<PieComponent args={{ ...args, groups: ['a'] }} {...getDefaultArgs()} /> | ||
); | ||
expect(component.find(Settings).prop('showLegend')).toEqual(false); | ||
}); | ||
|
||
test('it hides legend that would show otherwise in preview mode', () => { | ||
const component = shallow( | ||
<PieComponent args={{ ...args, hideLabels: true }} {...getDefaultArgs()} /> | ||
); | ||
expect(component.find(Settings).prop('showLegend')).toEqual(false); | ||
}); | ||
|
||
test('it hides legend with 2 groups for treemap', () => { | ||
const component = shallow( | ||
<PieComponent args={{ ...args, shape: 'treemap' }} {...getDefaultArgs()} /> | ||
); | ||
expect(component.find(Settings).prop('showLegend')).toEqual(false); | ||
}); | ||
|
||
test('it shows treemap legend only when forced on', () => { | ||
const component = shallow( | ||
<PieComponent | ||
args={{ ...args, legendDisplay: 'show', shape: 'treemap' }} | ||
{...getDefaultArgs()} | ||
/> | ||
); | ||
expect(component.find(Settings).prop('showLegend')).toEqual(true); | ||
}); | ||
|
||
test('it defaults to 1-level legend depth', () => { | ||
const component = shallow(<PieComponent args={args} {...getDefaultArgs()} />); | ||
expect(component.find(Settings).prop('legendMaxDepth')).toEqual(1); | ||
}); | ||
|
||
test('it shows nested legend only when forced on', () => { | ||
const component = shallow( | ||
<PieComponent args={{ ...args, nestedLegend: true }} {...getDefaultArgs()} /> | ||
); | ||
expect(component.find(Settings).prop('legendMaxDepth')).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
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
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
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
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