Skip to content

Commit

Permalink
adding unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jun 23, 2020
1 parent 1188e7f commit cca31e9
Showing 1 changed file with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { fetchData, hasData } from './observability_dashboard';
import * as createCallApmApi from './createCallApmApi';

describe('Observability dashboard data', () => {
const callApmApiMock = jest.spyOn(createCallApmApi, 'callApmApi');
afterEach(() => {
callApmApiMock.mockClear();
});
describe('hasData', () => {
it('returns false when no data is available', async () => {
callApmApiMock.mockImplementation(() => Promise.resolve(false));
const response = await hasData();
expect(response).toBeFalsy();
});
it('returns true when data is available', async () => {
callApmApiMock.mockImplementation(() => Promise.resolve(true));
const response = await hasData();
expect(response).toBeTruthy();
});
});

describe('fetchData', () => {
it('returns APM data with series and stats', async () => {
callApmApiMock.mockImplementation(() =>
Promise.resolve({
serviceCount: 10,
transactionCoordinates: [
{ x: 1, y: 1 },
{ x: 2, y: 2 },
{ x: 3, y: 3 },
],
})
);
const response = await fetchData({
startTime: '1',
endTime: '2',
bucketSize: '3',
});
expect(response).toEqual({
title: 'APM',
appLink: '/app/apm',
stats: {
services: {
label: 'Services',
value: 10,
},
transactions: {
label: 'Transactions',
value: 6,
},
},
series: {
transactions: {
label: 'Transactions',
coordinates: [
{ x: 1, y: 1 },
{ x: 2, y: 2 },
{ x: 3, y: 3 },
],
color: 'euiColorVis1',
},
},
});
});
it('returns empty transaction coordinates', async () => {
callApmApiMock.mockImplementation(() =>
Promise.resolve({
serviceCount: 0,
transactionCoordinates: [],
})
);
const response = await fetchData({
startTime: '1',
endTime: '2',
bucketSize: '3',
});
expect(response).toEqual({
title: 'APM',
appLink: '/app/apm',
stats: {
services: {
label: 'Services',
value: 0,
},
transactions: {
label: 'Transactions',
value: 0,
},
},
series: {
transactions: {
label: 'Transactions',
coordinates: [],
color: 'euiColorVis1',
},
},
});
});
});
});

0 comments on commit cca31e9

Please sign in to comment.