diff --git a/change/@fluentui-react-charting-556f2e0e-35f0-44cd-9bd6-aa9b24aaa57e.json b/change/@fluentui-react-charting-556f2e0e-35f0-44cd-9bd6-aa9b24aaa57e.json new file mode 100644 index 0000000000000..f6d32fb738f20 --- /dev/null +++ b/change/@fluentui-react-charting-556f2e0e-35f0-44cd-9bd6-aa9b24aaa57e.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Fixing re-render issue for all charts when empty", + "packageName": "@fluentui/react-charting", + "email": "srmukher@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-charting/src/components/AreaChart/AreaChart.base.tsx b/packages/react-charting/src/components/AreaChart/AreaChart.base.tsx index 02babbaee3754..5a03d7c585b7c 100644 --- a/packages/react-charting/src/components/AreaChart/AreaChart.base.tsx +++ b/packages/react-charting/src/components/AreaChart/AreaChart.base.tsx @@ -70,7 +70,6 @@ export interface IAreaChartState extends IBasestate { nearestCircleToHighlight: number | string | Date | null; xAxisCalloutAccessibilityData?: IAccessibilityProps; isShowCalloutPending: boolean; - emptyChart?: boolean; /** focused point */ activePoint: string; } @@ -107,6 +106,7 @@ export class AreaChartBase extends React.Component 0 && - this.props.data.lineChartData.filter(item => item.data.length === 0).length === 0 - ) - // if all the data sets have no data - // filtering all items which have no data and checking if the length of the filtered array is 0 - // which means chart is not empty - ), activePoint: '', }; warnDeprecations(COMPONENT_NAME, props, { @@ -146,6 +135,7 @@ export class AreaChartBase extends React.Component 0 && + this.props.data.lineChartData.filter(item => item.data.length === 0).length === 0 + ) + // if all the data sets have no data + // filtering all items which have no data and checking if the length of the filtered array is 0 + // which means chart is not empty + ); + } } diff --git a/packages/react-charting/src/components/AreaChart/AreaChart.test.tsx b/packages/react-charting/src/components/AreaChart/AreaChart.test.tsx index fb0894f66dd8e..48f2256eb6bd5 100644 --- a/packages/react-charting/src/components/AreaChart/AreaChart.test.tsx +++ b/packages/react-charting/src/components/AreaChart/AreaChart.test.tsx @@ -46,7 +46,7 @@ const points: ILineChartPoints[] = [ color: 'red', }, ]; -const chartPoints = { +export const chartPoints = { chartTitle: 'AreaChart', lineChartData: points, }; @@ -70,7 +70,7 @@ const emptyPoint = [ color: 'red', }, ]; -const emptyChartPoints = { +export const emptyChartPoints = { chartTitle: 'EmptyAreaChart', lineChartData: emptyPoint, }; diff --git a/packages/react-charting/src/components/AreaChart/AreaChartRTL.test.tsx b/packages/react-charting/src/components/AreaChart/AreaChartRTL.test.tsx new file mode 100644 index 0000000000000..69b422bd6cfa8 --- /dev/null +++ b/packages/react-charting/src/components/AreaChart/AreaChartRTL.test.tsx @@ -0,0 +1,22 @@ +import * as React from 'react'; +import { queryAllByAttribute, render, waitFor } from '@testing-library/react'; +import { chartPoints, emptyChartPoints } from './AreaChart.test'; +import { AreaChart } from './index'; + +describe('Area chart rendering', () => { + test('Should re-render the Area chart with data', async () => { + // Arrange + const { container, rerender } = render(); + const getById = queryAllByAttribute.bind(null, 'id'); + // Assert + expect(container).toMatchSnapshot(); + expect(getById(container, /_AreaChart_empty/i)).toHaveLength(1); + // Act + rerender(); + await waitFor(() => { + // Assert + expect(container).toMatchSnapshot(); + expect(getById(container, /_AreaChart_empty/i)).toHaveLength(0); + }); + }); +}); diff --git a/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChart.test.tsx.snap b/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChart.test.tsx.snap index adc1d00ad35b3..dd51632647b90 100644 --- a/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChart.test.tsx.snap +++ b/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChart.test.tsx.snap @@ -16,7 +16,7 @@ exports[`AreaChart - mouse events Should render callout correctly on mouseover 1 overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -29,7 +29,7 @@ exports[`AreaChart - mouse events Should render callout correctly on mouseover 1 { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -70,7 +70,7 @@ exports[`AreaChart - mouse events Should render callout correctly on mouseover 1 & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -232,7 +232,7 @@ exports[`AreaChart - mouse events Should render callout correctly on mouseover 1 &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -558,7 +558,7 @@ exports[`AreaChart - mouse events Should render customized callout on mouseover overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -571,7 +571,7 @@ exports[`AreaChart - mouse events Should render customized callout on mouseover { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -612,7 +612,7 @@ exports[`AreaChart - mouse events Should render customized callout on mouseover & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -774,7 +774,7 @@ exports[`AreaChart - mouse events Should render customized callout on mouseover &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -997,7 +997,7 @@ exports[`AreaChart - mouse events Should render customized callout per stack on overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -1010,7 +1010,7 @@ exports[`AreaChart - mouse events Should render customized callout per stack on { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1051,7 +1051,7 @@ exports[`AreaChart - mouse events Should render customized callout per stack on & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -1213,7 +1213,7 @@ exports[`AreaChart - mouse events Should render customized callout per stack on &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1436,7 +1436,7 @@ exports[`AreaChart snapShot testing Should not render circles when optimizeLarge overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -1449,7 +1449,7 @@ exports[`AreaChart snapShot testing Should not render circles when optimizeLarge { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1490,7 +1490,7 @@ exports[`AreaChart snapShot testing Should not render circles when optimizeLarge & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -1618,7 +1618,7 @@ exports[`AreaChart snapShot testing Should not render circles when optimizeLarge &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1755,7 +1755,7 @@ exports[`AreaChart snapShot testing Should render with default colors when line overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -1768,7 +1768,7 @@ exports[`AreaChart snapShot testing Should render with default colors when line { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1809,7 +1809,7 @@ exports[`AreaChart snapShot testing Should render with default colors when line & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -1977,7 +1977,7 @@ exports[`AreaChart snapShot testing Should render with default colors when line &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2114,7 +2114,7 @@ exports[`AreaChart snapShot testing renders Areachart correctly 1`] = ` overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -2127,7 +2127,7 @@ exports[`AreaChart snapShot testing renders Areachart correctly 1`] = ` { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2168,7 +2168,7 @@ exports[`AreaChart snapShot testing renders Areachart correctly 1`] = ` & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -2336,7 +2336,7 @@ exports[`AreaChart snapShot testing renders Areachart correctly 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2473,7 +2473,7 @@ exports[`AreaChart snapShot testing renders Areachart with single point correctl overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -2486,7 +2486,7 @@ exports[`AreaChart snapShot testing renders Areachart with single point correctl { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2527,7 +2527,7 @@ exports[`AreaChart snapShot testing renders Areachart with single point correctl & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -2681,7 +2681,7 @@ exports[`AreaChart snapShot testing renders Areachart with single point correctl &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2818,7 +2818,7 @@ exports[`AreaChart snapShot testing renders enabledLegendsWrapLines correctly 1` overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -2831,7 +2831,7 @@ exports[`AreaChart snapShot testing renders enabledLegendsWrapLines correctly 1` { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2872,7 +2872,7 @@ exports[`AreaChart snapShot testing renders enabledLegendsWrapLines correctly 1` & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -3023,7 +3023,7 @@ exports[`AreaChart snapShot testing renders enabledLegendsWrapLines correctly 1` &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3157,7 +3157,7 @@ exports[`AreaChart snapShot testing renders hideLegend hhh correctly 1`] = ` overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -3170,7 +3170,7 @@ exports[`AreaChart snapShot testing renders hideLegend hhh correctly 1`] = ` { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3211,7 +3211,7 @@ exports[`AreaChart snapShot testing renders hideLegend hhh correctly 1`] = ` & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 315)" /> @@ -3355,7 +3355,7 @@ exports[`AreaChart snapShot testing renders hideTooltip correctly 1`] = ` overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -3368,7 +3368,7 @@ exports[`AreaChart snapShot testing renders hideTooltip correctly 1`] = ` { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3409,7 +3409,7 @@ exports[`AreaChart snapShot testing renders hideTooltip correctly 1`] = ` & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -3577,7 +3577,7 @@ exports[`AreaChart snapShot testing renders hideTooltip correctly 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3714,7 +3714,7 @@ exports[`AreaChart snapShot testing renders showXAxisLablesTooltip correctly 1`] overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -3727,7 +3727,7 @@ exports[`AreaChart snapShot testing renders showXAxisLablesTooltip correctly 1`] { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3768,7 +3768,7 @@ exports[`AreaChart snapShot testing renders showXAxisLablesTooltip correctly 1`] & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -3936,7 +3936,7 @@ exports[`AreaChart snapShot testing renders showXAxisLablesTooltip correctly 1`] &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -4073,7 +4073,7 @@ exports[`AreaChart snapShot testing renders wrapXAxisLables correctly 1`] = ` overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -4086,7 +4086,7 @@ exports[`AreaChart snapShot testing renders wrapXAxisLables correctly 1`] = ` { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -4127,7 +4127,7 @@ exports[`AreaChart snapShot testing renders wrapXAxisLables correctly 1`] = ` & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -4295,7 +4295,7 @@ exports[`AreaChart snapShot testing renders wrapXAxisLables correctly 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -4432,7 +4432,7 @@ exports[`AreaChart snapShot testing renders yAxisTickFormat correctly 1`] = ` overflow: hidden; width: 100%; } - id="chart_5" + id="chart_6" onMouseLeave={[Function]} role="presentation" > @@ -4445,7 +4445,7 @@ exports[`AreaChart snapShot testing renders yAxisTickFormat correctly 1`] = ` { overflow: auto; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone7" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -4486,7 +4486,7 @@ exports[`AreaChart snapShot testing renders yAxisTickFormat correctly 1`] = ` & path { display: none; } - id="xAxisGElementchart_5" + id="xAxisGElementchart_6" transform="translate(0, 275)" /> @@ -4654,7 +4654,7 @@ exports[`AreaChart snapShot testing renders yAxisTickFormat correctly 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone7" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} diff --git a/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChartRTL.test.tsx.snap b/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChartRTL.test.tsx.snap new file mode 100644 index 0000000000000..8df081a9230a2 --- /dev/null +++ b/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChartRTL.test.tsx.snap @@ -0,0 +1,5103 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Area chart rendering Should re-render the Area chart with data 1`] = ` +
+ +`; + +exports[`Area chart rendering Should re-render the Area chart with data 2`] = ` +
+ +
+`; + +exports[`AreaChart - mouse events Should render callout correctly on mouseover 1`] = ` + +`; + +exports[`AreaChart - mouse events Should render customized callout on mouseover 1`] = ` + +`; + +exports[`AreaChart - mouse events Should render customized callout per stack on mouseover 1`] = ` + +`; + +exports[`AreaChart snapShot testing Should not render circles when optimizeLargeData is true 1`] = ` + +`; + +exports[`AreaChart snapShot testing Should render with default colors when line color is not provided 1`] = ` + +`; + +exports[`AreaChart snapShot testing renders Areachart correctly 1`] = ` + +`; + +exports[`AreaChart snapShot testing renders Areachart with single point correctly 1`] = ` + +`; + +exports[`AreaChart snapShot testing renders enabledLegendsWrapLines correctly 1`] = ` + +`; + +exports[`AreaChart snapShot testing renders hideLegend hhh correctly 1`] = ` + +`; + +exports[`AreaChart snapShot testing renders hideTooltip correctly 1`] = ` + +`; + +exports[`AreaChart snapShot testing renders showXAxisLablesTooltip correctly 1`] = ` + +`; + +exports[`AreaChart snapShot testing renders wrapXAxisLables correctly 1`] = ` + +`; + +exports[`AreaChart snapShot testing renders yAxisTickFormat correctly 1`] = ` + +`; diff --git a/packages/react-charting/src/components/DonutChart/DonutChart.base.tsx b/packages/react-charting/src/components/DonutChart/DonutChart.base.tsx index b4d07ec0fddd4..71280d92ae296 100644 --- a/packages/react-charting/src/components/DonutChart/DonutChart.base.tsx +++ b/packages/react-charting/src/components/DonutChart/DonutChart.base.tsx @@ -26,7 +26,6 @@ export interface IDonutChartState { selectedLegend: string; dataPointCalloutProps?: IChartDataPoint; callOutAccessibilityData?: IAccessibilityProps; - emptyChart?: boolean; } export class DonutChartBase extends React.Component { @@ -42,6 +41,7 @@ export class DonutChartBase extends React.Component, @@ -74,13 +74,13 @@ export class DonutChartBase extends React.Component d.data! > 0).length > 0 - ); - if (this.state.emptyChart !== isChartEmpty) { - this.setState({ emptyChart: isChartEmpty }); - } } public render(): JSX.Element { @@ -118,7 +110,7 @@ export class DonutChartBase extends React.Component d.data! > 0); const valueInsideDonut = this._valueInsideDonut(this.props.valueInsideDonut!, chartData!); - return !this.state.emptyChart ? ( + return !this._isChartEmpty() ? (
(this._rootElem = rootElem)} @@ -184,7 +176,7 @@ export class DonutChartBase extends React.Component ) : (
d.data! > 0).length > 0 + ); + } } diff --git a/packages/react-charting/src/components/DonutChart/DonutChart.test.tsx b/packages/react-charting/src/components/DonutChart/DonutChart.test.tsx index 5561d998e37eb..6a8cf183171a0 100644 --- a/packages/react-charting/src/components/DonutChart/DonutChart.test.tsx +++ b/packages/react-charting/src/components/DonutChart/DonutChart.test.tsx @@ -42,7 +42,7 @@ export const chartPoints: IChartProps = { chartData: points, }; -const emptyChartPoints: IChartProps = { +export const emptyChartPoints: IChartProps = { chartTitle: chartTitle, chartData: [], }; diff --git a/packages/react-charting/src/components/DonutChart/DonutChartRTL.test.tsx b/packages/react-charting/src/components/DonutChart/DonutChartRTL.test.tsx index d0e65307484d4..78c00c84b2c38 100644 --- a/packages/react-charting/src/components/DonutChart/DonutChartRTL.test.tsx +++ b/packages/react-charting/src/components/DonutChart/DonutChartRTL.test.tsx @@ -1,204 +1,180 @@ -import { render, screen, queryAllByAttribute, fireEvent, act } from '@testing-library/react'; +import { render, screen, queryAllByAttribute, fireEvent } from '@testing-library/react'; import { chartPoints } from './DonutChart.test'; import { DonutChart } from './index'; import * as React from 'react'; import { DarkTheme } from '@fluentui/theme-samples'; import { ThemeProvider } from '@fluentui/react'; import * as utils from '../../utilities/utilities'; +import { resetIds } from '../../Utilities'; -test('Should hide callout on mouse leave', () => { - // Arrange - const { container } = render(); +describe('Donut chart interactions', () => { + beforeEach(() => { + resetIds(); + jest.spyOn(global.Math, 'random').mockReturnValue(0.1); + }); + afterEach(() => { + jest.spyOn(global.Math, 'random').mockRestore(); + }); + test('Should hide callout on mouse leave', () => { + // Arrange + const { container } = render( + , + ); - // Act - const getById = queryAllByAttribute.bind(null, 'id'); - fireEvent.mouseOver(getById(container, /Pie/i)[0]); - expect(getById(container, /callout/i)[0]).toBeDefined(); - fireEvent.mouseLeave(getById(container, /Pie/i)[0]); + // Act + const getById = queryAllByAttribute.bind(null, 'id'); + fireEvent.mouseOver(getById(container, /Pie/i)[0]); + expect(getById(container, /callout/i)[0]).toBeDefined(); + fireEvent.mouseLeave(getById(container, /Pie/i)[0]); - // Assert - expect(getById(container, /callout/i)[0]).toHaveStyle('opacity: 0'); - expect(container).toMatchSnapshot(); -}); + // Assert + expect(getById(container, /callout/i)[0]).toHaveStyle('opacity: 0'); + expect(container).toMatchSnapshot(); + }); -test('Should show callout on focus', () => { - // Arrange - const { container } = render(); + test('Should show callout on focus', () => { + // Arrange + const { container } = render( + , + ); - // Act - const getById = queryAllByAttribute.bind(null, 'id'); - fireEvent.focus(getById(container, /Pie/i)[0]); + // Act + const getById = queryAllByAttribute.bind(null, 'id'); + fireEvent.focus(getById(container, /Pie/i)[0]); - // Assert - expect(getById(container, /focusRing/i)).toBeDefined(); -}); + // Assert + expect(getById(container, /focusRing/i)).toBeDefined(); + }); -test('Should remove focus on blur', () => { - // Arrange - const { container } = render(); + test('Should remove focus on blur', () => { + // Arrange + const { container } = render( + , + ); - // Act - const getById = queryAllByAttribute.bind(null, 'id'); - fireEvent.blur(getById(container, /Pie/i)[0]); + // Act + const getById = queryAllByAttribute.bind(null, 'id'); + fireEvent.blur(getById(container, /Pie/i)[0]); - // Assert - const value = getById(container, /Pie/i)[0].getAttribute('id'); - expect(value).not.toContain('focusRing'); -}); + // Assert + const value = getById(container, /Pie/i)[0].getAttribute('id'); + expect(value).not.toContain('focusRing'); + }); -test('Should highlight the corresponding Pie on mouse over on legends', () => { - // Arrange - const { container } = render(); + test('Should highlight the corresponding Pie on mouse over on legends', () => { + // Arrange + const { container } = render(); - // Act - const legend = screen.queryByText('first'); - expect(legend).toBeDefined(); - fireEvent.mouseOver(legend!); + // Act + const legend = screen.queryByText('first'); + expect(legend).toBeDefined(); + fireEvent.mouseOver(legend!); - // Assert - const getById = queryAllByAttribute.bind(null, 'id'); - expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '0.1'); - expect(getById(container, /Pie.*?third/i)[0]).toHaveAttribute('opacity', '0.1'); -}); + // Assert + const getById = queryAllByAttribute.bind(null, 'id'); + expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '0.1'); + expect(getById(container, /Pie.*?third/i)[0]).toHaveAttribute('opacity', '0.1'); + }); -test('Should select legend on single mouse click on legends', () => { - // Arrange - const { container } = render(); - - // Act - const legend = screen.queryByText('first'); - expect(legend).toBeDefined(); - fireEvent.click(legend!); - - // Assert - const getById = queryAllByAttribute.bind(null, 'id'); - expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '0.1'); - const firstLegend = screen.queryByText('first')?.closest('button'); - expect(firstLegend).toHaveAttribute('aria-selected', 'true'); - expect(firstLegend).toHaveAttribute('tabIndex', '0'); -}); + test('Should select legend on single mouse click on legends', () => { + // Arrange + const { container } = render(); -test('Should deselect legend on double mouse click on legends', () => { - // Arrange - const { container } = render(); - - // Act - const legend = screen.queryByText('first'); - expect(legend).toBeDefined(); - - //single click on first legend - fireEvent.click(legend!); - const getById = queryAllByAttribute.bind(null, 'id'); - expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '0.1'); - const firstLegend = screen.queryByText('first')?.closest('button'); - expect(firstLegend).toHaveAttribute('aria-selected', 'true'); - expect(firstLegend).toHaveAttribute('tabIndex', '0'); - // double click on same first legend - fireEvent.click(legend!); - - // Assert - expect(firstLegend).toHaveAttribute('aria-selected', 'false'); -}); + // Act + const legend = screen.queryByText('first'); + expect(legend).toBeDefined(); + fireEvent.click(legend!); -test('Should show Pies with same opacity on mouse out of legends', () => { - // Arrange - const { container } = render(); - - // Act - const legend = screen.queryByText('first'); - expect(legend).toBeDefined(); - fireEvent.mouseOver(legend!); - const getById = queryAllByAttribute.bind(null, 'id'); - expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '0.1'); - fireEvent.mouseOut(legend!); - - // Assert - expect(getById(container, /Pie.*?first/i)[0]).toHaveAttribute('opacity', '1'); - expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '1'); -}); + // Assert + const getById = queryAllByAttribute.bind(null, 'id'); + expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '0.1'); + const firstLegend = screen.queryByText('first')?.closest('button'); + expect(firstLegend).toHaveAttribute('aria-selected', 'true'); + expect(firstLegend).toHaveAttribute('tabIndex', '0'); + }); -test('Should display correct callout data on mouse move', () => { - // Arrange - const { container } = render(); + test('Should deselect legend on double mouse click on legends', () => { + // Arrange + const { container } = render(); - // Act - const getById = queryAllByAttribute.bind(null, 'id'); - fireEvent.mouseOver(getById(container, /Pie/i)[0]); - expect(getById(container, /callout/i)[0]).toHaveTextContent('20,000'); - fireEvent.mouseLeave(getById(container, /Pie/i)[0]); - fireEvent.mouseOver(getById(container, /Pie/i)[1]); + // Act + const legend = screen.queryByText('first'); + expect(legend).toBeDefined(); + + //single click on first legend + fireEvent.click(legend!); + const getById = queryAllByAttribute.bind(null, 'id'); + expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '0.1'); + const firstLegend = screen.queryByText('first')?.closest('button'); + expect(firstLegend).toHaveAttribute('aria-selected', 'true'); + expect(firstLegend).toHaveAttribute('tabIndex', '0'); + // double click on same first legend + fireEvent.click(legend!); - // Assert - expect(getById(container, /callout/i)[0]).toHaveTextContent('39,000'); -}); + // Assert + expect(firstLegend).toHaveAttribute('aria-selected', 'false'); + }); -test('Should reflect theme change', () => { - // Arrange - const { container } = render( - - - , - ); + test('Should show Pies with same opacity on mouse out of legends', () => { + // Arrange + const { container } = render(); - // Assert - expect(container).toMatchSnapshot(); -}); + // Act + const legend = screen.queryByText('first'); + expect(legend).toBeDefined(); + fireEvent.mouseOver(legend!); + const getById = queryAllByAttribute.bind(null, 'id'); + expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '0.1'); + fireEvent.mouseOut(legend!); -describe('Screen resolution', () => { - const originalInnerWidth = global.innerWidth; - const originalInnerHeight = global.innerHeight; - afterEach(() => { - global.innerWidth = originalInnerWidth; - global.innerHeight = originalInnerHeight; - act(() => { - global.dispatchEvent(new Event('resize')); - }); + // Assert + expect(getById(container, /Pie.*?first/i)[0]).toHaveAttribute('opacity', '1'); + expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '1'); }); - test('Should remain unchanged on zoom in', () => { + test('Should display correct callout data on mouse move', () => { // Arrange - const { container } = render(); + const { container } = render( + , + ); // Act - global.innerWidth = window.innerWidth / 2; - global.innerHeight = window.innerHeight / 2; - act(() => { - global.dispatchEvent(new Event('resize')); - }); + const getById = queryAllByAttribute.bind(null, 'id'); + fireEvent.mouseOver(getById(container, /Pie/i)[0]); + expect(getById(container, /callout/i)[0]).toHaveTextContent('20,000'); + fireEvent.mouseLeave(getById(container, /Pie/i)[0]); + fireEvent.mouseOver(getById(container, /Pie/i)[1]); // Assert - expect(container).toMatchSnapshot(); + expect(getById(container, /callout/i)[0]).toHaveTextContent('39,000'); }); - test('Should remain unchanged on zoom out', () => { + test('Should change value inside donut with the legend value on mouseOver legend ', () => { + // Mock the implementation of wrapTextInsideDonut as it internally calls a Browser Function like + // getComputedTextLength() which will otherwise lead to a crash if mounted + jest.spyOn(utils, 'wrapTextInsideDonut').mockImplementation(() => '1000'); // Arrange - const { container } = render(); + const { container } = render( + , + ); + const getByClass = queryAllByAttribute.bind(null, 'class'); // Act - global.innerWidth = window.innerWidth * 2; - global.innerHeight = window.innerHeight * 2; - act(() => { - global.dispatchEvent(new Event('resize')); - }); + fireEvent.mouseOver(screen.getByText('first')); // Assert - expect(container).toMatchSnapshot(); + expect(getByClass(container, /insideDonutString.*?/)[0].textContent).toBe('20,000'); }); -}); -test('Should change value inside donut with the legend value on mouseOver legend ', () => { - // Mock the implementation of wrapTextInsideDonut as it internally calls a Browser Function like - // getComputedTextLength() which will otherwise lead to a crash if mounted - jest.spyOn(utils, 'wrapTextInsideDonut').mockImplementation(() => '1000'); - // Arrange - const { container } = render( - , - ); - const getByClass = queryAllByAttribute.bind(null, 'class'); - - // Act - fireEvent.mouseOver(screen.getByText('first')); - - // Assert - expect(getByClass(container, /insideDonutString.*?/)[0].textContent).toBe('20,000'); + test('Should reflect theme change', () => { + // Arrange + const { container } = render( + + + , + ); + + // Assert + expect(container).toMatchSnapshot(); + }); }); diff --git a/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChart.test.tsx.snap b/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChart.test.tsx.snap index 13bef1411e049..530573c78d09e 100644 --- a/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChart.test.tsx.snap +++ b/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChart.test.tsx.snap @@ -24,7 +24,7 @@ exports[`DonutChart - mouse events Should render callout correctly on mouseover &:focus { outline: none; } - data-focuszone-id="FocusZone2" + data-focuszone-id="FocusZone3" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -336,7 +336,7 @@ exports[`DonutChart - mouse events Should render callout correctly on mouseover &:focus { outline: none; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -660,7 +660,7 @@ exports[`DonutChart - mouse events Should render customized callout on mouseover &:focus { outline: none; } - data-focuszone-id="FocusZone2" + data-focuszone-id="FocusZone3" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -890,7 +890,7 @@ exports[`DonutChart - mouse events Should render customized callout on mouseover &:focus { outline: none; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1214,7 +1214,7 @@ exports[`DonutChart snapShot testing Should render arc labels 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone21" + data-focuszone-id="FocusZone27" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1252,7 +1252,7 @@ exports[`DonutChart snapShot testing Should render arc labels 1`] = ` } d="M0.6,-59.997A60,60,0,0,1,56.068,-21.363L0,0Z" data-is-focusable={true} - id="_Pie_20first20000" + id="_Pie_25first20000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -1294,7 +1294,7 @@ exports[`DonutChart snapShot testing Should render arc labels 1`] = ` } d="M56.484,-20.237A60,60,0,0,1,-24.404,54.813L0,0Z" data-is-focusable={true} - id="_Pie_20second39000" + id="_Pie_25second39000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -1336,7 +1336,7 @@ exports[`DonutChart snapShot testing Should render arc labels 1`] = ` } d="M-25.495,54.314A60,60,0,0,1,-0.6,-59.997L0,0Z" data-is-focusable={true} - id="_Pie_20third45000" + id="_Pie_25third45000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -1415,7 +1415,7 @@ exports[`DonutChart snapShot testing Should render arc labels 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone22" + data-focuszone-id="FocusZone28" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1736,7 +1736,7 @@ exports[`DonutChart snapShot testing Should render arc labels in percentage form &:focus { outline: none; } - data-focuszone-id="FocusZone25" + data-focuszone-id="FocusZone32" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1774,7 +1774,7 @@ exports[`DonutChart snapShot testing Should render arc labels in percentage form } d="M0.6,-59.997A60,60,0,0,1,56.068,-21.363L0,0Z" data-is-focusable={true} - id="_Pie_24first20000" + id="_Pie_30first20000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -1816,7 +1816,7 @@ exports[`DonutChart snapShot testing Should render arc labels in percentage form } d="M56.484,-20.237A60,60,0,0,1,-24.404,54.813L0,0Z" data-is-focusable={true} - id="_Pie_24second39000" + id="_Pie_30second39000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -1858,7 +1858,7 @@ exports[`DonutChart snapShot testing Should render arc labels in percentage form } d="M-25.495,54.314A60,60,0,0,1,-0.6,-59.997L0,0Z" data-is-focusable={true} - id="_Pie_24third45000" + id="_Pie_30third45000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -1937,7 +1937,7 @@ exports[`DonutChart snapShot testing Should render arc labels in percentage form &:focus { outline: none; } - data-focuszone-id="FocusZone26" + data-focuszone-id="FocusZone33" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2258,7 +2258,7 @@ exports[`DonutChart snapShot testing renders DonutChart correctly 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone2" + data-focuszone-id="FocusZone3" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2411,7 +2411,7 @@ exports[`DonutChart snapShot testing renders DonutChart correctly 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2732,7 +2732,7 @@ exports[`DonutChart snapShot testing renders enabledLegendsWrapLines correctly 1 &:focus { outline: none; } - data-focuszone-id="FocusZone13" + data-focuszone-id="FocusZone17" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2770,7 +2770,7 @@ exports[`DonutChart snapShot testing renders enabledLegendsWrapLines correctly 1 } d="M1,-99.995A100,100,0,0,1,93.447,-35.604L0,0Z" data-is-focusable={true} - id="_Pie_12first20000" + id="_Pie_15first20000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -2796,7 +2796,7 @@ exports[`DonutChart snapShot testing renders enabledLegendsWrapLines correctly 1 } d="M94.14,-33.728A100,100,0,0,1,-40.673,91.355L0,0Z" data-is-focusable={true} - id="_Pie_12second39000" + id="_Pie_15second39000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -2822,7 +2822,7 @@ exports[`DonutChart snapShot testing renders enabledLegendsWrapLines correctly 1 } d="M-42.492,90.523A100,100,0,0,1,-1,-99.995L0,0Z" data-is-focusable={true} - id="_Pie_12third45000" + id="_Pie_15third45000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -2885,7 +2885,7 @@ exports[`DonutChart snapShot testing renders enabledLegendsWrapLines correctly 1 &:focus { outline: none; } - data-focuszone-id="FocusZone14" + data-focuszone-id="FocusZone18" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3206,7 +3206,7 @@ exports[`DonutChart snapShot testing renders hideLegend correctly 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone6" + data-focuszone-id="FocusZone8" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3244,7 +3244,7 @@ exports[`DonutChart snapShot testing renders hideLegend correctly 1`] = ` } d="M1,-99.995A100,100,0,0,1,93.447,-35.604L0,0Z" data-is-focusable={true} - id="_Pie_5first20000" + id="_Pie_6first20000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -3270,7 +3270,7 @@ exports[`DonutChart snapShot testing renders hideLegend correctly 1`] = ` } d="M94.14,-33.728A100,100,0,0,1,-40.673,91.355L0,0Z" data-is-focusable={true} - id="_Pie_5second39000" + id="_Pie_6second39000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -3296,7 +3296,7 @@ exports[`DonutChart snapShot testing renders hideLegend correctly 1`] = ` } d="M-42.492,90.523A100,100,0,0,1,-1,-99.995L0,0Z" data-is-focusable={true} - id="_Pie_5third45000" + id="_Pie_6third45000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -3340,7 +3340,7 @@ exports[`DonutChart snapShot testing renders hideTooltip correctly 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone9" + data-focuszone-id="FocusZone12" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3378,7 +3378,7 @@ exports[`DonutChart snapShot testing renders hideTooltip correctly 1`] = ` } d="M1,-99.995A100,100,0,0,1,93.447,-35.604L0,0Z" data-is-focusable={true} - id="_Pie_8first20000" + id="_Pie_10first20000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -3404,7 +3404,7 @@ exports[`DonutChart snapShot testing renders hideTooltip correctly 1`] = ` } d="M94.14,-33.728A100,100,0,0,1,-40.673,91.355L0,0Z" data-is-focusable={true} - id="_Pie_8second39000" + id="_Pie_10second39000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -3430,7 +3430,7 @@ exports[`DonutChart snapShot testing renders hideTooltip correctly 1`] = ` } d="M-42.492,90.523A100,100,0,0,1,-1,-99.995L0,0Z" data-is-focusable={true} - id="_Pie_8third45000" + id="_Pie_10third45000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -3493,7 +3493,7 @@ exports[`DonutChart snapShot testing renders hideTooltip correctly 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone10" + data-focuszone-id="FocusZone13" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3814,7 +3814,7 @@ exports[`DonutChart snapShot testing renders value inside onf the pie 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone17" + data-focuszone-id="FocusZone22" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3852,7 +3852,7 @@ exports[`DonutChart snapShot testing renders value inside onf the pie 1`] = ` } d="M1,-99.995A100,100,0,0,1,93.447,-35.604L0,0Z" data-is-focusable={true} - id="_Pie_16first20000" + id="_Pie_20first20000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -3878,7 +3878,7 @@ exports[`DonutChart snapShot testing renders value inside onf the pie 1`] = ` } d="M94.14,-33.728A100,100,0,0,1,-40.673,91.355L0,0Z" data-is-focusable={true} - id="_Pie_16second39000" + id="_Pie_20second39000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -3904,7 +3904,7 @@ exports[`DonutChart snapShot testing renders value inside onf the pie 1`] = ` } d="M-42.492,90.523A100,100,0,0,1,-1,-99.995L0,0Z" data-is-focusable={true} - id="_Pie_16third45000" + id="_Pie_20third45000" onBlur={[Function]} onFocus={[Function]} onMouseLeave={[Function]} @@ -3985,7 +3985,7 @@ exports[`DonutChart snapShot testing renders value inside onf the pie 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone18" + data-focuszone-id="FocusZone23" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} diff --git a/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChartRTL.test.tsx.snap b/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChartRTL.test.tsx.snap index df446ed4c626b..551ad53f5f2a7 100644 --- a/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChartRTL.test.tsx.snap +++ b/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChartRTL.test.tsx.snap @@ -1,630 +1,577 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`DonutChart - mouse events Should render callout correctly on mouseover 1`] = ` -
-
-
- - - - - - - - - - - - - -
-
+exports[`Donut chart interactions Should hide callout on mouse leave 1`] = ` +
-
-
-
+ > +
- -
-
- +
+
-
-
- second -
- -
-
- +
+
-
-
- third -
- +
+
+ third +
+ +
@@ -636,1071 +583,447 @@ exports[`DonutChart - mouse events Should render callout correctly on mouseover
`; -exports[`DonutChart - mouse events Should render customized callout on mouseover 1`] = ` -
+exports[`Donut chart interactions Should reflect theme change 1`] = ` +
-
- - - - - - - - - - - - - -
-
-
-
-
-
-
-
-
-
-
-
+ - -
+ { + padding-top: 16px; + width: 0px; + } + > +
+
+
+
- -
-
- -
-
-
-
-
-
-
-
-
-`; - -exports[`DonutChart snapShot testing Should render arc labels 1`] = ` -
-
-
- - - - - - 20.0k - - - - - - 39.0k - - - - - - 45.0k - - - - -
-
- -
-
-
-
-
-
-
-
- -
-
- -
-
- +
-
+ +
+
- third +
- +
@@ -1712,7 +1035,7 @@ exports[`DonutChart snapShot testing Should render arc labels 1`] = `
`; -exports[`DonutChart snapShot testing Should render arc labels in percentage format 1`] = ` +exports[`DonutChart - mouse events Should render callout correctly on mouseover 1`] = `
- - 19% - - - 38% - + id="_Pie_1second39000" + onBlur={[Function]} + onFocus={[Function]} + onMouseLeave={[Function]} + onMouseMove={[Function]} + onMouseOver={[Function]} + opacity={1} + role="img" + /> - + + +
+
+
+
-
- +
+ +
- -
-`; - -exports[`DonutChart snapShot testing renders hideTooltip correctly 1`] = ` -
-
-
- - - - + dominantBaseline="hanging" + textAnchor="start" + x={42.16983494620299} + y={45.45002772947447} + > + 38% + - - - + dominantBaseline="auto" + textAnchor="end" + x={-60.58001193073337} + y={-13.19326170710649} + > + 43% + @@ -3493,7 +2972,7 @@ exports[`DonutChart snapShot testing renders hideTooltip correctly 1`] = ` &:focus { outline: none; } - data-focuszone-id="FocusZone10" + data-focuszone-id="FocusZone33" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3790,7 +3269,7 @@ exports[`DonutChart snapShot testing renders hideTooltip correctly 1`] = `
`; -exports[`DonutChart snapShot testing renders value inside onf the pie 1`] = ` +exports[`DonutChart snapShot testing renders DonutChart correctly 1`] = ` @@ -3961,227 +3422,47 @@ exports[`DonutChart snapShot testing renders value inside onf the pie 1`] = ` } >
-
-
-
-
-
- -
-
- -
+
+
+
+
-
-
-
-
-
-
-
-
-
-`; - -exports[`Screen resolution Should remain unchanged on zoom in 1`] = ` -
-
-
-
- - - - - - - - - - - - - -
-
- -
-
-
-
-
-
-
-
- +
+
+
- -
-
- +
+
+
- -
-
- -
+ third +
+
@@ -4717,436 +3740,472 @@ exports[`Screen resolution Should remain unchanged on zoom in 1`] = `
-
-`; - -exports[`Screen resolution Should remain unchanged on zoom out 1`] = ` -
+
+`; + +exports[`DonutChart snapShot testing renders enabledLegendsWrapLines correctly 1`] = ` +
+
+
+ + + + + + + + + + + + + +
+
+
-
- - - - - - - - - - - - - -
-
- -
-
+
-
+ } + >
-
- +
+
+
- -
-
- +
+
+
- -
-
- -
+ third +
+
@@ -5158,1030 +4217,1095 @@ exports[`Screen resolution Should remain unchanged on zoom out 1`] = `
`; -exports[`Should hide callout on mouse leave 1`] = ` -
+exports[`DonutChart snapShot testing renders hideLegend correctly 1`] = ` +
+
+
+ + + + + + + + + + + + + +
+
+ +
+`; + +exports[`DonutChart snapShot testing renders hideTooltip correctly 1`] = ` +
-
-
- - - - - - - - - - + - - - -
-
- +
+ +
-
+
-
+ } + >
-
- +
+
+
- -
-
- +
+
+
- -
-
- +
+
+
+
+
+
+
+
+
+`; + +exports[`DonutChart snapShot testing renders value inside onf the pie 1`] = ` +
+
+
+ + + + + + + + + + - - -
-
-
-
-
-
-
+ { + fill: #323130; + font-size: 24px; + font-weight: 600; + } + @media screen and (-ms-high-contrast: white-on-black), screen and (forced-colors: active) and (prefers-color-scheme: dark){& { + fill: rgb(179, 179, 179); + } + data-is-focusable={true} + dominantBaseline="middle" + textAnchor="middle" + y={5} + > + 1,000 + + +
-
-`; - -exports[`Should reflect theme change 1`] = ` -
+
-
-
- - - - - - - - - - - - - -
-
- -
+
-
+
-
- +
+
+ -
+ { + background-color: #0078D4; + border-color: #0078D4; + border: 1px solid; + content: ; + height: 12px; + margin-right: 8px; + width: 12px; + } + @media screen and (-ms-high-contrast: active), screen and (forced-colors: active){& { + content: linear-gradient(to right, #0078D4, #0078D4); + opacity: ; + } + />
- +
+
+ -
+ { + background-color: #DADADA; + border-color: #DADADA; + border: 1px solid; + content: ; + height: 12px; + margin-right: 8px; + width: 12px; + } + @media screen and (-ms-high-contrast: active), screen and (forced-colors: active){& { + content: linear-gradient(to right, #DADADA, #DADADA); + opacity: ; + } + />
- + third
-
+
diff --git a/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.tsx b/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.tsx index 982172e5729a8..5611bc8889648 100644 --- a/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.tsx +++ b/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.tsx @@ -56,7 +56,6 @@ export interface IGroupedVerticalBarChartState extends IBasestate { dataPointCalloutProps?: IGVBarChartSeriesPoint; callOutAccessibilityData?: IAccessibilityProps; calloutLegend: string; - emptyChart?: boolean; } export class GroupedVerticalBarChartBase extends React.Component< @@ -84,6 +83,7 @@ export class GroupedVerticalBarChartBase extends React.Component< private _calloutAnchorPoint: IGVBarChartSeriesPoint | null; private _barWidth: number; private _domainMargin: number; + private _emptyChartId: string; public constructor(props: IGroupedVerticalBarChartProps) { super(props); @@ -100,7 +100,6 @@ export class GroupedVerticalBarChartBase extends React.Component< hoverXValue: '', calloutLegend: '', activeLegend: '', - emptyChart: false, }; warnDeprecations(COMPONENT_NAME, props, { showYAxisGridLines: 'Dont use this property. Lines are drawn by default', @@ -113,17 +112,7 @@ export class GroupedVerticalBarChartBase extends React.Component< this._calloutId = getId('callout'); this._tooltipId = getId('GVBCTooltipId_'); this._domainMargin = MIN_DOMAIN_MARGIN; - } - - public componentDidMount(): void { - const isChartEmpty = !( - this.props.data && - this.props.data.length > 0 && - this.props.data.filter((item: IGroupedVerticalBarChartData) => item.series.length).length > 0 - ); - if (this.state.emptyChart !== isChartEmpty) { - this.setState({ emptyChart: isChartEmpty }); - } + this._emptyChartId = getId('_GVBC_empty'); } public render(): React.ReactNode { @@ -166,7 +155,7 @@ export class GroupedVerticalBarChartBase extends React.Component< tickFormat: this.props.tickFormat!, }; - return !this.state.emptyChart ? ( + return !this._isChartEmpty() ? ( ) : ( -
+
); } @@ -595,4 +589,12 @@ export class GroupedVerticalBarChartBase extends React.Component< right: this.margins.right! + this._domainMargin, }; }; + + private _isChartEmpty(): boolean { + return !( + this.props.data && + this.props.data.length > 0 && + this.props.data.filter((item: IGroupedVerticalBarChartData) => item.series.length).length > 0 + ); + } } diff --git a/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChart.test.tsx b/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChart.test.tsx index f47fc308799bb..419bb0fece3e2 100644 --- a/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChart.test.tsx +++ b/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChart.test.tsx @@ -38,7 +38,7 @@ function sharedAfterEach() { window.requestAnimationFrame = originalRAF; } -const chartPoints = [ +export const chartPoints = [ { name: '2000', series: [ @@ -87,7 +87,7 @@ const chartPoints = [ }, ]; -const emptyChartPoints = [ +export const emptyChartPoints = [ { name: 'Empty chart', series: [], diff --git a/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChartRTL.test.tsx b/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChartRTL.test.tsx new file mode 100644 index 0000000000000..60911e280ad24 --- /dev/null +++ b/packages/react-charting/src/components/GroupedVerticalBarChart/GroupedVerticalBarChartRTL.test.tsx @@ -0,0 +1,22 @@ +import * as React from 'react'; +import { queryAllByAttribute, render, waitFor } from '@testing-library/react'; +import { chartPoints, emptyChartPoints } from './GroupedVerticalBarChart.test'; +import { GroupedVerticalBarChart } from './index'; + +describe('Grouped Vertical Bar chart rendering', () => { + test('Should re-render the Grouped Vertical Bar chart with data', async () => { + // Arrange + const { container, rerender } = render(); + const getById = queryAllByAttribute.bind(null, 'id'); + // Assert + expect(container).toMatchSnapshot(); + expect(getById(container, /_GVBC_empty/i)).toHaveLength(1); + // Act + rerender(); + await waitFor(() => { + // Assert + expect(container).toMatchSnapshot(); + expect(getById(container, /_GVBC_empty/i)).toHaveLength(0); + }); + }); +}); diff --git a/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChart.test.tsx.snap b/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChart.test.tsx.snap index 813b0f62f75a7..eccc78c98f254 100644 --- a/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChart.test.tsx.snap +++ b/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChart.test.tsx.snap @@ -16,7 +16,7 @@ exports[`GroupedVerticalBarChart - mouse events Should render callout correctly overflow: hidden; width: 100%; } - id="chart_2" + id="chart_3" onMouseLeave={[Function]} role="presentation" > @@ -29,7 +29,7 @@ exports[`GroupedVerticalBarChart - mouse events Should render callout correctly { overflow: auto; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -69,7 +69,7 @@ exports[`GroupedVerticalBarChart - mouse events Should render callout correctly & path { display: none; } - id="xAxisGElementchart_2" + id="xAxisGElementchart_3" transform="translate(0, 275)" /> @@ -286,7 +286,7 @@ exports[`GroupedVerticalBarChart - mouse events Should render callout correctly &:focus { outline: none; } - data-focuszone-id="FocusZone4" + data-focuszone-id="FocusZone5" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -768,7 +768,7 @@ exports[`GroupedVerticalBarChart - mouse events Should render customized callout overflow: hidden; width: 100%; } - id="chart_2" + id="chart_3" onMouseLeave={[Function]} role="presentation" > @@ -781,7 +781,7 @@ exports[`GroupedVerticalBarChart - mouse events Should render customized callout { overflow: auto; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -821,7 +821,7 @@ exports[`GroupedVerticalBarChart - mouse events Should render customized callout & path { display: none; } - id="xAxisGElementchart_2" + id="xAxisGElementchart_3" transform="translate(0, 275)" /> @@ -1038,7 +1038,7 @@ exports[`GroupedVerticalBarChart - mouse events Should render customized callout &:focus { outline: none; } - data-focuszone-id="FocusZone4" + data-focuszone-id="FocusZone5" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1440,7 +1440,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders GroupedVerticalBarChar overflow: hidden; width: 100%; } - id="chart_2" + id="chart_3" onMouseLeave={[Function]} role="presentation" > @@ -1453,7 +1453,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders GroupedVerticalBarChar { overflow: auto; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -1493,7 +1493,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders GroupedVerticalBarChar & path { display: none; } - id="xAxisGElementchart_2" + id="xAxisGElementchart_3" transform="translate(0, 275)" /> @@ -1716,7 +1716,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders GroupedVerticalBarChar &:focus { outline: none; } - data-focuszone-id="FocusZone4" + data-focuszone-id="FocusZone5" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2035,7 +2035,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders enabledLegendsWrapLine overflow: hidden; width: 100%; } - id="chart_2" + id="chart_3" onMouseLeave={[Function]} role="presentation" > @@ -2048,7 +2048,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders enabledLegendsWrapLine { overflow: auto; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2088,7 +2088,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders enabledLegendsWrapLine & path { display: none; } - id="xAxisGElementchart_2" + id="xAxisGElementchart_3" transform="translate(0, 275)" /> @@ -2294,7 +2294,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders enabledLegendsWrapLine &:focus { outline: none; } - data-focuszone-id="FocusZone4" + data-focuszone-id="FocusZone5" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2610,7 +2610,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders hideLegend correctly 1 overflow: hidden; width: 100%; } - id="chart_2" + id="chart_3" onMouseLeave={[Function]} role="presentation" > @@ -2623,7 +2623,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders hideLegend correctly 1 { overflow: auto; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2663,7 +2663,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders hideLegend correctly 1 & path { display: none; } - id="xAxisGElementchart_2" + id="xAxisGElementchart_3" transform="translate(0, 315)" /> @@ -2862,7 +2862,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders hideTooltip correctly overflow: hidden; width: 100%; } - id="chart_2" + id="chart_3" onMouseLeave={[Function]} role="presentation" > @@ -2875,7 +2875,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders hideTooltip correctly { overflow: auto; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -2915,7 +2915,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders hideTooltip correctly & path { display: none; } - id="xAxisGElementchart_2" + id="xAxisGElementchart_3" transform="translate(0, 275)" /> @@ -3138,7 +3138,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders hideTooltip correctly &:focus { outline: none; } - data-focuszone-id="FocusZone4" + data-focuszone-id="FocusZone5" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3457,7 +3457,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders showXAxisLablesTooltip overflow: hidden; width: 100%; } - id="chart_2" + id="chart_3" onMouseLeave={[Function]} role="presentation" > @@ -3470,7 +3470,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders showXAxisLablesTooltip { overflow: auto; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -3510,7 +3510,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders showXAxisLablesTooltip & path { display: none; } - id="xAxisGElementchart_2" + id="xAxisGElementchart_3" transform="translate(0, 275)" /> @@ -3733,7 +3733,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders showXAxisLablesTooltip &:focus { outline: none; } - data-focuszone-id="FocusZone4" + data-focuszone-id="FocusZone5" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -4052,7 +4052,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders wrapXAxisLables correc overflow: hidden; width: 100%; } - id="chart_2" + id="chart_3" onMouseLeave={[Function]} role="presentation" > @@ -4065,7 +4065,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders wrapXAxisLables correc { overflow: auto; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -4105,7 +4105,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders wrapXAxisLables correc & path { display: none; } - id="xAxisGElementchart_2" + id="xAxisGElementchart_3" transform="translate(0, 275)" /> @@ -4328,7 +4328,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders wrapXAxisLables correc &:focus { outline: none; } - data-focuszone-id="FocusZone4" + data-focuszone-id="FocusZone5" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -4647,7 +4647,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders yAxisTickFormat correc overflow: hidden; width: 100%; } - id="chart_2" + id="chart_3" onMouseLeave={[Function]} role="presentation" > @@ -4660,7 +4660,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders yAxisTickFormat correc { overflow: auto; } - data-focuszone-id="FocusZone3" + data-focuszone-id="FocusZone4" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} @@ -4700,7 +4700,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders yAxisTickFormat correc & path { display: none; } - id="xAxisGElementchart_2" + id="xAxisGElementchart_3" transform="translate(0, 275)" /> @@ -4923,7 +4923,7 @@ exports[`GroupedVerticalBarChart snapShot testing renders yAxisTickFormat correc &:focus { outline: none; } - data-focuszone-id="FocusZone4" + data-focuszone-id="FocusZone5" onFocus={[Function]} onKeyDown={[Function]} onMouseDownCapture={[Function]} diff --git a/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChartRTL.test.tsx.snap b/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChartRTL.test.tsx.snap new file mode 100644 index 0000000000000..3bd8ef6e150d3 --- /dev/null +++ b/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChartRTL.test.tsx.snap @@ -0,0 +1,5769 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Grouped Vertical Bar chart rendering Should re-render the Grouped Vertical Bar chart with data 1`] = ` +
+ +`; + +exports[`Grouped Vertical Bar chart rendering Should re-render the Grouped Vertical Bar chart with data 2`] = ` +
+ +
+`; + +exports[`GroupedVerticalBarChart - mouse events Should render callout correctly on mouseover 1`] = ` +