diff --git a/CHANGELOG.md b/CHANGELOG.md index d9e47c374..c1c58fd9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [26.9.3](https://github.com/dhis2/analytics/compare/v26.9.2...v26.9.3) (2024-11-22) + + +### Bug Fixes + +* enable ou tree and levels/groups with user orgunits (DHIS2-18066) ([#1702](https://github.com/dhis2/analytics/issues/1702)) ([f58c708](https://github.com/dhis2/analytics/commit/f58c708af214f13147e5c95ede8545fc5c03bc57)) + ## [26.9.2](https://github.com/dhis2/analytics/compare/v26.9.1...v26.9.2) (2024-11-03) diff --git a/package.json b/package.json index 95eaac5e0..cf36c5afd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dhis2/analytics", - "version": "26.9.2", + "version": "26.9.3", "main": "./build/cjs/index.js", "module": "./build/es/index.js", "exports": { diff --git a/src/components/OrgUnitDimension/OrgUnitDimension.js b/src/components/OrgUnitDimension/OrgUnitDimension.js index 5d2d7115a..9ed1078de 100644 --- a/src/components/OrgUnitDimension/OrgUnitDimension.js +++ b/src/components/OrgUnitDimension/OrgUnitDimension.js @@ -51,10 +51,7 @@ const OrgUnitDimension = ({ let result = [...selected] if (checked && DYNAMIC_ORG_UNITS.includes(id)) { - result = [ - ...result.filter((item) => DYNAMIC_ORG_UNITS.includes(item.id)), - { id, displayName }, - ] + result = [...result, { id, displayName }] } else if (checked) { result.push({ id, path, name: displayName }) } else { @@ -236,13 +233,7 @@ const OrgUnitDimension = ({ /> )} -
- DYNAMIC_ORG_UNITS.includes(item.id) - ), - })} - > +
- DYNAMIC_ORG_UNITS.includes(item.id) - ), hidden: hideLevelSelect && hideGroupSelect, })} > diff --git a/src/components/OrgUnitDimension/__tests__/OrgUnitDimension.spec.js b/src/components/OrgUnitDimension/__tests__/OrgUnitDimension.spec.js new file mode 100644 index 000000000..9f85b035b --- /dev/null +++ b/src/components/OrgUnitDimension/__tests__/OrgUnitDimension.spec.js @@ -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() + } + 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: [], + }) + }) +}) diff --git a/src/components/OrgUnitDimension/__tests__/__snapshots__/OrgUnitDimension.spec.js.snap b/src/components/OrgUnitDimension/__tests__/__snapshots__/OrgUnitDimension.spec.js.snap new file mode 100644 index 000000000..1faa60b95 --- /dev/null +++ b/src/components/OrgUnitDimension/__tests__/__snapshots__/OrgUnitDimension.spec.js.snap @@ -0,0 +1,94 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`The OrgUnitDimension component matches the snapshot 1`] = ` +
+
+ + + +
+
+ +
+
+ + +
+
+ + Nothing selected + +
+ +
+
+