-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { render, fireEvent } from '../../__tests__/utils'; | ||
import { DBreadcrumb } from './Breadcrumb'; | ||
|
||
describe('DBreadcrumb', () => { | ||
it('renders the breadcrumb with items', () => { | ||
const breadcrumbItems = [ | ||
{ id: 'home', title: 'Home' }, | ||
{ id: 'about', title: 'About', link: true }, | ||
{ id: 'contact', title: 'Contact' }, | ||
]; | ||
|
||
const { getByText } = render(<DBreadcrumb dList={breadcrumbItems} />); | ||
|
||
expect(getByText('Home')).toBeInTheDocument(); | ||
expect(getByText('About')).toBeInTheDocument(); | ||
expect(getByText('Contact')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls "onItemClick" when an item is clicked', () => { | ||
const onItemClickMock = jest.fn(); | ||
const breadcrumbItems = [ | ||
{ id: 'home', title: 'Home' }, | ||
{ id: 'about', title: 'About', link: true }, | ||
]; | ||
|
||
const { getByText } = render(<DBreadcrumb dList={breadcrumbItems} onItemClick={onItemClickMock} />); | ||
|
||
fireEvent.click(getByText('About')); | ||
expect(onItemClickMock).toHaveBeenCalledWith('about', breadcrumbItems[1]); | ||
}); | ||
|
||
it('uses the custom separator if provided', () => { | ||
const customSeparator = '>'; | ||
const breadcrumbItems = [ | ||
{ id: 'home', title: 'Home' }, | ||
{ id: 'about', title: 'About', link: true }, | ||
]; | ||
|
||
const { queryAllByRole } = render(<DBreadcrumb dList={breadcrumbItems} dSeparator={customSeparator} />); | ||
|
||
const separators = queryAllByRole('separator'); | ||
separators.forEach((separator) => { | ||
expect(separator).toHaveTextContent(customSeparator); | ||
}); | ||
}); | ||
}); |