Skip to content

Commit

Permalink
Cleanup and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kahummer committed Jul 10, 2024
1 parent 415ab6f commit b3ff652
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('location-management/src/components/AllLocationListFlat/utils', () => {
parent: '',
status: 'active',
type: 'Building',
location: flatLocations.entry[0].resource,
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditLinkProps> = ({ location }) => {
const EditLink: React.FC<EditLinkProps> = (props) => {
const { location, editLinkText } = props;
const { t } = useMls();
const { id, physicalType } = location;
const isBuilding = physicalType?.coding?.[0].code === 'bu';
Expand All @@ -29,7 +31,7 @@ const EditLink: React.FC<EditLinkProps> = ({ location }) => {
}
className="m-0 p-1"
>
{t('Edit')}
{t(editLinkText ? editLinkText : 'Edit')}
</Link>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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', () => {
Expand All @@ -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(
<Router>
<EditLink location={Location} editLinkText="Edit details" />
</Router>
);

const link = getByText('Edit details');
expect(link).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const LocationDetails = ({ location }: { location: ILocation }) => {
headerRightData={dateCreatedKeyPairing}
headerActions={
<RbacCheck permissions={['Location.update']}>
<EditLink location={location} />
<EditLink location={location} editLinkText="Edit details" />
</RbacCheck>
}
bodyData={otherDetailsMap}
Expand Down

0 comments on commit b3ff652

Please sign in to comment.