Skip to content

Commit

Permalink
Fix regression where selected parent node is not passed to addEdit lo…
Browse files Browse the repository at this point in the history
…cation form (#1273)

* Fix condition of how parentId is passed to Addedit location unit

* Add tests
  • Loading branch information
peterMuriuki authored Nov 10, 2023
1 parent 16893c2 commit 37137eb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ export const LocationUnitList: React.FC<LocationUnitListProps> = (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);
}}
>
<PlusOutlined />
Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
<span
title="Ona Office Sub Location"
>
Ona Office Sub Location
</span>
`;

exports[`location-management/src/components/LocationUnitList works correctly: first row containing ona office loc details 1`] = `
<td
class="ant-table-cell"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { Provider } from 'react-redux';
import { RoleContext } from '@opensrp/rbac';
import { superUserRole } from '@opensrp/react-utils';
import { locationHierarchyResourceType } from '../../../constants';
import { locationResourceType } from '../../../constants';
import { locationSData } from '../../../ducks/tests/fixtures';
import userEvent from '@testing-library/user-event';

const history = createBrowserHistory();

Expand Down Expand Up @@ -202,4 +205,38 @@ describe('location-management/src/components/LocationUnitList', () => {
});
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(<AppWrapper {...props} />);

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');
});
});

0 comments on commit 37137eb

Please sign in to comment.