Skip to content

Commit

Permalink
[Metric] convert mocha tests to jest (elastic#54054)
Browse files Browse the repository at this point in the history
* Add fixtures/* alias to tsconfig and jest config
* Convert metric tests to jest
* Convert remaining js files to ts
  • Loading branch information
nickofthyme committed Jan 17, 2020
1 parent cc8ed75 commit 675c998
Show file tree
Hide file tree
Showing 31 changed files with 443 additions and 291 deletions.
1 change: 1 addition & 0 deletions src/dev/jest/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default {
'^ui/(.*)': '<rootDir>/src/legacy/ui/public/$1',
'^uiExports/(.*)': '<rootDir>/src/dev/jest/mocks/file_mock.js',
'^test_utils/(.*)': '<rootDir>/src/test_utils/public/$1',
'^fixtures/(.*)': '<rootDir>/src/fixtures/$1',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/src/dev/jest/mocks/file_mock.js',
'\\.(css|less|scss)$': '<rootDir>/src/dev/jest/mocks/style_mock.js',
Expand Down

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

This file was deleted.

This file was deleted.

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
@@ -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();
});
});
Loading

0 comments on commit 675c998

Please sign in to comment.