Skip to content

Commit

Permalink
update some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed May 6, 2022
1 parent 8c28bbc commit c4f118d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { findTestSubject } from '@elastic/eui/lib/test';
import { act } from 'react-dom/test-utils';
import { HeatmapRenderProps, HeatmapArguments } from '../../common';
import HeatmapComponent from './heatmap_component';
import { LegendSize, LegendSizeToPixels } from '@kbn/visualizations-plugin/common';

jest.mock('@elastic/charts', () => {
const original = jest.requireActual('@elastic/charts');
Expand Down Expand Up @@ -47,6 +48,7 @@ const args: HeatmapArguments = {
isVisible: true,
position: 'top',
type: 'heatmap_legend',
legendSize: LegendSize.SMALL,
},
gridConfig: {
isCellLabelVisible: true,
Expand Down Expand Up @@ -119,6 +121,33 @@ describe('HeatmapComponent', function () {
expect(component.find(Settings).prop('legendPosition')).toEqual('top');
});

it('sets correct legend sizes', () => {
const component = shallowWithIntl(<HeatmapComponent {...wrapperProps} />);
expect(component.find(Settings).prop('legendSize')).toEqual(80);

component.setProps({
args: {
...args,
legend: {
...args.legend,
legendSize: LegendSize.AUTO,
},
},
});
expect(component.find(Settings).prop('legendSize')).toBeUndefined();

component.setProps({
args: {
...args,
legend: {
...args.legend,
legendSize: undefined,
},
},
});
expect(component.find(Settings).prop('legendSize')).toEqual(130);
});

it('renders the legend toggle component if uiState is set', async () => {
const component = mountWithIntl(<HeatmapComponent {...wrapperProps} />);
await actWithTimeout(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import React from 'react';
import { Settings, TooltipType, SeriesIdentifier } from '@elastic/charts';
import { Settings, TooltipType, SeriesIdentifier, Partition } from '@elastic/charts';
import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks';
Expand All @@ -25,6 +25,7 @@ import {
createMockWaffleParams,
} from '../mocks';
import { ChartTypes } from '../../common/types';
import { LegendSize } from '@kbn/visualizations-plugin/common';

jest.mock('@elastic/charts', () => {
const original = jest.requireActual('@elastic/charts');
Expand Down Expand Up @@ -177,6 +178,35 @@ describe('PartitionVisComponent', function () {
expect(component.find(Settings).prop('legendMaxDepth')).toBeUndefined();
});

it('sets correct legend sizes', () => {
const component = shallow(
<PartitionVisComponent
{...wrapperProps}
visParams={{
...visParams,
legendSize: LegendSize.SMALL,
}}
/>
);
expect(component.find(Settings).prop('legendSize')).toEqual(80);

component.setProps({
visParams: {
...visParams,
legendSize: LegendSize.AUTO,
},
});
expect(component.find(Settings).prop('legendSize')).toBeUndefined();

component.setProps({
visParams: {
...visParams,
legendSize: undefined,
},
});
expect(component.find(Settings).prop('legendSize')).toEqual(130);
});

it('defaults on displaying the tooltip', () => {
const component = shallow(<PartitionVisComponent {...wrapperProps} />);
expect(component.find(Settings).prop('tooltip')).toStrictEqual({ type: TooltipType.Follow });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
} from '../../common/types';
import { DataLayers } from './data_layers';
import { Annotations } from './annotations';
import { LegendSize } from '@kbn/visualizations-plugin/common';

const onClickValue = jest.fn();
const onSelectRange = jest.fn();
Expand Down Expand Up @@ -2377,6 +2378,37 @@ describe('XYChart component', () => {
expect(component.find(Settings).prop('legendPosition')).toEqual('top');
});

it('computes correct legend sizes', () => {
const { args } = sampleArgs();

const component = shallow(
<XYChart
{...defaultProps}
args={{
...args,
legend: { ...args.legend, legendSize: LegendSize.SMALL },
}}
/>
);
expect(component.find(Settings).prop('legendSize')).toEqual(80);

component.setProps({
args: {
...args,
legend: { ...args.legend, legendSize: LegendSize.AUTO },
},
});
expect(component.find(Settings).prop('legendSize')).toBeUndefined();

component.setProps({
args: {
...args,
legend: { ...args.legend, legendSize: undefined },
},
});
expect(component.find(Settings).prop('legendSize')).toEqual(130);
});

test('it should apply the fitting function to all non-bar series', () => {
const data: Datatable = createSampleDatatableWithRows([
{ a: 1, b: 2, c: 'I', d: 'Foo' },
Expand Down

0 comments on commit c4f118d

Please sign in to comment.