Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki committed Mar 25, 2024
1 parent fcf8ba5 commit 4f5dc35
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Show data as expected: table data 1`] = `"Good Health Clinic"`;

exports[`Show data as expected: table data 2`] = `"Building"`;

exports[`Show data as expected: table data 3`] = `"active"`;

exports[`Show data as expected: table data 4`] = `""`;

exports[`Show data as expected: table data 5`] = `"Edit"`;

exports[`Show data as expected: table header 1`] = `"NameTypeStatusParentActions"`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { EusmLocationListFlat } from '..';
import React from 'react';
import { store } from '@opensrp/store';
import { authenticateUser } from '@onaio/session-reducer';
import { QueryClientProvider, QueryClient } from 'react-query';
import nock from 'nock';
import { render, cleanup, waitForElementToBeRemoved, screen } from '@testing-library/react';
import { Router } from 'react-router';
import { createBrowserHistory } from 'history';
import { flatLocations } from '../../../ducks/tests/fixtures';
import { Provider } from 'react-redux';
import { RoleContext } from '@opensrp/rbac';
import { superUserRole } from '@opensrp/react-utils';
import { locationResourceType } from '../../../constants';
import { eusmPhysicalLocationsFilterParams } from '../utils';

const history = createBrowserHistory();

const props = {
fhirBaseURL: 'http://test.server.org',
};

jest.mock('fhirclient', () => {
return jest.requireActual('fhirclient/lib/entry/browser');
});

jest.setTimeout(10000);

const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
cacheTime: 0,
},
},
});

const AppWrapper = (props) => {
return (
<Provider store={store}>
<RoleContext.Provider value={superUserRole}>
<Router history={history}>
<QueryClientProvider client={queryClient}>
<EusmLocationListFlat {...props} />
</QueryClientProvider>
</Router>
</RoleContext.Provider>
</Provider>
);
};

beforeAll(() => {
nock.disableNetConnect();
store.dispatch(
authenticateUser(
true,
{
email: '[email protected]',
name: 'Bobbie',
username: 'RobertBaratheon',
},
{ api_token: 'hunter2', oAuth2Data: { access_token: 'hunter2', state: 'abcde' } }
)
);
});

afterEach(() => {
nock.cleanAll();
cleanup();
});

afterAll(() => {
nock.enableNetConnect();
});

test('Show data as expected', async () => {
// __summary: 'count'
nock(props.fhirBaseURL)
.get(`/${locationResourceType}/_search`)
.query({
_total: 'accurate',
_include: 'Location:partof',
_getpagesoffset: 0,
_count: 20,
...eusmPhysicalLocationsFilterParams,
})
.reply(200, flatLocations);

render(<AppWrapper {...props} />);
await waitForElementToBeRemoved(document.querySelector('.ant-spin'));
expect(screen.getByText(/Service points/i)).toBeInTheDocument();

// check table contnets
const table = document.querySelector('table');
// check table headers
expect(table?.querySelectorAll('thead tr')).toHaveLength(1);
const header = table?.querySelectorAll('thead tr');
header?.forEach((td) => {
expect(td.textContent).toMatchSnapshot('table header');
});
// check table body
expect(table?.querySelectorAll('tbody tr')).toHaveLength(1);
const firstRowTd = table?.querySelectorAll('tbody tr:nth-child(1) td');
firstRowTd?.forEach((td) => {
expect(td.textContent).toMatchSnapshot('table data');
});

expect(nock.isDone()).toBeTruthy();
});
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('location-management/src/components/AllLocationListFlat', () => {

render(<AppWrapper {...props} />);
await waitForElementToBeRemoved(document.querySelector('.ant-spin'));
expect(screen.getByText(/All Locations/)).toBeInTheDocument();
expect(screen.getByText(/Locations/)).toBeInTheDocument();
expect(screen.getByTitle(/Empty raw svg icon/)).toBeInTheDocument();
expect(
screen.getByText(/No data available to display, you can start adding data now/)
Expand All @@ -128,7 +128,7 @@ describe('location-management/src/components/AllLocationListFlat', () => {

render(<AppWrapper {...props} />);
await waitForElementToBeRemoved(document.querySelector('.ant-spin'));
expect(screen.getByText(/All Locations/)).toBeInTheDocument();
expect(screen.getByText(/Locations/)).toBeInTheDocument();

// check table contnets
const table = document.querySelector('table');
Expand Down

0 comments on commit 4f5dc35

Please sign in to comment.