-
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 1 commit
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" | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions
48
packages/react-charting/docs/Component tests/DonutChartTestPlan.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,48 @@ | ||
| <div align="center"> | ||
|
|
||
| # Component testing - Donut chart test plan | ||
srmukher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
|
|
||
| ## Subcomponents: Pie and Legend | ||
|
|
||
| ## Library used: jest and (enzyme or react testing library) | ||
|
|
||
| </div> | ||
|
|
||
| ### Test case 1: [Snapshot testing] [Component] | ||
|
|
||
| - Renders donut chart correctly with data. - [enzyme] | ||
|
|
||
| ### Test case 2: [Snapshot testing] [Individual Props] Renders donut chart with: | ||
|
|
||
| - HideTooltip prop set to “true”. - [enzyme] | ||
| - HideLegend prop set to “true”. - [enzyme] | ||
| - EnabledLegendsWrapLines prop set to “true”. - [enzyme] | ||
| - ValueInsideDonut set to a string / number. - [enzyme] | ||
|
|
||
| ### Test case 3: [Specific DOM elements] Renders individual elements on a prop change: | ||
|
|
||
| - Should mount legend when hideLegend prop is set to “false”. - [enzyme] | ||
| - Should mount callout when hideTootip prop is set to “false”. - [enzyme] | ||
| - Should not render onRenderCalloutPerStack with just data as a prop. - [enzyme] | ||
| - Should render onRenderCalloutPerDataPoint when the prop is given otherwise should not render onRenderCalloutPerDataPoint. - [enzyme] | ||
|
|
||
| ### Test case 4: [Mouse events – Donut chart] Renders individual elements on mouse events: | ||
|
|
||
| - On mouseOver on the donut chart should render callout. - [enzyme] | ||
| - On mouseMove on Pie 1 (step 1) -> mouseLeave (step 2) -> mouseMove on Pie 2 (step 3), html in step 1 should not be the same as in step 3. - [enzyme] | ||
| - On mouseover with onRenderCalloutPerDataPoint prop provided, should render the custom callout. [enzyme] | ||
| - On mouseOver, callout should be defined, on mouseLeave, callout should disappear. - [enzyme] | ||
|
|
||
| ### Test case 5: [Mouse events – Legends] Renders individual elements on mouse events: | ||
|
|
||
| - On mouseOver should highlight the corresponding pie. - [RTL] | ||
| - On mouseOver should change the value inside donut with the legend value. - [enzyme] | ||
| - On click should highlight the corresponding pie with aria-selected set to “true” and tabIndex set to 0. - [RTL] | ||
| - On mouseOut after mouseOver on first legend, should have opacity 0.1 for second Pie initially (during mouseOver on first legend) and opacity set to 1 for both the Pies on mouseOut. - [RTL] | ||
|
|
||
| ### Test case 6: [Keyboard events – Donut chart] Renders individual elements on keyboard events: | ||
|
|
||
| - On focus should render the corresponding callout. - [RTL] | ||
| - On blur 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
108 changes: 108 additions & 0 deletions
108
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,108 @@ | ||
| import { render, screen, queryAllByAttribute, fireEvent } from '@testing-library/react'; | ||
| import { chartPoints } from './DonutChart.test'; | ||
| import { DonutChart } from './index'; | ||
| import * as React from 'react'; | ||
|
|
||
| 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'); | ||
| }); | ||
|
|
||
| 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
|
||
| 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
|
||
| }); | ||
|
|
||
| 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'); | ||
| 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'); | ||
| //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'); | ||
| 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'); | ||
| }); | ||
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.