From 5a25c363ca6102cb57a4e9f2f38f90ca44bab906 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Fri, 4 Jun 2021 14:57:59 +0200 Subject: [PATCH] add unit tests for error and warning messages --- .../visualization.test.ts | 82 ++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/lens/public/heatmap_visualization/visualization.test.ts b/x-pack/plugins/lens/public/heatmap_visualization/visualization.test.ts index 3cd74a5aee71a..3ed82bef06105 100644 --- a/x-pack/plugins/lens/public/heatmap_visualization/visualization.test.ts +++ b/x-pack/plugins/lens/public/heatmap_visualization/visualization.test.ts @@ -402,5 +402,85 @@ describe('heatmap', () => { }); }); - describe('#getErrorMessages', () => {}); + describe('#getErrorMessages', () => { + test('should not return an error when chart has empty configuration', () => { + const mockState = { + shape: CHART_SHAPES.HEATMAP, + } as HeatmapVisualizationState; + expect(getHeatmapVisualization({}).getErrorMessages(mockState)).toEqual(undefined); + }); + + test('should return an error when the X accessor is missing', () => { + const mockState = { + shape: CHART_SHAPES.HEATMAP, + valueAccessor: 'v-accessor', + } as HeatmapVisualizationState; + expect(getHeatmapVisualization({}).getErrorMessages(mockState)).toEqual([ + { + longMessage: 'Configuration for the horizontal axis is missing.', + shortMessage: 'Missing Horizontal axis.', + }, + ]); + }); + }); + + describe('#getWarningMessages', () => { + beforeEach(() => { + const mockDatasource = createMockDatasource('testDatasource'); + + mockDatasource.publicAPIMock.getOperationForColumnId.mockReturnValue({ + dataType: 'string', + label: 'MyOperation', + } as Operation); + + frame.datasourceLayers = { + first: mockDatasource.publicAPIMock, + }; + }); + + test('should not return warning messages when the layer it not configured', () => { + const mockState = { + shape: CHART_SHAPES.HEATMAP, + valueAccessor: 'v-accessor', + } as HeatmapVisualizationState; + expect(getHeatmapVisualization({}).getWarningMessages!(mockState, frame)).toEqual(undefined); + }); + + test('should not return warning messages when the data table is empty', () => { + frame.activeData = { + first: { + type: 'datatable', + rows: [], + columns: [], + }, + }; + const mockState = { + shape: CHART_SHAPES.HEATMAP, + valueAccessor: 'v-accessor', + layerId: 'first', + } as HeatmapVisualizationState; + expect(getHeatmapVisualization({}).getWarningMessages!(mockState, frame)).toEqual(undefined); + }); + + test('should return a warning message when cell value data contains arrays', () => { + frame.activeData = { + first: { + type: 'datatable', + rows: [ + { + 'v-accessor': [1, 2, 3], + }, + ], + columns: [], + }, + }; + + const mockState = { + shape: CHART_SHAPES.HEATMAP, + valueAccessor: 'v-accessor', + layerId: 'first', + } as HeatmapVisualizationState; + expect(getHeatmapVisualization({}).getWarningMessages!(mockState, frame)).toHaveLength(1); + }); + }); });