-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Coachmark (v8): convert tests to use testing-library #22242
Merged
TristanWatanabe
merged 2 commits into
microsoft:master
from
TristanWatanabe:coachmark-convert-to-testing-library
Mar 30, 2022
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as React from 'react'; | ||
import { Coachmark } from './Coachmark'; | ||
import { safeCreate, safeMount } from '@fluentui/test-utilities'; | ||
import { Coachmark, ICoachmarkProps } from './index'; | ||
import { render, within } from '@testing-library/react'; | ||
import { resetIds } from '@fluentui/utilities'; | ||
import { isConformant } from '../../common/isConformant'; | ||
import * as path from 'path'; | ||
|
@@ -30,66 +30,63 @@ describe('Coachmark', () => { | |
it('renders Coachmark (correctly)', () => { | ||
ReactDOM.createPortal = jest.fn(element => element); | ||
|
||
safeCreate( | ||
const { container } = render( | ||
<Coachmark className={'test-className'} target="test-target"> | ||
This is a test | ||
</Coachmark>, | ||
component => { | ||
const tree = component!.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}, | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders Coachmark (isCollapsed)', () => { | ||
ReactDOM.createPortal = jest.fn(element => element); | ||
|
||
safeCreate( | ||
const { container } = render( | ||
<Coachmark isCollapsed={false} className={'test-className'} target="test-target"> | ||
This is a test | ||
</Coachmark>, | ||
component => { | ||
const tree = component!.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}, | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders Coachmark (color properties)', () => { | ||
ReactDOM.createPortal = jest.fn(element => element); | ||
|
||
safeCreate(<Coachmark beaconColorOne="green" beaconColorTwo="blue" color="red" target="test" />, component => { | ||
const tree = component!.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
const { container } = render(<Coachmark beaconColorOne="green" beaconColorTwo="blue" color="red" target="test" />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
// Accessibility Tests: | ||
it('correctly applies (ariaAlertText)', () => { | ||
safeMount(<Coachmark ariaAlertText="aria alert " target="test-target" />, component => { | ||
expect(component.find('[role="alert"]').getDOMNode()).toBeDefined(); | ||
}); | ||
const { getByRole } = render(<Coachmark ariaAlertText="aria alert " target="test-target" />); | ||
expect(getByRole('alert')).toBeTruthy(); | ||
}); | ||
|
||
it('correctly applies (ariaLabelBy)', () => { | ||
safeMount( | ||
<Coachmark ariaLabelledBy="aria label" ariaLabelledByText="aria text" target="test-target" />, | ||
component => { | ||
expect(component.find('[role="dialog"]').getDOMNode().getAttribute('aria-labelledby')).toBe('aria label'); | ||
expect(component.find('[id="aria label"]').text()).toBe('aria text'); | ||
}, | ||
const { getByRole } = render( | ||
<Coachmark | ||
ariaLabelledBy="aria label" | ||
ariaLabelledByText="aria text" | ||
target={document as ICoachmarkProps['target']} | ||
/>, | ||
); | ||
|
||
const coachmark = getByRole('dialog', { hidden: true }); | ||
expect(coachmark.getAttribute('aria-labelledby')).toBe('aria label'); | ||
expect(within(coachmark).queryByText('aria text')).toBeTruthy(); | ||
}); | ||
|
||
it('correctly applies (ariaDescribedBy)', () => { | ||
safeMount( | ||
<Coachmark ariaDescribedBy="aria description" ariaDescribedByText="aria description text" target="test-target" />, | ||
component => { | ||
expect(component.find('[role="dialog"]').getDOMNode().getAttribute('aria-describedby')).toBe( | ||
'aria description', | ||
); | ||
expect(component.find('[id="aria description"]').text()).toBe('aria description text'); | ||
}, | ||
const { getByRole } = render( | ||
<Coachmark | ||
ariaDescribedBy="aria description" | ||
ariaDescribedByText="aria description text" | ||
target={document as ICoachmarkProps['target']} | ||
/>, | ||
); | ||
|
||
const coachmark = getByRole('dialog', { hidden: true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
expect(coachmark.getAttribute('aria-describedby')).toBe('aria description'); | ||
expect(within(coachmark).queryByText('aria description text')).toBeTruthy(); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed
hidden:true
option sincedialog
role is inaccessible here because the element containing that role has a parent wrapper withrole=presentation
when theCoachmark
is not collapsed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I wonder if that's an actual a11y problem? Regardless would be good to note that in a comment in the file.