-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add org unit dimension component test
- Loading branch information
1 parent
6e62152
commit aacb0f7
Showing
2 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/components/OrgUnitDimension/__tests__/OrgUnitDimension.spec.js
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,76 @@ | ||
import { shallow } from 'enzyme' | ||
import React from 'react' | ||
import OrgUnitDimension from '../OrgUnitDimension.js' | ||
|
||
jest.mock('@dhis2/app-runtime', () => ({ | ||
useDataEngine: () => ({ | ||
query: jest.fn(), | ||
}), | ||
})) | ||
|
||
jest.mock('../../../api/organisationUnits.js', () => ({ | ||
apiFetchOrganisationUnitGroups: jest.fn().mockResolvedValue([]), | ||
apiFetchOrganisationUnitLevels: jest.fn().mockResolvedValue([]), | ||
})) | ||
|
||
jest.mock('../../../locales/index.js', () => ({ | ||
t: (key) => key, | ||
})) | ||
|
||
afterEach(jest.clearAllMocks) | ||
|
||
describe('The OrgUnitDimension component', () => { | ||
let props | ||
let shallowOrgUnitDimension | ||
|
||
const getWrapper = () => { | ||
if (!shallowOrgUnitDimension) { | ||
shallowOrgUnitDimension = shallow(<OrgUnitDimension {...props} />) | ||
} | ||
return shallowOrgUnitDimension | ||
} | ||
|
||
beforeEach(() => { | ||
props = { | ||
roots: [], | ||
selected: [], | ||
onSelect: jest.fn(), | ||
hideGroupSelect: false, | ||
hideLevelSelect: false, | ||
hideUserOrgUnits: false, | ||
warning: '', | ||
} | ||
shallowOrgUnitDimension = undefined | ||
}) | ||
|
||
it('matches the snapshot', () => { | ||
const wrapper = getWrapper() | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
it('calls onSelect when an organisation unit is selected', () => { | ||
const wrapper = getWrapper() | ||
const orgUnitTree = wrapper.find('OrganisationUnitTree') | ||
const testOrgUnit = { | ||
id: 'testId', | ||
path: '/testPath', | ||
displayName: 'Test Org Unit', | ||
checked: true, | ||
} | ||
orgUnitTree.props().onChange(testOrgUnit) | ||
expect(props.onSelect).toHaveBeenCalledWith({ | ||
dimensionId: 'ou', | ||
items: [{ id: 'testId', path: '/testPath', name: 'Test Org Unit' }], | ||
}) | ||
}) | ||
|
||
it('calls onSelect with an empty array when selection is cleared', () => { | ||
const wrapper = getWrapper() | ||
const deselectButton = wrapper.find('Button[onClick]') | ||
deselectButton.simulate('click') | ||
expect(props.onSelect).toHaveBeenCalledWith({ | ||
dimensionId: 'ou', | ||
items: [], | ||
}) | ||
}) | ||
}) |
94 changes: 94 additions & 0 deletions
94
src/components/OrgUnitDimension/__tests__/__snapshots__/OrgUnitDimension.spec.js.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,94 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`The OrgUnitDimension component matches the snapshot 1`] = ` | ||
<div | ||
className="container" | ||
> | ||
<div | ||
className="userOrgUnitsWrapper" | ||
> | ||
<Checkbox | ||
checked={false} | ||
dataTest="dhis2-uicore-checkbox" | ||
dense={true} | ||
indeterminate={false} | ||
label="User organisation unit" | ||
onChange={[Function]} | ||
/> | ||
<Checkbox | ||
checked={false} | ||
dataTest="dhis2-uicore-checkbox" | ||
dense={true} | ||
indeterminate={false} | ||
label="User sub-units" | ||
onChange={[Function]} | ||
/> | ||
<Checkbox | ||
checked={false} | ||
dataTest="dhis2-uicore-checkbox" | ||
dense={true} | ||
indeterminate={false} | ||
label="User sub-x2-units" | ||
onChange={[Function]} | ||
/> | ||
</div> | ||
<div | ||
className="orgUnitTreeWrapper" | ||
> | ||
<OrganisationUnitTree | ||
dataTest="org-unit-tree" | ||
filter={Array []} | ||
highlighted={Array []} | ||
initiallyExpanded={Array []} | ||
onChange={[Function]} | ||
renderNodeLabel={[Function]} | ||
roots={Array []} | ||
selected={Array []} | ||
/> | ||
</div> | ||
<div | ||
className="selectsWrapper" | ||
> | ||
<MultiSelect | ||
dataTest="org-unit-level-select" | ||
dense={true} | ||
loading={true} | ||
onChange={[Function]} | ||
placeholder="Select a level" | ||
selected={Array []} | ||
/> | ||
<MultiSelect | ||
dataTest="org-unit-group-select" | ||
dense={true} | ||
loading={true} | ||
onChange={[Function]} | ||
placeholder="Select a group" | ||
selected={Array []} | ||
/> | ||
</div> | ||
<div | ||
className="summaryWrapper" | ||
> | ||
<span | ||
className="summaryText" | ||
> | ||
Nothing selected | ||
</span> | ||
<div | ||
className="deselectButton" | ||
> | ||
<Button | ||
dataTest="dhis2-uicore-button" | ||
disabled={true} | ||
onClick={[Function]} | ||
secondary={true} | ||
small={true} | ||
type="button" | ||
> | ||
Deselect all | ||
</Button> | ||
</div> | ||
</div> | ||
<style /> | ||
</div> | ||
`; |