From c416c4b9013112e9af2a00aca4a976ab5a25a5b1 Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Thu, 19 Nov 2020 15:52:35 +0100 Subject: [PATCH 1/3] fix: add unit tests --- .../__tests__/getVisualizationConfig.spec.js | 71 ++++++++++++++++++- .../getVisualizationConfig.js | 2 +- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/components/Item/VisualizationItem/__tests__/getVisualizationConfig.spec.js b/src/components/Item/VisualizationItem/__tests__/getVisualizationConfig.spec.js index b0079e38f..f4607b509 100644 --- a/src/components/Item/VisualizationItem/__tests__/getVisualizationConfig.spec.js +++ b/src/components/Item/VisualizationItem/__tests__/getVisualizationConfig.spec.js @@ -28,6 +28,32 @@ describe('getVisualizationConfig', () => { expect(actualResult).toEqual(expectedResult) }) + it('returns correct config when switching from CHART to REPORT_TABLE and one row item', () => { + const visConfig = { + id: 'vis1', + type: 'CHART', + [AXIS_ID_COLUMNS]: [{ dimension: DIMENSION_ID_DATA }], + [AXIS_ID_ROWS]: [{ dimension: DIMENSION_ID_PERIOD }], + [AXIS_ID_FILTERS]: [ + { dimension: DIMENSION_ID_ORGUNIT }, + { dimension: 'rainbow' }, + { dimension: 'twilight' }, + ], + } + const actualResult = getVisualizationConfig( + visConfig, + CHART, + REPORT_TABLE + ) + const expectedResult = { + ...visConfig, + id: undefined, + type: 'PIVOT_TABLE', + } + + expect(actualResult).toEqual(expectedResult) + }) + it('returns correct config when switching from CHART to REPORT_TABLE', () => { const visConfig = { id: 'vis1', @@ -54,7 +80,42 @@ describe('getVisualizationConfig', () => { expect(actualResult).toEqual(expectedResult) }) - it('returns correct config when switching from REPORT_TABLE to CHART', () => { + it('returns correct config when switching from REPORT_TABLE to CHART one row item', () => { + const visConfig = { + id: 'vis1', + [AXIS_ID_COLUMNS]: [ + { dimension: DIMENSION_ID_DATA }, + { dimension: 'rainbow' }, + ], + [AXIS_ID_ROWS]: [{ dimension: DIMENSION_ID_PERIOD }], + [AXIS_ID_FILTERS]: [ + { dimension: DIMENSION_ID_ORGUNIT }, + { dimension: 'twilight' }, + ], + } + + const expectedVisConfig = { + id: undefined, + type: 'COLUMN', + [AXIS_ID_COLUMNS]: [{ dimension: DIMENSION_ID_DATA }], + [AXIS_ID_ROWS]: [{ dimension: DIMENSION_ID_PERIOD }], + [AXIS_ID_FILTERS]: [ + { dimension: DIMENSION_ID_ORGUNIT }, + { dimension: 'twilight' }, + { dimension: 'rainbow' }, + ], + } + + const actualResult = getVisualizationConfig( + visConfig, + REPORT_TABLE, + CHART + ) + + expect(actualResult).toEqual(expectedVisConfig) + }) + + it('returns correct config when switching from REPORT_TABLE to CHART >2 row items', () => { const visConfig = { id: 'vis1', [AXIS_ID_COLUMNS]: [ @@ -64,6 +125,7 @@ describe('getVisualizationConfig', () => { [AXIS_ID_ROWS]: [ { dimension: DIMENSION_ID_PERIOD }, { dimension: 'twilight' }, + { dimension: 'pinkiepie' }, ], [AXIS_ID_FILTERS]: [{ dimension: DIMENSION_ID_ORGUNIT }], } @@ -72,11 +134,14 @@ describe('getVisualizationConfig', () => { id: undefined, type: 'COLUMN', [AXIS_ID_COLUMNS]: [{ dimension: DIMENSION_ID_DATA }], - [AXIS_ID_ROWS]: [{ dimension: DIMENSION_ID_PERIOD }], + [AXIS_ID_ROWS]: [ + { dimension: DIMENSION_ID_PERIOD }, + { dimension: 'twilight' }, + ], [AXIS_ID_FILTERS]: [ { dimension: DIMENSION_ID_ORGUNIT }, { dimension: 'rainbow' }, - { dimension: 'twilight' }, + { dimension: 'pinkiepie' }, ], } diff --git a/src/components/Item/VisualizationItem/getVisualizationConfig.js b/src/components/Item/VisualizationItem/getVisualizationConfig.js index 410ac5f22..e47ce1224 100644 --- a/src/components/Item/VisualizationItem/getVisualizationConfig.js +++ b/src/components/Item/VisualizationItem/getVisualizationConfig.js @@ -30,7 +30,7 @@ const getVisualizationConfig = (visualization, originalType, activeType) => { type: activeType === CHART ? VIS_TYPE_COLUMN : VIS_TYPE_PIVOT_TABLE, }) } else if (originalType === REPORT_TABLE && activeType === CHART) { - const layout = getAdaptedUiLayoutByType(visualization, activeType) + const layout = getAdaptedUiLayoutByType(visualization, VIS_TYPE_COLUMN) return getWithoutId({ ...visualization, ...layout, From 30dfc7b50e880467adc10f580f7f1483c6ef6346 Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Thu, 19 Nov 2020 15:57:58 +0100 Subject: [PATCH 2/3] fix: unintended test copy --- .../__tests__/getVisualizationConfig.spec.js | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/src/components/Item/VisualizationItem/__tests__/getVisualizationConfig.spec.js b/src/components/Item/VisualizationItem/__tests__/getVisualizationConfig.spec.js index f4607b509..8e114fa31 100644 --- a/src/components/Item/VisualizationItem/__tests__/getVisualizationConfig.spec.js +++ b/src/components/Item/VisualizationItem/__tests__/getVisualizationConfig.spec.js @@ -28,32 +28,6 @@ describe('getVisualizationConfig', () => { expect(actualResult).toEqual(expectedResult) }) - it('returns correct config when switching from CHART to REPORT_TABLE and one row item', () => { - const visConfig = { - id: 'vis1', - type: 'CHART', - [AXIS_ID_COLUMNS]: [{ dimension: DIMENSION_ID_DATA }], - [AXIS_ID_ROWS]: [{ dimension: DIMENSION_ID_PERIOD }], - [AXIS_ID_FILTERS]: [ - { dimension: DIMENSION_ID_ORGUNIT }, - { dimension: 'rainbow' }, - { dimension: 'twilight' }, - ], - } - const actualResult = getVisualizationConfig( - visConfig, - CHART, - REPORT_TABLE - ) - const expectedResult = { - ...visConfig, - id: undefined, - type: 'PIVOT_TABLE', - } - - expect(actualResult).toEqual(expectedResult) - }) - it('returns correct config when switching from CHART to REPORT_TABLE', () => { const visConfig = { id: 'vis1', From e64a13cd36932242f4f95eb1273300501d93e4ef Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Thu, 19 Nov 2020 16:11:03 +0100 Subject: [PATCH 3/3] fix: send correct type for table --- .../Item/VisualizationItem/getVisualizationConfig.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Item/VisualizationItem/getVisualizationConfig.js b/src/components/Item/VisualizationItem/getVisualizationConfig.js index e47ce1224..3429e90e1 100644 --- a/src/components/Item/VisualizationItem/getVisualizationConfig.js +++ b/src/components/Item/VisualizationItem/getVisualizationConfig.js @@ -37,7 +37,10 @@ const getVisualizationConfig = (visualization, originalType, activeType) => { type: VIS_TYPE_COLUMN, }) } else if (originalType === CHART && activeType === REPORT_TABLE) { - const layout = getAdaptedUiLayoutByType(visualization, activeType) + const layout = getAdaptedUiLayoutByType( + visualization, + VIS_TYPE_PIVOT_TABLE + ) return getWithoutId({ ...visualization, ...layout,