-
Notifications
You must be signed in to change notification settings - Fork 294
feat: added the ability to close the hint using the keyboard #1812
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
bcd44b1
0bda1d0
152e9bd
3c3bca8
a9e7617
f00f1eb
4e6bbcd
3180f60
8be39b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { screen, waitFor } from '@testing-library/react'; | ||
|
||
| import userEvent from '@testing-library/user-event'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { IntlProvider } from 'react-intl'; | ||
| import GradeSummaryHeader from './GradeSummaryHeader'; | ||
| import { useModel } from '../../../../generic/model-store'; | ||
| import messages from '../messages'; | ||
| import { initializeMockApp, render } from '../../../../setupTest'; | ||
|
||
|
|
||
| jest.mock('react-redux', () => ({ | ||
| useSelector: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../../../../generic/model-store', () => ({ | ||
| useModel: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../../../../data/hooks', () => ({ | ||
| useContextId: () => 'test-course-id', | ||
| })); | ||
|
|
||
| describe('GradeSummaryHeader', () => { | ||
| beforeAll(() => { | ||
| initializeMockApp(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| useSelector.mockImplementation((selector) => selector({ | ||
| courseHome: { courseId: 'test-course-id' }, | ||
| })); | ||
| useModel.mockReturnValue({ gradesFeatureIsFullyLocked: false }); | ||
| }); | ||
|
|
||
| const renderComponent = (props = {}) => { | ||
| render( | ||
| <IntlProvider locale="en" messages={messages}> | ||
|
||
| <GradeSummaryHeader | ||
| allOfSomeAssignmentTypeIsLocked={false} | ||
| {...props} | ||
| /> | ||
| </IntlProvider>, | ||
| ); | ||
| }; | ||
|
|
||
| it('shows tooltip on icon button click', async () => { | ||
| renderComponent(); | ||
|
|
||
| const iconButton = screen.getByRole('button', { | ||
| name: messages.gradeSummaryTooltipAlt.defaultMessage, | ||
| }); | ||
|
|
||
| await userEvent.click(iconButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText(messages.gradeSummaryTooltipBody.defaultMessage)).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it('hides tooltip on click', async () => { | ||
| renderComponent(); | ||
|
|
||
| const iconButton = screen.getByRole('button', { | ||
| name: messages.gradeSummaryTooltipAlt.defaultMessage, | ||
| }); | ||
|
|
||
| await userEvent.click(iconButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText(messages.gradeSummaryTooltipBody.defaultMessage)).toBeVisible(); | ||
| }); | ||
|
|
||
| await userEvent.click(iconButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.queryByText(messages.gradeSummaryTooltipBody.defaultMessage)).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| it('hides tooltip on blur', async () => { | ||
| renderComponent(); | ||
|
|
||
| const iconButton = screen.getByRole('button', { | ||
| name: messages.gradeSummaryTooltipAlt.defaultMessage, | ||
| }); | ||
|
|
||
| await userEvent.hover(iconButton); | ||
| await userEvent.click(iconButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText(messages.gradeSummaryTooltipBody.defaultMessage)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const blurTarget = document.createElement('button'); | ||
| blurTarget.textContent = 'Outside'; | ||
| document.body.appendChild(blurTarget); | ||
|
|
||
| await userEvent.click(blurTarget); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.queryByText(messages.gradeSummaryTooltipBody.defaultMessage)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| document.body.removeChild(blurTarget); | ||
| }); | ||
|
|
||
| it('hides tooltip when Escape is pressed (covers handleKeyDown)', async () => { | ||
| renderComponent(); | ||
|
|
||
| const iconButton = screen.getByRole('button', { | ||
| name: messages.gradeSummaryTooltipAlt.defaultMessage, | ||
| }); | ||
|
|
||
| await userEvent.hover(iconButton); | ||
| await userEvent.click(iconButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText(messages.gradeSummaryTooltipBody.defaultMessage)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| await userEvent.keyboard('{Escape}'); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.queryByText(messages.gradeSummaryTooltipBody.defaultMessage)).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); | ||
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.
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.
fixed