Skip to content

Commit 9330780

Browse files
[Synthetics] Fetch trend data when monitors are grouped (elastic#244551)
## Summary 1. Call `useOverviewTrendsRequests` in `GroupGridCardContent` so the trend data is fetched when the monitors are groupped 2. Add a unit test to cover this case
1 parent 6d8363a commit 9330780

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { render } from '@testing-library/react';
9+
import React from 'react';
10+
11+
jest.mock('../../../hooks/use_overview_trends_requests', () => ({
12+
useOverviewTrendsRequests: jest.fn(),
13+
}));
14+
15+
import { useOverviewTrendsRequests } from '../../../hooks/use_overview_trends_requests';
16+
import { GroupGridItem } from './grid_group_item';
17+
import type { OverviewStatusMetaData } from '../../types';
18+
import { WrappedHelper } from '../../../../../utils/testing';
19+
20+
describe('GridGroupItem', () => {
21+
const renderComponent = (props: Partial<React.ComponentProps<typeof GroupGridItem>> = {}) => {
22+
const defaultProps: React.ComponentProps<typeof GroupGridItem> = {
23+
loaded: false,
24+
groupLabel: 'Test Group',
25+
fullScreenGroup: '',
26+
setFullScreenGroup: () => {},
27+
groupMonitors: [],
28+
setFlyoutConfigCallback: () => {},
29+
view: 'cardView',
30+
};
31+
return render(
32+
<WrappedHelper>
33+
<GroupGridItem {...defaultProps} {...props} />
34+
</WrappedHelper>
35+
);
36+
};
37+
it('calls useOverviewTrendsRequests to fetch trends for visible monitors', () => {
38+
const monitors = [
39+
{ configId: 'id1', locationId: 'loc1', schedule: 10 },
40+
{ configId: 'id2', locationId: 'loc2', schedule: 10 },
41+
] as unknown as OverviewStatusMetaData[];
42+
43+
renderComponent({ groupMonitors: monitors, loaded: true });
44+
expect(useOverviewTrendsRequests).toHaveBeenCalledWith(expect.arrayContaining(monitors));
45+
});
46+
});

x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/grid_by_group/grid_group_item.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { selectOverviewStatus } from '../../../../../state/overview_status';
2828
import { MetricItem } from '../metric_item/metric_item';
2929
import type { OverviewView } from '../../../../../state';
3030
import { MonitorsTable } from '../compact_view/components/monitors_table';
31+
import { useOverviewTrendsRequests } from '../../../hooks/use_overview_trends_requests';
3132

3233
const PER_ROW = 4;
3334
const DEFAULT_ROW_SIZE = 2;
@@ -47,6 +48,7 @@ const GroupGridCardContent = ({
4748
activePage * rowSize * PER_ROW,
4849
(activePage + 1) * rowSize * PER_ROW
4950
);
51+
useOverviewTrendsRequests(visibleMonitors);
5052

5153
const totalEntries = groupMonitors.length / PER_ROW;
5254

0 commit comments

Comments
 (0)