From 551c67be488a898e961795d846d16b9dd8885e2e Mon Sep 17 00:00:00 2001 From: Shahzad Date: Wed, 27 Nov 2019 14:41:33 +0100 Subject: [PATCH] [Uptime] added test for chart wrapper (#50399) (#51808) * added test for chart wrapper * update unit test * updated test selector --- .../__snapshots__/chart_wrapper.test.tsx.snap | 280 ++++++++++++++++++ .../charts/__tests__/chart_wrapper.test.tsx | 83 ++++++ 2 files changed, 363 insertions(+) create mode 100644 x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/__snapshots__/chart_wrapper.test.tsx.snap create mode 100644 x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/chart_wrapper.test.tsx diff --git a/x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/__snapshots__/chart_wrapper.test.tsx.snap b/x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/__snapshots__/chart_wrapper.test.tsx.snap new file mode 100644 index 00000000000000..3f3e6b0b929e12 --- /dev/null +++ b/x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/__snapshots__/chart_wrapper.test.tsx.snap @@ -0,0 +1,280 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ChartWrapper component renders the component with loading false 1`] = ` + +
+ + + +
+
+`; + +exports[`ChartWrapper component renders the component with loading true 1`] = ` + +
+ + + +
+ + + + + +
+`; diff --git a/x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/chart_wrapper.test.tsx b/x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/chart_wrapper.test.tsx new file mode 100644 index 00000000000000..43e6b80d5c840c --- /dev/null +++ b/x-pack/legacy/plugins/uptime/public/components/functional/charts/__tests__/chart_wrapper.test.tsx @@ -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( + + + + + + ); + expect(component).toMatchSnapshot(); + }); + + it('renders the component with loading true', () => { + const component = shallowWithIntl( + + + + + + ); + expect(component).toMatchSnapshot(); + }); + + it('mounts the component with loading true or false', async () => { + const component = mount( + + + + + + ); + + 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( + + + + + + ); + + 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); + }); +});