Skip to content

Commit

Permalink
add unit tests for error and warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Jun 4, 2021
1 parent ef95471 commit 5a25c36
Showing 1 changed file with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 5a25c36

Please sign in to comment.