-
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.
fix: enable ou tree and levels/groups with user orgunits (DHIS2-18066) (
#1702) * fix: do not disable tree or levels/groups for user ou * fix: Grab name from 'items' when necessary * test: add unit test for getOuLevelAndGroupText * test: add org unit dimension component test * test: remove unnecessary mocks from OrgUnitDimension test
- Loading branch information
1 parent
90cf3e9
commit f58c708
Showing
6 changed files
with
170 additions
and
15 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
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,59 @@ | ||
import { shallow } from 'enzyme' | ||
import React from 'react' | ||
import OrgUnitDimension from '../OrgUnitDimension.js' | ||
|
||
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> | ||
`; |
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
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
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