-
Notifications
You must be signed in to change notification settings - Fork 21
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
1 parent
3db126d
commit 002f861
Showing
10 changed files
with
106 additions
and
12 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
5 changes: 2 additions & 3 deletions
5
packages/react-utils/src/components/PageHeaders/RichPageHeader/index.tsx
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
79 changes: 79 additions & 0 deletions
79
packages/react-utils/src/components/PageHeaders/RichPageHeader/tests/index.test.tsx
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,79 @@ | ||
import React from 'react'; | ||
import { RichPageHeader } from '..'; | ||
import { render, cleanup, screen } from '@testing-library/react'; | ||
import { Router } from 'react-router'; | ||
import { createBrowserHistory } from 'history'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const history = createBrowserHistory(); | ||
|
||
const ComponentWrapper = (props) => { | ||
return ( | ||
<Router history={history}> | ||
<RichPageHeader {...props} /> | ||
</Router> | ||
); | ||
}; | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
jest.clearAllMocks(); | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanup(); | ||
}); | ||
|
||
it('Renders as expected', async () => { | ||
const backBtnSpy = jest.spyOn(history, 'goBack'); | ||
const pageURL = '/test/page'; | ||
history.push(pageURL); | ||
render(<ComponentWrapper />); | ||
|
||
const container = document.querySelector('.ant-page-header'); | ||
const breadCrumbElement = container?.querySelector('.ant-breadcrumb'); | ||
expect(screen.getByText(/View details/)).toBeInTheDocument(); | ||
expect(breadCrumbElement).toBeNull(); | ||
|
||
expect(history.location.pathname).toEqual(pageURL); | ||
|
||
const backBtn = screen.getByRole('button'); | ||
userEvent.click(backBtn); | ||
expect(backBtnSpy).toBeCalledTimes(1); | ||
}); | ||
|
||
it('Renders as expected with props', async () => { | ||
const prevPageURL = '/users'; | ||
const pageURL = `${prevPageURL}/details`; | ||
const breadCrumbProps = { | ||
items: [ | ||
{ | ||
title: 'Users', | ||
path: prevPageURL, | ||
}, | ||
{ | ||
title: 'User details', | ||
}, | ||
], | ||
}; | ||
const pageHeaderProps = { | ||
subTitle: '1234', | ||
}; | ||
const richPageHeaderProps = { | ||
pageHeaderProps, | ||
breadCrumbProps, | ||
}; | ||
history.push(pageURL); | ||
render(<ComponentWrapper {...richPageHeaderProps} />); | ||
|
||
expect(screen.getByText(/View details/)).toBeInTheDocument(); | ||
expect(screen.getByText(/123/)).toBeInTheDocument(); | ||
expect(screen.getByText(/User details/)).toBeInTheDocument(); | ||
|
||
expect(history.location.pathname).toEqual(pageURL); | ||
|
||
const usersLink = screen.getByRole('link', { name: /Users/i }); | ||
userEvent.click(usersLink); | ||
expect(history.location.pathname).toEqual(prevPageURL); | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/react-utils/src/components/PageHeaders/SimplePageHeader/tests/index.test.tsx
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,14 @@ | ||
import React from 'react'; | ||
import { SimplePageHeader } from '..'; | ||
import { render, cleanup, screen } from '@testing-library/react'; | ||
|
||
afterAll(() => { | ||
cleanup(); | ||
}); | ||
|
||
it('Renders as expected', async () => { | ||
const title = 'Test Page'; | ||
render(<SimplePageHeader title={title} />); | ||
|
||
expect(screen.getByText(title)).toBeInTheDocument(); | ||
}); |