diff --git a/packages/fhir-location-management/src/components/LocationUnitList/index.tsx b/packages/fhir-location-management/src/components/LocationUnitList/index.tsx index 49f55d08f..94888be13 100644 --- a/packages/fhir-location-management/src/components/LocationUnitList/index.tsx +++ b/packages/fhir-location-management/src/components/LocationUnitList/index.tsx @@ -147,8 +147,9 @@ export const LocationUnitList: React.FC = (props: Locatio const queryParams = { parentId: selectedNode.model.nodeId }; const searchString = new URLSearchParams(queryParams).toString(); history.push(`${URL_LOCATION_UNIT_ADD}?${searchString}`); + } else { + history.push(URL_LOCATION_UNIT_ADD); } - history.push(URL_LOCATION_UNIT_ADD); }} > diff --git a/packages/fhir-location-management/src/components/LocationUnitList/tests/__snapshots__/index.test.tsx.snap b/packages/fhir-location-management/src/components/LocationUnitList/tests/__snapshots__/index.test.tsx.snap index ac0d64230..fe94a6320 100644 --- a/packages/fhir-location-management/src/components/LocationUnitList/tests/__snapshots__/index.test.tsx.snap +++ b/packages/fhir-location-management/src/components/LocationUnitList/tests/__snapshots__/index.test.tsx.snap @@ -1,5 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`location-management/src/components/LocationUnitList Passes selected node as the parent location when adding location clicked: user defined root location 1`] = ` + + Ona Office Sub Location + +`; + exports[`location-management/src/components/LocationUnitList works correctly: first row containing ona office loc details 1`] = ` { }); await waitForElementToBeRemoved(screen.getByText(/Refreshing data/i)); }); + + it('Passes selected node as the parent location when adding location clicked', async () => { + nock(props.fhirBaseURL) + .get(`/${locationResourceType}/_search`) + .query({ _summary: 'count' }) + .reply(200, { total: 1000 }); + + nock(props.fhirBaseURL) + .get(`/${locationResourceType}/_search`) + .query({ _count: 1000 }) + .reply(200, locationSData) + .persist(); + + render(); + + await waitForElementToBeRemoved(document.querySelector('.ant-spin')); + + expect(screen.getByText(/Location Unit Management/)).toBeInTheDocument(); + + // initially show single user defined root location + const treeSection = document.querySelector('.ant-tree') as HTMLElement; + const firstRootLoc = within(treeSection).getByTitle(/Ona Office Sub Location/); + expect(firstRootLoc).toMatchSnapshot('user defined root location'); + + // click/select this first root location + userEvent.click(firstRootLoc); + + // then click add location + const addLocationBtn = screen.getByText(/Add Location Unit/); + userEvent.click(addLocationBtn); + + // check where we redirected to + expect(history.location.search).toEqual('?parentId=Location%2F303'); + }); });