-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIEH-1442: Package Record - Title List view - Apply MCL component, ad…
…d display of managed, custom coverage dates.
- Loading branch information
1 parent
4173702
commit d5a8adc
Showing
42 changed files
with
410 additions
and
128 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
133 changes: 133 additions & 0 deletions
133
src/components/package/show/components/PackageTitleList/PackageTitleList.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,133 @@ | ||
import { useIntl } from 'react-intl'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
MCLPagingTypes, | ||
MultiColumnList, | ||
TextLink, | ||
} from '@folio/stripes/components'; | ||
|
||
import SelectedLabel from '../../../../selected-label'; | ||
import InternalLink from '../../../../internal-link'; | ||
import CoverageDateList from '../../../../coverage-date-list'; | ||
import { isBookPublicationType } from '../../../../utilities'; | ||
|
||
import styles from '../../package-show.css'; | ||
|
||
const COLUMNS = { | ||
STATUS: 'status', | ||
TITLE: 'title', | ||
MANAGED_COVERAGE: 'managedCoverage', | ||
CUSTOM_COVERAGE: 'customCoverage', | ||
MANAGED_EMBARGO: 'managedEmbargo', | ||
}; | ||
|
||
const MAX_HEIGHT = 526; | ||
|
||
const propTypes = { | ||
count: PropTypes.number.isRequired, | ||
isLoading: PropTypes.bool, | ||
onFetchPackageTitles: PropTypes.func.isRequired, | ||
page: PropTypes.number.isRequired, | ||
records: PropTypes.arrayOf(PropTypes.object).isRequired, | ||
totalResults: PropTypes.number.isRequired, | ||
}; | ||
|
||
const PackageTitleList = ({ | ||
records, | ||
isLoading, | ||
totalResults, | ||
page, | ||
count, | ||
onFetchPackageTitles, | ||
}) => { | ||
const intl = useIntl(); | ||
|
||
const columnMappings = { | ||
[COLUMNS.STATUS]: intl.formatMessage({ id: 'ui-eholdings.titlesList.status' }), | ||
[COLUMNS.TITLE]: intl.formatMessage({ id: 'ui-eholdings.titlesList.title' }), | ||
[COLUMNS.MANAGED_COVERAGE]: intl.formatMessage({ id: 'ui-eholdings.titlesList.managedCoverage' }), | ||
[COLUMNS.CUSTOM_COVERAGE]: intl.formatMessage({ id: 'ui-eholdings.titlesList.customCoverage' }), | ||
[COLUMNS.MANAGED_EMBARGO]: intl.formatMessage({ id: 'ui-eholdings.titlesList.managedEmbargo' }), | ||
}; | ||
|
||
const handleMore = (askAmount, index, firstIndex, direction) => { | ||
const newPage = direction === 'next' ? page + 1 : page - 1; | ||
onFetchPackageTitles(newPage); | ||
}; | ||
|
||
const formatter = { | ||
[COLUMNS.STATUS]: item => { | ||
return ( | ||
<SelectedLabel isSelected={item.attributes.isSelected} /> | ||
); | ||
}, | ||
[COLUMNS.TITLE]: item => { | ||
return ( | ||
<TextLink element="span"> | ||
{({ className }) => ( | ||
<InternalLink | ||
to={`/eholdings/resources/${item.id}`} | ||
className={className} | ||
> | ||
{item.attributes.name} | ||
</InternalLink> | ||
)} | ||
</TextLink> | ||
); | ||
}, | ||
[COLUMNS.MANAGED_COVERAGE]: item => { | ||
return ( | ||
<CoverageDateList | ||
isManagedCoverage | ||
coverageArray={item.attributes.managedCoverages} | ||
isYearOnly={isBookPublicationType(item.attributes.publicationType)} | ||
/> | ||
); | ||
}, | ||
[COLUMNS.CUSTOM_COVERAGE]: item => { | ||
return ( | ||
<CoverageDateList | ||
coverageArray={item.attributes.customCoverages} | ||
isYearOnly={isBookPublicationType(item.attributes.publicationType)} | ||
/> | ||
); | ||
}, | ||
[COLUMNS.MANAGED_EMBARGO]: item => { | ||
const { embargoUnit, embargoValue } = item.attributes.managedEmbargoPeriod || {}; | ||
|
||
if (!embargoUnit || !embargoValue) { | ||
return null; | ||
} | ||
|
||
return intl.formatMessage({ id: `ui-eholdings.resource.embargoUnit.${embargoUnit}` }, { | ||
value: embargoValue, | ||
}); | ||
}, | ||
}; | ||
|
||
return ( | ||
<div className={styles.titlesListContainer}> | ||
<MultiColumnList | ||
id="package-title-list" | ||
maxHeight={MAX_HEIGHT} | ||
contentData={records} | ||
visibleColumns={Object.values(COLUMNS)} | ||
columnMapping={columnMappings} | ||
formatter={formatter} | ||
isEmptyMessage={intl.formatMessage({ id: 'ui-eholdings.notFound' })} | ||
loading={isLoading} | ||
hasMargin | ||
totalCount={totalResults} | ||
onNeedMoreData={handleMore} | ||
pageAmount={count} | ||
pagingType={MCLPagingTypes.PREV_NEXT} | ||
pagingOffset={count * (page - 1)} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
PackageTitleList.propTypes = propTypes; | ||
|
||
export { PackageTitleList }; |
137 changes: 137 additions & 0 deletions
137
src/components/package/show/components/PackageTitleList/PackageTitleList.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,137 @@ | ||
import { render } from '@folio/jest-config-stripes/testing-library/react'; | ||
import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; | ||
|
||
import { createMemoryHistory } from 'history'; | ||
import { PackageTitleList } from './PackageTitleList'; | ||
import getAxe from '../../../../../../test/jest/helpers/get-axe'; | ||
import Harness from '../../../../../../test/jest/helpers/harness'; | ||
|
||
const records = [ | ||
{ | ||
id: '1', | ||
attributes: { | ||
isSelected: true, | ||
name: 'Title name1', | ||
managedCoverages: [{ | ||
'beginCoverage': '2005-01-01', | ||
'endCoverage': '2005-12-31' | ||
}], | ||
customCoverages: [ | ||
{ | ||
'beginCoverage': '2025-01-09', | ||
'endCoverage': '2026-01-01' | ||
}, | ||
{ | ||
'beginCoverage': '2025-01-07', | ||
'endCoverage': '2025-01-08' | ||
}, | ||
], | ||
managedEmbargoPeriod: { | ||
embargoUnit: 'Days', | ||
embargoValue: 11, | ||
}, | ||
publicationType: 'book', | ||
}, | ||
}, | ||
{ | ||
id: '2', | ||
attributes: { | ||
isSelected: false, | ||
name: 'Title name2', | ||
managedCoverages: [{ | ||
beginCoverage: '2017-08-01', | ||
endCoverage: '2017-08-01', | ||
}], | ||
customCoverages: [], | ||
managedEmbargoPeriod: { | ||
embargoValue: 0, | ||
}, | ||
publicationType: 'book', | ||
}, | ||
}, | ||
]; | ||
|
||
const mockOnFetchPackageTitles = jest.fn(); | ||
const mockHistoryPush = jest.fn(); | ||
|
||
const history = createMemoryHistory(); | ||
history.push = mockHistoryPush; | ||
|
||
const renderPackageTitleList = (props = {}) => render( | ||
<Harness | ||
history={history} | ||
> | ||
<PackageTitleList | ||
records={records} | ||
isLoading={false} | ||
totalResults={3} | ||
page={1} | ||
count={2} | ||
onFetchPackageTitles={mockOnFetchPackageTitles} | ||
{...props} | ||
/> | ||
</Harness> | ||
); | ||
|
||
const axe = getAxe(); | ||
|
||
describe('Given PackageTitleList', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should have no a11y issues', async () => { | ||
const { container } = renderPackageTitleList(); | ||
|
||
const a11yResults = await axe.run(container); | ||
|
||
expect(a11yResults.violations.length).toEqual(0); | ||
}); | ||
|
||
it('should display the correct columns', () => { | ||
const { getByText } = renderPackageTitleList(); | ||
|
||
expect(getByText('ui-eholdings.titlesList.status')).toBeDefined(); | ||
expect(getByText('ui-eholdings.titlesList.title')).toBeDefined(); | ||
expect(getByText('ui-eholdings.titlesList.managedCoverage')).toBeDefined(); | ||
expect(getByText('ui-eholdings.titlesList.customCoverage')).toBeDefined(); | ||
expect(getByText('ui-eholdings.titlesList.managedEmbargo')).toBeDefined(); | ||
}); | ||
|
||
it('should call onFetchPackageTitles when fetching more data', async () => { | ||
const { getByRole } = renderPackageTitleList(); | ||
|
||
await userEvent.click(getByRole('button', { name: 'stripes-components.next' })); | ||
|
||
expect(mockOnFetchPackageTitles).toHaveBeenCalledWith(2); | ||
}); | ||
|
||
describe('when clicking on the title link', () => { | ||
it('should set location.state.eholdings to true', async () => { | ||
const { getByText } = renderPackageTitleList(); | ||
|
||
await userEvent.click(getByText('Title name1')); | ||
|
||
expect(mockHistoryPush).toHaveBeenCalledWith({ | ||
pathname: '/eholdings/resources/1', | ||
state: { | ||
eholdings: true, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should display records correctly', () => { | ||
const { getByText } = renderPackageTitleList(); | ||
|
||
expect(getByText('ui-eholdings.selected')).toBeDefined(); | ||
expect(getByText('Title name1')).toBeDefined(); | ||
expect(getByText('1/1/2005 - 12/31/2005')).toBeDefined(); | ||
expect(getByText('1/9/2025 - 1/1/2026, 1/7/2025 - 1/8/2025')).toBeDefined(); | ||
expect(getByText('ui-eholdings.resource.embargoUnit.Days')).toBeDefined(); | ||
|
||
expect(getByText('ui-eholdings.notSelected')).toBeDefined(); | ||
expect(getByText('Title name2')).toBeDefined(); | ||
expect(getByText('8/1/2017 - 8/1/2017')).toBeDefined(); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
src/components/package/show/components/PackageTitleList/index.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 @@ | ||
export * from './PackageTitleList'; |
Oops, something went wrong.