Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Uptime] added test for chart wrapper (#50399) #51808

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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,83 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { EuiSpacer } from '@elastic/eui';
import { mount } from 'enzyme';
import { nextTick } from 'test_utils/enzyme_helpers';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import { ChartWrapper } from '../chart_wrapper';
import { SnapshotHeading } from '../../snapshot_heading';
import { DonutChart } from '../donut_chart';
const SNAPSHOT_CHART_WIDTH = 144;
const SNAPSHOT_CHART_HEIGHT = 144;
describe('ChartWrapper component', () => {
it('renders the component with loading false', () => {
const component = shallowWithIntl(
<ChartWrapper loading={false}>
<SnapshotHeading down={8} total={12} />
<EuiSpacer size="xs" />
<DonutChart up={4} down={8} height={SNAPSHOT_CHART_HEIGHT} width={SNAPSHOT_CHART_WIDTH} />
</ChartWrapper>
);
expect(component).toMatchSnapshot();
});

it('renders the component with loading true', () => {
const component = shallowWithIntl(
<ChartWrapper loading={true}>
<SnapshotHeading down={8} total={12} />
<EuiSpacer size="xs" />
<DonutChart up={4} down={8} height={SNAPSHOT_CHART_HEIGHT} width={SNAPSHOT_CHART_WIDTH} />
</ChartWrapper>
);
expect(component).toMatchSnapshot();
});

it('mounts the component with loading true or false', async () => {
const component = mount(
<ChartWrapper loading={true}>
<SnapshotHeading down={8} total={12} />
<EuiSpacer size="xs" />
<DonutChart up={4} down={8} height={SNAPSHOT_CHART_HEIGHT} width={SNAPSHOT_CHART_WIDTH} />
</ChartWrapper>
);

let loadingChart = component.find(`.euiLoadingChart`);
expect(loadingChart.length).toBe(1);

component.setProps({
loading: false,
});
await nextTick();
component.update();

loadingChart = component.find(`.euiLoadingChart`);
expect(loadingChart.length).toBe(0);
});

it('mounts the component with chart when loading true or false', async () => {
const component = mount(
<ChartWrapper loading={true}>
<SnapshotHeading down={8} total={12} />
<EuiSpacer size="xs" />
<DonutChart up={4} down={8} height={SNAPSHOT_CHART_HEIGHT} width={SNAPSHOT_CHART_WIDTH} />
</ChartWrapper>
);

let donutChart = component.find(DonutChart);
expect(donutChart.length).toBe(1);

component.setProps({
loading: false,
});
await nextTick();
component.update();

donutChart = component.find(DonutChart);
expect(donutChart.length).toBe(1);
});
});