-
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.
UIU-3219 - navigate to pre patron registrations page and render list (#…
…2755) * UIU-3219 - navigate to pre patron registrations page and render list * upgrade upload artifact version * cleanup * update unit test * UIU-3219 - update tests * UIU-3219 - update records count * UIU-3219 - add interface dependency, fix review comments * UIU-3219 - update query to fetch only 'TIER-2' records * UIU-3219 - update test data for staging records with 'TIER-2' status * UIU-3219 - update chanelog to reflect breaking change * UIU-3221 - create new permission 'Users: Can view patron preregistration data' * UIU-3219 - update tests for PatronPreRegistrationRecordsContainer * UIU-3219 - update sub permission of permission 'Users: Can view patron preregistration data' * UIU-3219 - fix rveiew comments * UIU-3219 - fix lint issue
- Loading branch information
1 parent
f106bde
commit 7889b7d
Showing
22 changed files
with
836 additions
and
7 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
34 changes: 34 additions & 0 deletions
34
src/components/LinkToPatronPreRegistrations/LinkToPatronPreRegistrations.js
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,34 @@ | ||
import { useHistory } from 'react-router-dom'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { IfPermission } from '@folio/stripes/core'; | ||
import { | ||
Button, | ||
Icon, | ||
} from '@folio/stripes/components'; | ||
|
||
|
||
const LinkToPatronPreRegistrations = () => { | ||
const history = useHistory(); | ||
|
||
return ( | ||
<IfPermission perm="ui-users.patron-pre-registrations-view"> | ||
<Button | ||
to={{ | ||
pathname: '/users/pre-registration-records', | ||
state: { | ||
pathname: history?.location?.pathname, | ||
search: history?.location?.search, | ||
}, | ||
}} | ||
buttonStyle="dropdownItem" | ||
> | ||
<Icon icon="search"> | ||
<FormattedMessage id="ui-users.actionMenu.preRegistrationRecords" /> | ||
</Icon> | ||
</Button> | ||
</IfPermission> | ||
); | ||
}; | ||
|
||
export default LinkToPatronPreRegistrations; |
26 changes: 26 additions & 0 deletions
26
src/components/LinkToPatronPreRegistrations/LinkToPatronPreRegistrations.test.js
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 { | ||
screen, | ||
render, | ||
} from '@folio/jest-config-stripes/testing-library/react'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { createMemoryHistory } from 'history'; | ||
|
||
import '../../../test/jest/__mock__'; | ||
|
||
import LinkToPatronPreRegistrations from './LinkToPatronPreRegistrations'; | ||
|
||
describe('LinkToPatronPreRegistrations', () => { | ||
beforeEach(() => { | ||
const history = createMemoryHistory(); | ||
|
||
render( | ||
<Router history={history}> | ||
<LinkToPatronPreRegistrations /> | ||
</Router> | ||
); | ||
}); | ||
|
||
it('should render button', () => { | ||
expect(screen.getByText('ui-users.actionMenu.preRegistrationRecords')).toBeInTheDocument(); | ||
}); | ||
}); |
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 @@ | ||
export { default } from './LinkToPatronPreRegistrations'; |
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,96 @@ | ||
import PropTypes from 'prop-types'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { get } from 'lodash'; | ||
|
||
import { stripesConnect } from '@folio/stripes/core'; | ||
import { | ||
makeQueryFunction, | ||
StripesConnectedSource, | ||
} from '@folio/stripes/smart-components'; | ||
import PatronsPreRegistrationListContainer from '../views/PatronsPreRegistrationListContainer/PatronsPreRegistrationListContainer'; | ||
|
||
import { PATRON_PREREGISTRATION_RECORDS_NAME } from '../constants'; | ||
|
||
const RESULT_COUNT_INCREMENT = 100; | ||
const PAGE_AMOUNT = 100; | ||
|
||
const PatronPreRegistrationRecordsContainer = ({ | ||
resources, | ||
mutator, | ||
stripes, | ||
}) => { | ||
const history = useHistory(); | ||
const source = new StripesConnectedSource({ resources, mutator }, stripes.logger, PATRON_PREREGISTRATION_RECORDS_NAME); | ||
const data = get(resources, `${PATRON_PREREGISTRATION_RECORDS_NAME}.records`, []); | ||
|
||
const queryGetter = () => { | ||
return get(resources, 'query', {}); | ||
}; | ||
|
||
const onNeedMoreData = (askAmount, index) => { | ||
const { resultOffset } = mutator; | ||
|
||
if (source) { | ||
if (resultOffset && index >= 0) { | ||
source.fetchOffset(index); | ||
} else { | ||
source.fetchMore(RESULT_COUNT_INCREMENT); | ||
} | ||
} | ||
}; | ||
|
||
const onClose = () => { | ||
history.push('/users?sort=name'); | ||
}; | ||
|
||
return ( | ||
<PatronsPreRegistrationListContainer | ||
onClose={onClose} | ||
queryGetter={queryGetter} | ||
onNeedMoreData={onNeedMoreData} | ||
source={source} | ||
data={data} | ||
stripes={stripes} | ||
/> | ||
); | ||
}; | ||
|
||
PatronPreRegistrationRecordsContainer.manifest = { | ||
query: { initialValue: {} }, | ||
resultCount: { initialValue: 0 }, | ||
resultOffset: { initialValue: 0 }, | ||
[PATRON_PREREGISTRATION_RECORDS_NAME]: { | ||
type: 'okapi', | ||
records: 'staging_users', | ||
resultOffset: '%{resultOffset}', | ||
resultDensity: 'sparse', | ||
perRequest: PAGE_AMOUNT, | ||
path: 'staging-users', | ||
GET: { | ||
params: { | ||
query: makeQueryFunction( | ||
'cql.allRecords=1', | ||
'(keywords="%{query.query}*") AND status == "TIER-2"', | ||
{ | ||
'firstName': 'personal.firstName', | ||
'lastName': 'personal.lastName', | ||
'middleName': 'personal.middleName', | ||
'preferredFirsName': 'personal.preferredFirstName', | ||
'email': 'personal.email', | ||
}, | ||
'', | ||
2 | ||
), | ||
}, | ||
staticFallback: { params: {} }, | ||
}, | ||
} | ||
}; | ||
|
||
PatronPreRegistrationRecordsContainer.propTypes = { | ||
mutator: PropTypes.object, | ||
stripes: PropTypes.object, | ||
resources: PropTypes.object, | ||
}; | ||
|
||
export default stripesConnect(PatronPreRegistrationRecordsContainer); |
118 changes: 118 additions & 0 deletions
118
src/routes/PatronPreRegistrationRecordsContainer.test.js
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,118 @@ | ||
import { render, screen, fireEvent } from '@folio/jest-config-stripes/testing-library/react'; | ||
|
||
import preRegistrationRecords from 'fixtures/preRegistrationRecords'; | ||
import buildStripes from '__mock__/stripes.mock'; | ||
|
||
import { createMemoryHistory } from 'history'; | ||
import { MemoryRouter, useHistory } from 'react-router-dom'; | ||
|
||
import { StripesConnectedSource } from '@folio/stripes/smart-components'; | ||
|
||
import PatronPreRegistrationRecordsContainer from './PatronPreRegistrationRecordsContainer'; | ||
|
||
jest.unmock('@folio/stripes/components'); | ||
jest.unmock('@folio/stripes/smart-components'); | ||
jest.mock('@folio/stripes/components', () => ({ | ||
...jest.requireActual('@folio/stripes/components'), | ||
SearchField: jest.fn((props) => ( | ||
<input | ||
{...props} | ||
/> | ||
)), | ||
})); | ||
jest.mock('../views/PatronsPreRegistrationListContainer/PatronsPreRegistrationListContainer', () => { | ||
return jest.fn(({ onClose, onNeedMoreData }) => ( | ||
<div data-testid="mock-PatronsPreRegistrationListContainer"> | ||
Mocked component PatronsPreRegistrationListContainer | ||
<button data-testid="close-button" type="button" onClick={onClose}>close</button> | ||
<button data-testid="need-more-button" type="button" onClick={() => onNeedMoreData(100, 1)}>Need more</button> | ||
</div> | ||
)); | ||
}); | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useHistory: jest.fn(), | ||
})); | ||
|
||
const history = createMemoryHistory(); | ||
history.push = jest.fn(); | ||
const props = { | ||
resources: { | ||
patronPreRegistrationRecords: { | ||
records: preRegistrationRecords, | ||
}, | ||
resultCount: 1, | ||
resultOffset: 0, | ||
}, | ||
mutator: { | ||
patronPreRegistrationRecords:{ | ||
GET: jest.fn(), | ||
}, | ||
resultOffset: 100 | ||
}, | ||
stripes: buildStripes(), | ||
history, | ||
}; | ||
|
||
const renderPatronPreRegistrationRecordsContainer = (alteredProps) => render( | ||
<MemoryRouter> | ||
<PatronPreRegistrationRecordsContainer {...props} {...alteredProps} /> | ||
</MemoryRouter> | ||
); | ||
|
||
describe('PatronPreRegistrationRecordsContainer', () => { | ||
let mockHistory; | ||
let mockSource; | ||
|
||
beforeEach(() => { | ||
// Set up the mock history object | ||
mockHistory = { push: jest.fn() }; | ||
useHistory.mockReturnValue(mockHistory); | ||
|
||
// Mock the StripesConnectedSource instance | ||
mockSource = { | ||
fetchOffset: jest.fn(), | ||
fetchMore: jest.fn(), | ||
}; | ||
|
||
jest.spyOn(StripesConnectedSource.prototype, 'fetchOffset').mockImplementation(mockSource.fetchOffset); | ||
jest.spyOn(StripesConnectedSource.prototype, 'fetchMore').mockImplementation(mockSource.fetchMore); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render', () => { | ||
renderPatronPreRegistrationRecordsContainer(); | ||
expect(screen.getByTestId('mock-PatronsPreRegistrationListContainer')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call onClose method', () => { | ||
renderPatronPreRegistrationRecordsContainer(); | ||
fireEvent.click(screen.getByTestId('close-button')); | ||
|
||
expect(mockHistory.push).toHaveBeenCalledWith('/users?sort=name'); | ||
}); | ||
|
||
it('should call onNeedMoreData method', () => { | ||
renderPatronPreRegistrationRecordsContainer(); | ||
fireEvent.click(screen.getByTestId('need-more-button')); | ||
|
||
expect(mockSource.fetchOffset).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
it('should call onNeedMoreData method', () => { | ||
const alteredProps = { | ||
...props, | ||
mutator: { | ||
...props.mutator, | ||
resultOffset: 0 | ||
}, | ||
}; | ||
renderPatronPreRegistrationRecordsContainer(alteredProps); | ||
fireEvent.click(screen.getByTestId('need-more-button')); | ||
|
||
expect(mockSource.fetchMore).toHaveBeenCalledWith(100); | ||
}); | ||
}); |
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.