-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DonorsListContainer
component to fetch data with `donorOrganization…
…Ids`
- Loading branch information
1 parent
2ec2735
commit 1affaad
Showing
6 changed files
with
98 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import { Loading } from '@folio/stripes/components'; | ||
|
||
import { DonorsList } from './DonorsList'; | ||
import { useFetchDonors } from './hooks'; | ||
|
||
export const DonorsListContainer = ({ donorOrganizationIds, ...rest }) => { | ||
const { donors, isLoading } = useFetchDonors(donorOrganizationIds); | ||
|
||
if (isLoading) { | ||
return <Loading />; | ||
} | ||
|
||
return ( | ||
<DonorsList | ||
rowProps={{ alignLastColToEnd: false }} | ||
contentData={donors} | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
DonorsListContainer.propTypes = { | ||
donorOrganizationIds: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
}; |
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,58 @@ | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { DonorsListContainer } from './DonorsListContainer'; | ||
import { useFetchDonors } from './hooks'; | ||
|
||
jest.mock('@folio/stripes/components', () => ({ | ||
...jest.requireActual('@folio/stripes/components'), | ||
Loading: jest.fn(() => 'Loading'), | ||
})); | ||
|
||
jest.mock('./DonorsList', () => ({ | ||
DonorsList: jest.fn(() => 'DonorsList'), | ||
})); | ||
|
||
jest.mock('./hooks', () => ({ | ||
useFetchDonors: jest.fn().mockReturnValue({ | ||
donors: [], | ||
isLoading: false, | ||
}), | ||
})); | ||
|
||
const defaultProps = { | ||
donorOrganizationIds: [], | ||
}; | ||
|
||
const wrapper = ({ children }) => ( | ||
<MemoryRouter> | ||
{children} | ||
</MemoryRouter> | ||
); | ||
|
||
const renderComponent = (props = {}) => (render( | ||
<DonorsListContainer | ||
{...defaultProps} | ||
{...props} | ||
/>, | ||
{ wrapper }, | ||
)); | ||
|
||
describe('DonorsListContainer', () => { | ||
it('should render component', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByText('DonorsList')).toBeDefined(); | ||
}); | ||
|
||
it('should render loading component', () => { | ||
useFetchDonors.mockClear().mockReturnValue({ | ||
donors: [], | ||
isLoading: true, | ||
}); | ||
|
||
renderComponent(); | ||
|
||
expect(screen.getByText('Loading')).toBeDefined(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { Donors } from './Donors'; | ||
export { DonorsList } from './DonorsList'; | ||
export { DonorsListContainer } from './DonorsListContainer'; | ||
export { useFetchDonors } from './hooks/useFetchDonors'; |