Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki committed Nov 10, 2023
1 parent 5a32d4f commit 2c4dc58
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
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 2c4dc58

Please sign in to comment.