Skip to content

Commit

Permalink
test: added unit tests for period (pe) filter functionality in getIfr…
Browse files Browse the repository at this point in the history
…ameSrc

- Added tests to validate the behavior of the period (pe) filter with single and multiple values. - Ensured proper handling when both pe and ou filters are applied together. - Included a test to confirm pe filter is omitted when empty. - Verified the generated iframeSrc matches the expected URL for all scenarios.
  • Loading branch information
EdsonNhancale committed Jan 15, 2025
1 parent 229d25e commit f838ec6
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/components/Item/AppItem/__tests__/getIframeSrc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,64 @@ describe('getIframeSrc', () => {
`${expectedSrc}&userOrgUnit=USER_ORGUNIT_CHILDREN,USER_ORGUNIT_GRANDCHILDREN,USER_ORGUNIT`
)
})

it('only period filter with a single value', () => {
const peFilter = [{ id: 'LAST_MONTH' }];

const src = getIframeSrc(appDetails, dashboardItem, { pe: peFilter });
expect(src).toEqual(`${expectedSrc}&period=LAST_MONTH`);
});

it('only period filter with multiple values', () => {
const peFilter = [
{ id: 'LAST_MONTH' },
{ id: 'LAST_3_MONTHS' },
];

const src = getIframeSrc(appDetails, dashboardItem, { pe: peFilter });
expect(src).toEqual(`${expectedSrc}&period=LAST_MONTH,LAST_3_MONTHS`);
});

it('period filter and org unit filter', () => {
const peFilter = [{ id: 'LAST_MONTH' }];
const ouFilter = [
{
id: 'fdc6uOvgoji',
path: '/ImspTQPwCqd/fdc6uOvgoji',
name: 'Bombali',
},
];

const src = getIframeSrc(appDetails, dashboardItem, { pe: peFilter, ou: ouFilter });
expect(src).toEqual(`${expectedSrc}&userOrgUnit=fdc6uOvgoji&period=LAST_MONTH`);
});

it('period filter with multiple values and org unit filter', () => {
const peFilter = [
{ id: 'LAST_MONTH' },
{ id: 'LAST_3_MONTHS' },
];
const ouFilter = [
{
id: 'fdc6uOvgoji',
path: '/ImspTQPwCqd/fdc6uOvgoji',
name: 'Bombali',
},
{
id: 'lc3eMKXaEfw',
path: '/ImspTQPwCqd/lc3eMKXaEfw',
name: 'Bonthe',
},
];

const src = getIframeSrc(appDetails, dashboardItem, { pe: peFilter, ou: ouFilter });
expect(src).toEqual(`${expectedSrc}&userOrgUnit=fdc6uOvgoji,lc3eMKXaEfw&period=LAST_MONTH,LAST_3_MONTHS`);
});

it('empty pe filter', () => {
const peFilter = [];

const src = getIframeSrc(appDetails, dashboardItem, { pe: peFilter });
expect(src).toEqual(expectedSrc);
});
})

0 comments on commit f838ec6

Please sign in to comment.