-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from kubit-ui/feature/new-components-and-impro…
…vements Feature/new components and improvements
- Loading branch information
Showing
203 changed files
with
3,280 additions
and
805 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
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,106 @@ | ||
import { fireEvent, screen } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
|
||
import { axe } from 'jest-axe'; | ||
|
||
import { renderProvider } from '@/tests/renderProvider/renderProvider.utility'; | ||
|
||
import { Badge } from '../badge'; | ||
import { IBadge } from '../types'; | ||
|
||
// Mocks | ||
const mockProps: IBadge = { | ||
dataTestId: 'badge-component', | ||
variant: 'PRIMARY', | ||
size: 'DEFAULT', | ||
dot: { | ||
variant: 'WITH_BORDER', | ||
size: 'MEDIUM', | ||
number: 23, | ||
maxNumber: 99, | ||
}, | ||
icon: { icon: 'CONTACTS' }, | ||
label: { content: 'Notifications' }, | ||
labelIcon: { icon: 'CHEVRON_DOWN' }, | ||
ariaLiveText: 'New notification', | ||
['aria-label']: 'Open menu', | ||
}; | ||
|
||
describe('Badge component', () => { | ||
it('Should be displayed correctly', async () => { | ||
const ref = jest.fn(); | ||
const { container } = renderProvider(<Badge ref={ref} {...mockProps} />); | ||
|
||
const badge = screen.getByTestId(mockProps.dataTestId + 'Badge'); | ||
expect(badge).toBeInTheDocument(); | ||
|
||
const results = await axe(container); | ||
expect(container).toHTMLValidate(); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
it('When it has a dot, the dot position is custompizable using customDotTranslate', () => { | ||
const ref = jest.fn(); | ||
renderProvider(<Badge ref={ref} {...mockProps} customDotTranslate="translate(2px, 2px)" />); | ||
|
||
const badge = screen.getByTestId(mockProps.dataTestId + 'Badge'); | ||
expect(badge).toBeInTheDocument(); | ||
}); | ||
|
||
it('CustomDotTranslate can also be defined via styles', () => { | ||
const ref = jest.fn(); | ||
renderProvider( | ||
<Badge ref={ref} {...mockProps} cts={{ customDotNumberTranslate: '"translate(2px, 2px)' }} /> | ||
); | ||
|
||
const badge = screen.getByTestId(mockProps.dataTestId + 'Badge'); | ||
expect(badge).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should be displayed correctly without label', async () => { | ||
const { container } = renderProvider(<Badge {...mockProps} label={undefined} />); | ||
|
||
const badge = screen.getByTestId(mockProps.dataTestId + 'Badge'); | ||
expect(badge).toBeInTheDocument(); | ||
|
||
const results = await axe(container); | ||
expect(container).toHTMLValidate(); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
it('Should be displayed correctly with simulate onClick', () => { | ||
renderProvider(<Badge {...mockProps} label={undefined} />); | ||
|
||
const triggerButton = screen.getByLabelText('Open menu'); | ||
fireEvent.click(triggerButton); | ||
|
||
const badge = screen.getByTestId(mockProps.dataTestId + 'Badge'); | ||
expect(badge).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should call onClick if defined when open', async () => { | ||
const onClick = jest.fn(); | ||
const { container, getByLabelText } = renderProvider( | ||
<Badge {...mockProps} onClick={onClick} /> | ||
); | ||
|
||
const triggerButton = getByLabelText('Open menu'); | ||
fireEvent.click(triggerButton); | ||
|
||
expect(onClick).toHaveBeenCalled(); | ||
|
||
const results = await axe(container); | ||
expect(container).toHTMLValidate(); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
it('Should be displayed correctly when simulate onBlur', () => { | ||
renderProvider(<Badge {...mockProps} />); | ||
|
||
const triggerButton = screen.getByLabelText('Open menu'); | ||
fireEvent.blur(triggerButton); | ||
|
||
const badge = screen.getByTestId(mockProps.dataTestId + 'Badge'); | ||
expect(badge).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.