-
Notifications
You must be signed in to change notification settings - Fork 20
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
Showing
4 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/fhir-location-management/src/components/EditLink/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { useMls } from '../../mls'; | ||
import { URL_LOCATION_UNIT_EDIT, URL_SERVICE_POINT_ADD_EDIT } from '../../constants'; | ||
import { ILocation } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/ILocation'; | ||
|
||
interface EditLinkProps { | ||
location: ILocation; | ||
} | ||
|
||
const EditLink: React.FC<EditLinkProps> = ({ location }) => { | ||
const { t } = useMls(); | ||
const { id, physicalType } = location; | ||
const isBuilding = physicalType?.coding?.[0].code === 'bu'; | ||
|
||
return ( | ||
<Link | ||
to={`${isBuilding ? URL_SERVICE_POINT_ADD_EDIT : URL_LOCATION_UNIT_EDIT}/${id}`} | ||
className="m-0 p-1" | ||
> | ||
{t('Edit')} | ||
</Link> | ||
); | ||
}; | ||
|
||
export { EditLink }; |
36 changes: 36 additions & 0 deletions
36
packages/fhir-location-management/src/components/EditLink/tests/fixtures.ts
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,36 @@ | ||
import { ILocation } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/ILocation'; | ||
|
||
export const Location: ILocation = { | ||
resourceType: 'Location', | ||
id: '303', | ||
meta: { | ||
versionId: '4', | ||
lastUpdated: '2021-10-14T13:12:22.740+00:00', | ||
source: '#13bbc7f09daa1751', | ||
}, | ||
identifier: [{ use: 'official', value: '93bc9c3d-6321-41b0-9b93-1275d7114e22' }], | ||
status: 'active', | ||
name: 'Yosemite', | ||
description: 'The Sub location', | ||
partOf: { reference: 'Location/2252', display: 'Root FHIR Location' }, | ||
type: [ | ||
{ | ||
coding: [ | ||
{ | ||
system: 'http://terminology.hl7.org/CodeSystem/location-physical-type', | ||
code: 'bu', | ||
display: 'Building', | ||
}, | ||
], | ||
}, | ||
], | ||
physicalType: { | ||
coding: [ | ||
{ | ||
system: 'http://terminology.hl7.org/CodeSystem/location-physical-type', | ||
code: 'bu', | ||
display: 'Building', | ||
}, | ||
], | ||
}, | ||
}; |
51 changes: 51 additions & 0 deletions
51
packages/fhir-location-management/src/components/EditLink/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,51 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { URL_LOCATION_UNIT_EDIT, URL_SERVICE_POINT_ADD_EDIT } from '../../../constants'; | ||
import { EditLink } from '..'; | ||
import { Location } from './fixtures'; | ||
|
||
// Mock the useMls hook | ||
jest.mock('../../mls', () => ({ | ||
useMls: () => ({ t: (key: string) => key }), | ||
})); | ||
|
||
describe('EditLink', () => { | ||
it('renders the correct link for building locations', () => { | ||
const { getByText } = render( | ||
<Router> | ||
<EditLink location={Location} /> | ||
</Router> | ||
); | ||
|
||
const link = getByText('Edit'); | ||
expect(link).toBeInTheDocument(); | ||
expect(link).toHaveAttribute('href', `${URL_SERVICE_POINT_ADD_EDIT}/1`); | ||
}); | ||
|
||
it('renders the correct link for non-building locations', () => { | ||
const location = { | ||
...Location, | ||
physicalType: { | ||
coding: [ | ||
{ | ||
system: 'http://terminology.hl7.org/CodeSystem/location-physical-type', | ||
code: 'jdn', | ||
display: 'Jurisdiction', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const { getByText } = render( | ||
<Router> | ||
<EditLink location={location} /> | ||
</Router> | ||
); | ||
|
||
const link = getByText('Edit'); | ||
expect(link).toBeInTheDocument(); | ||
expect(link).toHaveAttribute('href', `${URL_LOCATION_UNIT_EDIT}/2`); | ||
}); | ||
}); |
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