From b3ff652bae506a2443f2e772d8d0f50faa163860 Mon Sep 17 00:00:00 2001 From: kahummer Date: Thu, 11 Jul 2024 00:58:45 +0300 Subject: [PATCH] Cleanup and add tests --- .../AllLocationListFlat/tests/utils.test.tsx | 1 + .../src/components/EditLink/index.tsx | 6 ++++-- .../components/EditLink/tests/index.test.tsx | 19 ++++++++++++------- .../ViewDetails/LocationDetails/index.tsx | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/fhir-location-management/src/components/AllLocationListFlat/tests/utils.test.tsx b/packages/fhir-location-management/src/components/AllLocationListFlat/tests/utils.test.tsx index 23059794a..adaa71fb1 100644 --- a/packages/fhir-location-management/src/components/AllLocationListFlat/tests/utils.test.tsx +++ b/packages/fhir-location-management/src/components/AllLocationListFlat/tests/utils.test.tsx @@ -19,6 +19,7 @@ describe('location-management/src/components/AllLocationListFlat/utils', () => { parent: '', status: 'active', type: 'Building', + location: flatLocations.entry[0].resource, }, ]); }); diff --git a/packages/fhir-location-management/src/components/EditLink/index.tsx b/packages/fhir-location-management/src/components/EditLink/index.tsx index d810f099a..8227a6b09 100644 --- a/packages/fhir-location-management/src/components/EditLink/index.tsx +++ b/packages/fhir-location-management/src/components/EditLink/index.tsx @@ -10,9 +10,11 @@ import { ILocation } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/ILocation'; interface EditLinkProps { location: ILocation; + editLinkText?: string; } -const EditLink: React.FC = ({ location }) => { +const EditLink: React.FC = (props) => { + const { location, editLinkText } = props; const { t } = useMls(); const { id, physicalType } = location; const isBuilding = physicalType?.coding?.[0].code === 'bu'; @@ -29,7 +31,7 @@ const EditLink: React.FC = ({ location }) => { } className="m-0 p-1" > - {t('Edit')} + {t(editLinkText ? editLinkText : 'Edit')} ); }; diff --git a/packages/fhir-location-management/src/components/EditLink/tests/index.test.tsx b/packages/fhir-location-management/src/components/EditLink/tests/index.test.tsx index dad589973..a4c134454 100644 --- a/packages/fhir-location-management/src/components/EditLink/tests/index.test.tsx +++ b/packages/fhir-location-management/src/components/EditLink/tests/index.test.tsx @@ -6,11 +6,6 @@ import { URL_LOCATION_UNIT_EDIT, URL_SERVICE_POINT_ADD_EDIT } from '../../../con 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( @@ -21,7 +16,7 @@ describe('EditLink', () => { const link = getByText('Edit'); expect(link).toBeInTheDocument(); - expect(link).toHaveAttribute('href', `${URL_SERVICE_POINT_ADD_EDIT}/1`); + expect(link).toHaveAttribute('href', `${URL_SERVICE_POINT_ADD_EDIT}/303`); }); it('renders the correct link for non-building locations', () => { @@ -46,6 +41,16 @@ describe('EditLink', () => { const link = getByText('Edit'); expect(link).toBeInTheDocument(); - expect(link).toHaveAttribute('href', `${URL_LOCATION_UNIT_EDIT}/2`); + expect(link).toHaveAttribute('href', `${URL_LOCATION_UNIT_EDIT}/303?back_to=%2F`); + }); + it('renders custom text link', () => { + const { getByText } = render( + + + + ); + + const link = getByText('Edit details'); + expect(link).toBeInTheDocument(); }); }); diff --git a/packages/fhir-location-management/src/components/ViewDetails/LocationDetails/index.tsx b/packages/fhir-location-management/src/components/ViewDetails/LocationDetails/index.tsx index 5eb957406..dbef934cd 100644 --- a/packages/fhir-location-management/src/components/ViewDetails/LocationDetails/index.tsx +++ b/packages/fhir-location-management/src/components/ViewDetails/LocationDetails/index.tsx @@ -69,7 +69,7 @@ export const LocationDetails = ({ location }: { location: ILocation }) => { headerRightData={dateCreatedKeyPairing} headerActions={ - + } bodyData={otherDetailsMap}