-
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.
[Metric] convert mocha tests to jest (#54054)
* Add fixtures/* alias to tsconfig and jest config * Convert metric tests to jest * Convert remaining js files to ts
- Loading branch information
1 parent
cc8ed75
commit 675c998
Showing
31 changed files
with
443 additions
and
291 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
src/legacy/core_plugins/vis_type_metric/public/__snapshots__/metric_vis_fn.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
95 changes: 0 additions & 95 deletions
95
src/legacy/core_plugins/vis_type_metric/public/__tests__/metric_vis.js
This file was deleted.
Oops, something went wrong.
71 changes: 0 additions & 71 deletions
71
src/legacy/core_plugins/vis_type_metric/public/__tests__/metric_vis_controller.js
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
...lugins/vis_type_metric/public/components/__snapshots__/metric_vis_component.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
src/legacy/core_plugins/vis_type_metric/public/components/metric_vis_component.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,93 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import { MetricVisComponent } from './metric_vis_component'; | ||
import { Vis } from '../legacy_imports'; | ||
|
||
jest.mock('ui/new_platform'); | ||
|
||
type Props = MetricVisComponent['props']; | ||
|
||
const baseVisData = { | ||
columns: [{ id: 'col-0', name: 'Count' }], | ||
rows: [{ 'col-0': 4301021 }], | ||
} as any; | ||
|
||
describe('MetricVisComponent', function() { | ||
const vis: Vis = { | ||
params: { | ||
metric: { | ||
colorSchema: 'Green to Red', | ||
colorsRange: [{ from: 0, to: 1000 }], | ||
style: {}, | ||
labels: { | ||
show: true, | ||
}, | ||
}, | ||
dimensions: { | ||
metrics: [{ accessor: 0 }], | ||
bucket: null, | ||
}, | ||
}, | ||
} as any; | ||
|
||
const getComponent = (propOverrides: Partial<Props> = {} as Partial<Props>) => { | ||
const props: Props = { | ||
vis, | ||
visParams: vis.params, | ||
visData: baseVisData, | ||
renderComplete: jest.fn(), | ||
...propOverrides, | ||
}; | ||
|
||
return shallow(<MetricVisComponent {...props} />); | ||
}; | ||
|
||
it('should render component', () => { | ||
expect(getComponent().exists()).toBe(true); | ||
}); | ||
|
||
it('should render correct structure for single metric', function() { | ||
expect(getComponent()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render correct structure for multi-value metrics', function() { | ||
const component = getComponent({ | ||
visData: { | ||
columns: [ | ||
{ id: 'col-0', name: '1st percentile of bytes' }, | ||
{ id: 'col-1', name: '99th percentile of bytes' }, | ||
], | ||
rows: [{ 'col-0': 182, 'col-1': 445842.4634666484 }], | ||
}, | ||
visParams: { | ||
...vis.params, | ||
dimensions: { | ||
...vis.params.dimensions, | ||
metrics: [{ accessor: 0 }, { accessor: 1 }], | ||
}, | ||
}, | ||
} as any); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.