-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parse the ou filter correctly for all ou types (#2691)
Fixes DHIS2-14544 If path exists, then parse it, otherwise use id (which will be the case for groups, levels and USER_ORGUNITS)
- Loading branch information
1 parent
87723a4
commit 529bc5b
Showing
9 changed files
with
260 additions
and
55 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
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
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,25 @@ | ||
Cypress.Commands.add('getByDataTest', (selector, ...args) => | ||
cy.get(`[data-test=${selector}]`, ...args) | ||
) | ||
Cypress.Commands.add( | ||
'findByDataTest', | ||
{ | ||
prevSubject: true, | ||
}, | ||
(subject, selector, ...args) => | ||
cy.wrap(subject).find(`[data-test="${selector}"]`, ...args) | ||
) | ||
|
||
Cypress.Commands.add( | ||
'containsExact', | ||
{ | ||
prevSubject: 'optional', | ||
}, | ||
(subject, selector) => | ||
cy.wrap(subject).contains( | ||
new RegExp( | ||
`^${selector.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')}$`, //eslint-disable-line no-useless-escape | ||
'gm' | ||
) | ||
) | ||
) |
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
106 changes: 106 additions & 0 deletions
106
src/components/Item/AppItem/__tests__/getIframeSrc.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,106 @@ | ||
import { getIframeSrc } from '../getIframeSrc.js' | ||
|
||
const appDetails = { launchUrl: 'debug/dev' } | ||
const dashboardItem = { id: 'rainbowdashitem' } | ||
const expectedSrc = `${appDetails.launchUrl}?dashboardItemId=${dashboardItem.id}` | ||
|
||
describe('getIframeSrc', () => { | ||
it('no ou filter', () => { | ||
const ouFilter = [] | ||
|
||
const src = getIframeSrc(appDetails, dashboardItem, { ou: ouFilter }) | ||
expect(src).toEqual(expectedSrc) | ||
}) | ||
|
||
it('org units chosen from the tree', () => { | ||
const ouFilter = [ | ||
{ | ||
id: 'fdc6uOvgoji', | ||
path: '/ImspTQPwCqd/fdc6uOvgoji', | ||
name: 'Bombali', | ||
}, | ||
{ | ||
id: 'lc3eMKXaEfw', | ||
path: '/ImspTQPwCqd/lc3eMKXaEfw', | ||
name: 'Bonthe', | ||
}, | ||
] | ||
|
||
const src = getIframeSrc(appDetails, dashboardItem, { ou: ouFilter }) | ||
expect(src).toEqual( | ||
`${expectedSrc}&userOrgUnit=fdc6uOvgoji,lc3eMKXaEfw` | ||
) | ||
}) | ||
|
||
it('org unit group and org unit from tree', () => { | ||
const ouFilter = [ | ||
{ | ||
id: 'OU_GROUP-b0EsAxm8Nge', | ||
name: 'Western Area', | ||
}, | ||
{ | ||
id: 'lc3eMKXaEfw', | ||
path: '/ImspTQPwCqd/lc3eMKXaEfw', | ||
name: 'Bonthe', | ||
}, | ||
] | ||
|
||
const src = getIframeSrc(appDetails, dashboardItem, { ou: ouFilter }) | ||
expect(src).toEqual( | ||
`${expectedSrc}&userOrgUnit=OU_GROUP-b0EsAxm8Nge,lc3eMKXaEfw` | ||
) | ||
}) | ||
|
||
it('org unit level and org unit from tree', () => { | ||
const ouFilter = [ | ||
{ | ||
id: 'LEVEL-m9lBJogzE95', | ||
name: 'Facility', | ||
}, | ||
{ | ||
id: 'fdc6uOvgoji', | ||
path: '/ImspTQPwCqd/fdc6uOvgoji', | ||
name: 'Bombali', | ||
}, | ||
] | ||
|
||
const src = getIframeSrc(appDetails, dashboardItem, { ou: ouFilter }) | ||
expect(src).toEqual( | ||
`${expectedSrc}&userOrgUnit=LEVEL-m9lBJogzE95,fdc6uOvgoji` | ||
) | ||
}) | ||
|
||
it('user org unit', () => { | ||
const ouFilter = [ | ||
{ | ||
id: 'USER_ORGUNIT', | ||
displayName: 'User organisation unit', | ||
}, | ||
] | ||
|
||
const src = getIframeSrc(appDetails, dashboardItem, { ou: ouFilter }) | ||
expect(src).toEqual(`${expectedSrc}&userOrgUnit=USER_ORGUNIT`) | ||
}) | ||
|
||
it('all user org units', () => { | ||
const ouFilter = [ | ||
{ | ||
id: 'USER_ORGUNIT_CHILDREN', | ||
displayName: 'User sub-units', | ||
}, | ||
{ | ||
id: 'USER_ORGUNIT_GRANDCHILDREN', | ||
displayName: 'User sub-x2-units', | ||
}, | ||
{ | ||
id: 'USER_ORGUNIT', | ||
displayName: 'User organisation unit', | ||
}, | ||
] | ||
|
||
const src = getIframeSrc(appDetails, dashboardItem, { ou: ouFilter }) | ||
expect(src).toEqual( | ||
`${expectedSrc}&userOrgUnit=USER_ORGUNIT_CHILDREN,USER_ORGUNIT_GRANDCHILDREN,USER_ORGUNIT` | ||
) | ||
}) | ||
}) |
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,15 @@ | ||
import { FILTER_ORG_UNIT } from '../../../actions/itemFilters.js' | ||
|
||
export const getIframeSrc = (appDetails, item, itemFilters) => { | ||
let iframeSrc = `${appDetails.launchUrl}?dashboardItemId=${item.id}` | ||
|
||
if (itemFilters[FILTER_ORG_UNIT] && itemFilters[FILTER_ORG_UNIT].length) { | ||
const ouIds = itemFilters[FILTER_ORG_UNIT].map(({ id, path }) => | ||
path ? path.split('/').slice(-1)[0] : id | ||
) | ||
|
||
iframeSrc += `&userOrgUnit=${ouIds.join(',')}` | ||
} | ||
|
||
return iframeSrc | ||
} |