Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Dec 6, 2021
1 parent 7ffafe9 commit bf8fba9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import {
byDataColorPaletteMap,
extractUniqTermsMap,
checkTableForContainsSmallValues,
shouldShowValuesInLegend,
} from './render_helpers';
import { chartPluginMock } from '../../../../../src/plugins/charts/public/mocks';
import type { PieLayerState } from '../../common/expressions';

describe('render helpers', () => {
describe('#getSliceValue', () => {
Expand Down Expand Up @@ -374,4 +376,28 @@ describe('render helpers', () => {
expect(checkTableForContainsSmallValues(datatable, columnId, 1)).toBeFalsy();
});
});

describe('#shouldShowValuesInLegend', () => {
it('should firstly read the state value', () => {
expect(
shouldShowValuesInLegend({ showValuesInLegend: true } as PieLayerState, 'waffle')
).toBeTruthy();

expect(
shouldShowValuesInLegend({ showValuesInLegend: false } as PieLayerState, 'waffle')
).toBeFalsy();
});

it('should read value from meta in case of value in state is undefined', () => {
expect(
shouldShowValuesInLegend({ showValuesInLegend: undefined } as PieLayerState, 'waffle')
).toBeTruthy();

expect(shouldShowValuesInLegend({} as PieLayerState, 'waffle')).toBeTruthy();

expect(
shouldShowValuesInLegend({ showValuesInLegend: undefined } as PieLayerState, 'pie')
).toBeFalsy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const isTreemapOrMosaicShape = (shape: PieChartTypes | string) =>
['treemap', 'mosaic'].includes(shape);

export const shouldShowValuesInLegend = (layer: PieLayerState, shape: PieChartTypes) =>
'showValuesInLegend' in layer
? layer.showValuesInLegend!
layer.showValuesInLegend !== undefined
? layer.showValuesInLegend
: Boolean(PartitionChartsMeta[shape]?.legend?.showValues);

export const extractUniqTermsMap = (dataTable: Datatable, columnId: string) =>
Expand Down

0 comments on commit bf8fba9

Please sign in to comment.