-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Component testing - Donut chart #27033
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
Merged
srmukher
merged 15 commits into
microsoft:master
from
srmukher:users/srmukher/CompTestDonut
May 2, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8ed087d
Donut chart component testing
srmukher c73df28
Resolving PR comments
srmukher 89999b2
Merging master
srmukher 1e77d96
Merge branch 'microsoft:master' into users/srmukher/CompTestDonut
srmukher 420079b
Merge branch 'master' into users/srmukher/CompTestDonut
srmukher c919d95
Merge branch 'master' into users/srmukher/CompTestDonut
srmukher 90dd8b1
Rearranged and modified tests and test plan
srmukher 8689225
Converting component test plan to a table
srmukher 11e91c2
Removing setup change for extend-expect
srmukher be56372
Merge branch 'master' of https://github.com/srmukher/fluentui into us…
srmukher f6e2b4e
Merge branch 'master' into users/srmukher/CompTestDonut
srmukher f427327
Merge branch 'master' into users/srmukher/CompTestDonut
srmukher 20970f0
Changing the setup for jest-dom in config
srmukher 7821fe3
Merge branch 'users/srmukher/CompTestDonut' of https://github.com/srm…
srmukher 04d58f2
Merge branch 'master' into users/srmukher/CompTestDonut
srmukher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-charting-053d3178-4089-4eb8-af55-9706b4484337.json
This file contains hidden or 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,7 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "Added component tests for donut chart", | ||
| "packageName": "@fluentui/react-charting", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "none" | ||
| } |
This file contains hidden or 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 @@ | ||
| require('@testing-library/jest-dom'); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions
35
packages/react-charting/docs/TestPlans/DonutChart/ComponentTests.md
This file contains hidden or 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,35 @@ | ||
| <div align="center"> | ||
|
|
||
| # Component testing - Donut chart test plan | ||
|
|
||
|  | ||
|
|
||
| ### Subcomponents: Pie and Legend | ||
|
|
||
| ### Library used: jest and (enzyme or react testing library) | ||
|
|
||
| </div> | ||
|
|
||
| | Test case | Execution steps | Validation steps | Library used | | ||
| | -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------ | | ||
| | Test case 1: [Snapshot testing] [Component] | <ul><li>Renders donut chart with data.</li></ul> | Donut chart renders correctly | Enzyme | | ||
| | Test case 2: [Snapshot testing] [Individual Props] | Renders donut chart with: <ul><li>HideTooltip prop set to “true”.</li></ul> | Donut chart renders correctly | Enzyme | | ||
| | | <ul><li>HideLegend prop set to “true”.</li></ul> | Donut chart renders correctly | Enzyme | | ||
| | | <ul><li>EnabledLegendsWrapLines prop set to “true”.</li></ul> | Donut chart renders correctly | Enzyme | | ||
| | | <ul><li>ValueInsideDonut set to a string / number.</li></ul> | Donut chart renders correctly | Enzyme | | ||
| | | <ul><li>HideLabels prop set to "false".</li></ul> | Donut chart renders correctly | Enzyme | | ||
| | | <ul><li>HideLabels prop set to "false" and ShowLabelsInPercent prop set to "true".</li></ul> | Donut chart renders correctly | Enzyme | | ||
| | Test case 3: [Specific DOM elements] Renders individual elements on a prop change: | <ul><li>HideLegend prop is set to “false”.</li></ul> | Legend mounts correctly | Enzyme | | ||
| | | <ul><li>HideTootip prop is set to “false”.</li></ul> | Callout mounts correctly | Enzyme | | ||
| | | <ul><li>onRenderCalloutPerStack prop is not given.</li></ul> | Should not render onRenderCalloutPerStack | Enzyme | | ||
| | | <ul><li>onRenderCalloutPerDataPoint prop is given.</li></ul> | Should render onRenderCalloutPerDataPoint correctly | Enzyme | | ||
| | Test case 4: [Mouse events – Donut chart] Renders individual elements on mouse events: | <ul><li>On mouse over on the donut chart.</li></ul> | Should render callout | Enzyme | | ||
| | | <ul><li>On mouse move on Pie 1 (step 1) -> mouse leave (step 2) -> mouse move on Pie 2 (step 3).</li></ul> | Html in step 1 should not be the same as in step 3 | Enzyme | | ||
| | | <ul><li>On mouse over with onRenderCalloutPerDataPoint prop provided.</li></ul> | Should render the custom callout | Enzyme | | ||
| | | <ul><li>On mouse over, followed by mouse leave on callout.</li></ul> | On mouse over, callout should be defined, on mouse leave, callout should disappear. | Enzyme | | ||
| | Test case 5: [Mouse events – Legends] Renders individual elements on mouse events: | <ul><li>On mouse over on legends.</li></ul> | Should highlight the corresponding pie | RTL | | ||
| | | <ul><li>On mouse over on legends.</li></ul> | Should change the value inside donut with the legend value | Enzyme | | ||
| | | <ul><li>On click on Pie.</li></ul> | Should highlight the corresponding pie with aria-selected set to “true” and tabIndex set to 0. | RTL | | ||
| | | <ul><li>On mouse out after mouse over on first legend.</li></ul> | Should have opacity 0.1 for second Pie initially (during mouseOver on first legend) and opacity set to 1 for both the Pies on mouse out. | RTL | | ||
| | Test case 6: [Keyboard events – Donut chart] Renders individual elements on keyboard events: | <ul><li>On focus on a Pie.</li></ul> | Should render the corresponding callout | RTL | | ||
| | | <ul><li>On blur on a Pie.</li></ul> | Should remove focus from the corresponding Pie | RTL | | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
204 changes: 204 additions & 0 deletions
204
packages/react-charting/src/components/DonutChart/DonutChartRTL.test.tsx
This file contains hidden or 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,204 @@ | ||
| import { render, screen, queryAllByAttribute, fireEvent, act } 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'; | ||
|
|
||
| test('Should hide callout on mouse leave', () => { | ||
| // Arrange | ||
| const { container } = render(<DonutChart data={chartPoints} innerRadius={55} calloutProps={{ doNotLayer: true }} />); | ||
|
|
||
| // Act | ||
| const getById = queryAllByAttribute.bind(null, 'id'); | ||
| fireEvent.mouseOver(getById(container, /Pie/i)[0]); | ||
| expect(getById(container, /callout/i)[0]).toBeDefined(); | ||
srmukher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fireEvent.mouseLeave(getById(container, /Pie/i)[0]); | ||
|
|
||
| // Assert | ||
| expect(getById(container, /callout/i)[0]).toHaveStyle('opacity: 0'); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('Should show callout on focus', () => { | ||
| // Arrange | ||
| const { container } = render(<DonutChart data={chartPoints} innerRadius={55} calloutProps={{ doNotLayer: true }} />); | ||
|
|
||
| // Act | ||
| const getById = queryAllByAttribute.bind(null, 'id'); | ||
| fireEvent.focus(getById(container, /Pie/i)[0]); | ||
|
|
||
| // Assert | ||
| expect(getById(container, /focusRing/i)).toBeDefined(); | ||
| }); | ||
|
|
||
| test('Should remove focus on blur', () => { | ||
| // Arrange | ||
| const { container } = render(<DonutChart data={chartPoints} innerRadius={55} calloutProps={{ doNotLayer: true }} />); | ||
|
|
||
| // Act | ||
| const getById = queryAllByAttribute.bind(null, 'id'); | ||
| fireEvent.blur(getById(container, /Pie/i)[0]); | ||
srmukher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // 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(<DonutChart data={chartPoints} innerRadius={55} hideLegend={false} />); | ||
|
|
||
| // Act | ||
| const legend = screen.queryByText('first'); | ||
srmukher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| expect(legend).toBeDefined(); | ||
| fireEvent.mouseOver(legend!); | ||
|
|
||
| // Assert | ||
| const getById = queryAllByAttribute.bind(null, 'id'); | ||
| expect(getById(container, /Pie.*?second/i)[0]).toHaveAttribute('opacity', '0.1'); | ||
srmukher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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(<DonutChart data={chartPoints} innerRadius={55} hideLegend={false} />); | ||
|
|
||
| // 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 deselect legend on double mouse click on legends', () => { | ||
| // Arrange | ||
| const { container } = render(<DonutChart data={chartPoints} innerRadius={55} hideLegend={false} />); | ||
|
|
||
| // 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'); | ||
| }); | ||
|
|
||
| test('Should show Pies with same opacity on mouse out of legends', () => { | ||
| // Arrange | ||
| const { container } = render(<DonutChart data={chartPoints} innerRadius={55} hideLegend={false} />); | ||
|
|
||
| // 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'); | ||
| }); | ||
|
|
||
| test('Should display correct callout data on mouse move', () => { | ||
| // Arrange | ||
| const { container } = render(<DonutChart data={chartPoints} innerRadius={55} calloutProps={{ doNotLayer: true }} />); | ||
|
|
||
| // 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]); | ||
|
|
||
| // Assert | ||
| expect(getById(container, /callout/i)[0]).toHaveTextContent('39,000'); | ||
| }); | ||
|
|
||
| test('Should reflect theme change', () => { | ||
| // Arrange | ||
| const { container } = render( | ||
| <ThemeProvider theme={DarkTheme}> | ||
| <DonutChart culture={window.navigator.language} data={chartPoints} innerRadius={55} /> | ||
| </ThemeProvider>, | ||
| ); | ||
|
|
||
| // Assert | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| describe('Screen resolution', () => { | ||
| const originalInnerWidth = global.innerWidth; | ||
| const originalInnerHeight = global.innerHeight; | ||
| afterEach(() => { | ||
| global.innerWidth = originalInnerWidth; | ||
| global.innerHeight = originalInnerHeight; | ||
| act(() => { | ||
| global.dispatchEvent(new Event('resize')); | ||
| }); | ||
| }); | ||
|
|
||
| test('Should remain unchanged on zoom in', () => { | ||
| // Arrange | ||
| const { container } = render(<DonutChart data={chartPoints} innerRadius={55} width={300} height={300} />); | ||
|
|
||
| // Act | ||
| global.innerWidth = window.innerWidth / 2; | ||
| global.innerHeight = window.innerHeight / 2; | ||
| act(() => { | ||
| global.dispatchEvent(new Event('resize')); | ||
| }); | ||
|
|
||
| // Assert | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('Should remain unchanged on zoom out', () => { | ||
| // Arrange | ||
| const { container } = render(<DonutChart data={chartPoints} innerRadius={55} width={300} height={300} />); | ||
|
|
||
| // Act | ||
| global.innerWidth = window.innerWidth * 2; | ||
| global.innerHeight = window.innerHeight * 2; | ||
| act(() => { | ||
| global.dispatchEvent(new Event('resize')); | ||
| }); | ||
|
|
||
| // Assert | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
|
|
||
| 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( | ||
| <DonutChart data={chartPoints} innerRadius={55} hideLegend={false} valueInsideDonut={1000} />, | ||
| ); | ||
| const getByClass = queryAllByAttribute.bind(null, 'class'); | ||
|
|
||
| // Act | ||
| fireEvent.mouseOver(screen.getByText('first')); | ||
|
|
||
| // Assert | ||
| expect(getByClass(container, /insideDonutString.*?/)[0].textContent).toBe('20,000'); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.