-
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.
UIORGS-355 Display all versions in change log in fourth pane (#655)
* UIORGS-355 Display all versions in change log in fourth pane * add unit tests * Map labels with the schema fields * ignore sonar alert * UIORGS-355 update * UIORGS-355 Add new required okapi interface
- Loading branch information
1 parent
53cecbb
commit 9a29cc4
Showing
17 changed files
with
555 additions
and
2 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
111 changes: 111 additions & 0 deletions
111
src/Organizations/OrganizationVersion/OrganizationVersion.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,111 @@ | ||
import get from 'lodash/get'; | ||
import { | ||
memo, | ||
useCallback, | ||
useMemo, | ||
} from 'react'; | ||
import ReactRouterPropTypes from 'react-router-prop-types'; | ||
|
||
import { | ||
useOrganization, | ||
VersionHistoryPane, | ||
VersionView, | ||
VersionViewContextProvider, | ||
} from '@folio/stripes-acq-components'; | ||
import { TitleManager } from '@folio/stripes/core'; | ||
|
||
import { | ||
ORGANIZATION_VERSIONS_VIEW_ROUTE, | ||
ORGANIZATIONS_ROUTE, | ||
VIEW_ORG_DETAILS, | ||
} from '../../common/constants'; | ||
import { HIDDEN_FIELDS_FOR_ORGANIZATION_VERSION_HISTORY } from '../constants'; | ||
import { getOrganizationFieldsLabelMap } from './getOrganizationFieldsLabelMap'; | ||
import { useOrganizationVersions } from './hooks'; | ||
|
||
const OrganizationVersion = ({ | ||
history, | ||
location, | ||
match, | ||
}) => { | ||
const { id: organizationId, versionId } = match.params; | ||
const snapshotPath = 'organizationSnapshot.map'; | ||
|
||
const { | ||
isLoading: isOrganizationLoading, | ||
organization, | ||
} = useOrganization(organizationId); | ||
|
||
const onHistoryClose = useCallback(() => history.push({ | ||
pathname: `${VIEW_ORG_DETAILS}${organizationId}`, | ||
search: location.search, | ||
}), [history, location.search, organizationId]); | ||
|
||
const onVersionClose = useCallback(() => history.push({ | ||
pathname: ORGANIZATIONS_ROUTE, | ||
search: location.search, | ||
}), [history, location.search]); | ||
|
||
const onSelectVersion = useCallback((_versionId) => { | ||
history.push({ | ||
pathname: `${ORGANIZATION_VERSIONS_VIEW_ROUTE.replace(':id', organizationId)}/${_versionId}`, | ||
search: location.search, | ||
}); | ||
}, [history, location.search, organizationId]); | ||
|
||
const { | ||
versions, | ||
isLoading: isHistoryLoading, | ||
} = useOrganizationVersions(organizationId, { | ||
onSuccess: ({ organizationAuditEvents }) => { | ||
if (!versionId && organizationAuditEvents[0]?.id) onSelectVersion(organizationAuditEvents[0].id); | ||
}, | ||
}); | ||
|
||
const isVersionLoading = ( | ||
isOrganizationLoading || isHistoryLoading | ||
); | ||
|
||
const labelsMap = useMemo(() => getOrganizationFieldsLabelMap(), []); | ||
|
||
return ( | ||
<VersionViewContextProvider | ||
snapshotPath={snapshotPath} | ||
versions={versions} | ||
versionId={versionId} | ||
> | ||
<TitleManager record={organization?.name} /> | ||
<VersionView | ||
id="organization" | ||
dismissible | ||
isLoading={isVersionLoading} | ||
onClose={onVersionClose} | ||
paneTitle={organization?.name} | ||
tags={get(organization, 'tags.tagList', [])} | ||
versionId={versionId} | ||
> | ||
{/* TODO: https://folio-org.atlassian.net/browse/UIORGS-356 */} | ||
</VersionView> | ||
|
||
<VersionHistoryPane | ||
currentVersion={versionId} | ||
id="organization" | ||
isLoading={isHistoryLoading} | ||
onClose={onHistoryClose} | ||
onSelectVersion={onSelectVersion} | ||
snapshotPath={snapshotPath} | ||
labelsMap={labelsMap} | ||
versions={versions} | ||
hiddenFields={HIDDEN_FIELDS_FOR_ORGANIZATION_VERSION_HISTORY} | ||
/> | ||
</VersionViewContextProvider> | ||
); | ||
}; | ||
|
||
OrganizationVersion.propTypes = { | ||
history: ReactRouterPropTypes.history, | ||
location: ReactRouterPropTypes.location, | ||
match: ReactRouterPropTypes.match, | ||
}; | ||
|
||
export default memo(OrganizationVersion); |
141 changes: 141 additions & 0 deletions
141
src/Organizations/OrganizationVersion/OrganizationVersion.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,141 @@ | ||
import { | ||
QueryClient, | ||
QueryClientProvider, | ||
} from 'react-query'; | ||
import { | ||
MemoryRouter, | ||
Route, | ||
Switch, | ||
withRouter, | ||
} from 'react-router-dom'; | ||
|
||
import { | ||
render, | ||
screen, | ||
} from '@folio/jest-config-stripes/testing-library/react'; | ||
import user from '@folio/jest-config-stripes/testing-library/user-event'; | ||
import { useOkapiKy } from '@folio/stripes/core'; | ||
import { | ||
AUDIT_ACQ_EVENTS_API, | ||
useOrganization, | ||
} from '@folio/stripes-acq-components'; | ||
|
||
import { | ||
organization, | ||
organizationAuditEvent, | ||
} from 'fixtures'; | ||
import { ORGANIZATION_VERSIONS_VIEW_ROUTE } from '../../common/constants'; | ||
import OrganizationVersion from './OrganizationVersion'; | ||
|
||
jest.mock('@folio/stripes-acq-components', () => ({ | ||
...jest.requireActual('@folio/stripes-acq-components'), | ||
useOrganization: jest.fn(() => ({})), | ||
})); | ||
|
||
const { organizationSnapshot, ...auditEvent } = organizationAuditEvent; | ||
|
||
const latestSnapshot = { | ||
...organizationSnapshot, | ||
edition: 'Second edition', | ||
}; | ||
const originalSnapshot = { ...organizationSnapshot }; | ||
|
||
const versions = [ | ||
{ | ||
...auditEvent, | ||
id: 'testAuditEventId', | ||
organizationSnapshot: { map: latestSnapshot }, | ||
}, | ||
{ | ||
...auditEvent, | ||
organizationSnapshot: { map: originalSnapshot }, | ||
}, | ||
]; | ||
|
||
const kyMock = { | ||
get: jest.fn((url) => ({ | ||
json: async () => { | ||
const result = {}; | ||
|
||
if (url.startsWith(`${AUDIT_ACQ_EVENTS_API}/organization/`)) { | ||
result.organizationAuditEvents = versions; | ||
} | ||
|
||
return Promise.resolve({ | ||
isLoading: false, | ||
...result, | ||
}); | ||
}, | ||
})), | ||
}; | ||
|
||
const queryClient = new QueryClient(); | ||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
<MemoryRouter | ||
initialEntries={[{ | ||
pathname: ORGANIZATION_VERSIONS_VIEW_ROUTE.replace(':id', organization.id), | ||
}]} | ||
> | ||
{children} | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
); | ||
|
||
const Component = withRouter(OrganizationVersion); | ||
const mockDefaultContent = 'Hello world'; | ||
|
||
const renderOrganizationVersion = (props = {}) => render( | ||
<Switch> | ||
<Route | ||
path={ORGANIZATION_VERSIONS_VIEW_ROUTE} | ||
render={() => ( | ||
<Component | ||
{...props} | ||
/> | ||
)} | ||
/> | ||
<Route | ||
render={() => ( | ||
<div>{mockDefaultContent}</div> | ||
)} | ||
/> | ||
</Switch>, | ||
{ wrapper }, | ||
); | ||
|
||
describe('OrganizationVersion', () => { | ||
beforeEach(() => { | ||
useOkapiKy.mockReturnValue(kyMock); | ||
useOrganization.mockReturnValue({ | ||
isLoading: false, | ||
organization, | ||
}); | ||
}); | ||
|
||
it('should close version view when \'Version close\' button was clicked', async () => { | ||
renderOrganizationVersion(); | ||
|
||
await screen.findAllByRole('button', { name: 'stripes-acq-components.versionHistory.card.select.tooltip' }) | ||
.then(async ([selectVersionBtn]) => user.click(selectVersionBtn)); | ||
|
||
await screen.findAllByRole('button', { name: 'stripes-components.closeItem' }) | ||
.then(async ([closeVersionBtn]) => user.click(closeVersionBtn)); | ||
|
||
expect(screen.queryByText(organization.name)).not.toBeInTheDocument(); | ||
expect(screen.getByText(mockDefaultContent)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should close version view when \'History close\' button was clicked', async () => { | ||
renderOrganizationVersion(); | ||
|
||
await screen.findAllByRole('button', { name: 'stripes-acq-components.versionHistory.card.select.tooltip' }) | ||
.then(async ([selectVersionBtn]) => user.click(selectVersionBtn)); | ||
|
||
await screen.findAllByRole('button', { name: 'stripes-components.closeItem' }) | ||
.then(async ([_, closeHistoryBtn]) => user.click(closeHistoryBtn)); | ||
|
||
expect(screen.queryByText(organization.name)).not.toBeInTheDocument(); | ||
expect(screen.getByText(mockDefaultContent)).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.