-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1188e7f
commit cca31e9
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |