From f838ec6c46a31bd70afebb9cc8c048bbba532b82 Mon Sep 17 00:00:00 2001 From: EdsonNhancale Date: Wed, 15 Jan 2025 12:02:09 +0200 Subject: [PATCH] test: added unit tests for period (pe) filter functionality in getIframeSrc - 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. --- .../AppItem/__tests__/getIframeSrc.spec.js | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/components/Item/AppItem/__tests__/getIframeSrc.spec.js b/src/components/Item/AppItem/__tests__/getIframeSrc.spec.js index fd85d6037..3807f1dea 100644 --- a/src/components/Item/AppItem/__tests__/getIframeSrc.spec.js +++ b/src/components/Item/AppItem/__tests__/getIframeSrc.spec.js @@ -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); + }); })