-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New ToolTips + InfoTips, including adding required InfoTips to IconButtons
- Loading branch information
Showing
68 changed files
with
1,821 additions
and
475 deletions.
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { StarIcon } from '@codecademy/gamut-icons'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { setupRtl } from 'component-test-setup'; | ||
|
||
import { IconButton } from '../IconButton'; | ||
import { IconButtonFloatingMock } from './mocks'; | ||
|
||
const label = 'Click'; | ||
const tip = 'Click this button'; | ||
const tipText = 'this button'; | ||
const uniqueTip = 'I am not repetitive text'; | ||
|
||
const onClick = jest.fn(); | ||
const buttonProps = { | ||
'aria-label': label, | ||
icon: StarIcon, | ||
onClick, | ||
tip, | ||
}; | ||
|
||
const renderView = setupRtl(IconButton, buttonProps); | ||
|
||
const renderFloatingView = setupRtl(IconButtonFloatingMock, buttonProps); | ||
|
||
describe('IconButton', () => { | ||
it('renders a clickable button', () => { | ||
const { view } = renderView(); | ||
|
||
const cta = view.getByRole('button', { name: label }); | ||
|
||
userEvent.click(cta); | ||
|
||
expect(onClick).toHaveBeenCalled(); | ||
}); | ||
it('renders an icon ', () => { | ||
const { view } = renderView(); | ||
|
||
view.getByTitle('Star Icon'); | ||
}); | ||
|
||
// TO-DO: When we upgrade jest, we can use `description` in the tests below to make sure they are semantically connected to buttons. | ||
it('renders a tip with repetition removed', async () => { | ||
const { view } = renderView({}); | ||
|
||
view.getByRole('button', { name: label }); | ||
view.getByRole('tooltip', { name: tipText }); | ||
}); | ||
|
||
it('renders a tip with both labels when they are not repetitive', async () => { | ||
const { view } = renderView({ tip: uniqueTip }); | ||
|
||
view.getByRole('button', { name: label }); | ||
view.getByRole('tooltip', { name: uniqueTip }); | ||
}); | ||
|
||
it('renders a true aria-label based on tip when aria-label is not defined', async () => { | ||
const { view } = renderView({ 'aria-label': undefined }); | ||
|
||
view.getByRole('button', { name: label }); | ||
view.getByRole('tooltip', { name: tipText }); | ||
}); | ||
|
||
it('renders a floating tip', async () => { | ||
const { view } = renderFloatingView({}); | ||
|
||
view.getByRole('tooltip', { name: tipText }); | ||
expect(view.queryByText(tip)).toBeNull(); | ||
|
||
const cta = view.getByRole('button', { name: label }); | ||
|
||
expect(view.queryByText('tooltip')).toBeNull(); | ||
|
||
userEvent.hover(cta); | ||
|
||
view.getByText(tip); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ColorMode } from '@codecademy/gamut-styles'; | ||
import { MockGamutProvider } from '@codecademy/gamut-tests'; | ||
import React, { ComponentProps } from 'react'; | ||
|
||
import { Box } from '../../Box'; | ||
import { IconButton } from '..'; | ||
|
||
export const IconButtonFloatingMock: React.FC< | ||
ComponentProps<typeof IconButton> | ||
> = (props) => { | ||
return ( | ||
<MockGamutProvider> | ||
<ColorMode mode="light"> | ||
<Box width="500px"> | ||
<IconButton tipProps={{ placement: 'floating' }} {...props} /> | ||
</Box> | ||
</ColorMode> | ||
</MockGamutProvider> | ||
); | ||
}; |
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
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
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
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
Oops, something went wrong.