Skip to content

Commit

Permalink
sanity check coordinates before calculate the mean
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jul 1, 2020
1 parent d7cb371 commit ffedc7f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,45 @@ describe('Observability dashboard data', () => {
},
});
});
it('returns transaction stat as 0 when y is undefined', async () => {
callApmApiMock.mockImplementation(() =>
Promise.resolve({
serviceCount: 0,
transactionCoordinates: [{ x: 1 }, { x: 2 }, { x: 3 }],
})
);
const response = await fetchLandingPageData(
{
startTime: '1',
endTime: '2',
bucketSize: '3',
},
{ theme }
);
expect(response).toEqual({
title: 'APM',
appLink: '/app/apm',
stats: {
services: {
type: 'number',
label: 'Services',
value: 0,
},
transactions: {
type: 'number',
label: 'Transactions',
value: 0,
color: '#6092c0',
},
},
series: {
transactions: {
label: 'Transactions',
coordinates: [{ x: 1 }, { x: 2 }, { x: 3 }],
color: '#6092c0',
},
},
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ export const fetchLandingPageData = async (
'xpack.apm.observabilityDashboard.stats.transactions',
{ defaultMessage: 'Transactions' }
),
value:
mean(transactionCoordinates.map((coordinates) => coordinates.y)) || 0,
value: !!transactionCoordinates.length
? mean(
transactionCoordinates.map((coordinates) => coordinates.y || 0)
)
: 0,
color: theme.euiColorVis1,
},
},
Expand Down

0 comments on commit ffedc7f

Please sign in to comment.