-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcf8ba5
commit 4f5dc35
Showing
3 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...tion-management/src/components/AllLocationListFlat/tests/__snapshots__/eusm.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"`; |
109 changes: 109 additions & 0 deletions
109
packages/fhir-location-management/src/components/AllLocationListFlat/tests/eusm.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters