Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression where selected parent node is not passed to addEdit location form #1273

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});
Loading