Skip to content

Commit

Permalink
[Legacy Metric] should call renderComplete once for multi-value met…
Browse files Browse the repository at this point in the history
…rics (#142842)

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
alexwizp and kibanamachine authored Oct 10, 2022
1 parent 6ec4061 commit a122316
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import React from 'react';
import { shallow } from 'enzyme';
import { shallow, mount } from 'enzyme';
import { Datatable } from '@kbn/expressions-plugin/common';
import MetricVisComponent, { MetricVisComponentProps } from './metric_component';
import { LabelPosition } from '../../common/constants';
Expand Down Expand Up @@ -76,15 +76,15 @@ describe('MetricVisComponent', function () {
...propOverrides,
};

return shallow(<MetricVisComponent {...props} />);
return <MetricVisComponent {...props} />;
};

it('should render component', () => {
expect(getComponent().exists()).toBe(true);
expect(shallow(getComponent()).exists()).toBe(true);
});

it('should render correct structure for single metric', function () {
expect(getComponent()).toMatchSnapshot();
expect(shallow(getComponent())).toMatchSnapshot();
});

it('should render correct structure for multi-value metrics', function () {
Expand All @@ -110,6 +110,36 @@ describe('MetricVisComponent', function () {
},
});

expect(component).toMatchSnapshot();
expect(shallow(component)).toMatchSnapshot();
});

it('should call renderComplete once for multi-value metrics', function () {
const renderComplete = jest.fn();
const component = getComponent({
renderComplete,
filterable: [true, false],
visData: {
type: 'datatable',
columns: [
{ id: 'col-0', name: '1st percentile of bytes', meta: { type: 'number' } },
{ id: 'col-1', name: '99th percentile of bytes', meta: { type: 'number' } },
],
rows: [{ 'col-0': 182, 'col-1': 445842.4634666484 }],
},
visParams: {
...visParams,
dimensions: {
...visParams.dimensions,
metrics: [
{ accessor: 0, type: 'vis_dimension', format: { id: 'number', params: {} } },
{ accessor: 1, type: 'vis_dimension', format: { id: 'number', params: {} } },
],
},
},
});

mount(component);

expect(renderComplete).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class MetricVisComponent extends Component<MetricVisComponentProps> {
return this.props.visParams.metric.autoScale && this.props.visParams.metric.colorFullBackground;
};

private renderMetric = (metric: MetricOptions, index: number) => {
private renderMetric = (metric: MetricOptions, index: number, arrayRef: MetricOptions[]) => {
const hasBuckets = this.props.visParams.dimensions.bucket !== undefined;
const MetricComponent = this.props.visParams.metric.autoScale
? AutoScaleMetricVisValue
Expand Down Expand Up @@ -157,7 +157,7 @@ class MetricVisComponent extends Component<MetricVisComponentProps> {
autoScale={this.props.visParams.metric.autoScale}
colorFullBackground={this.props.visParams.metric.colorFullBackground}
labelConfig={this.props.visParams.metric.labels}
renderComplete={this.props.renderComplete}
renderComplete={arrayRef.length - 1 === index ? this.props.renderComplete : undefined}
/>
);
};
Expand Down

0 comments on commit a122316

Please sign in to comment.