-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathservice_overview.test.tsx
94 lines (88 loc) · 3.11 KB
/
service_overview.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* 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 React, { ReactNode } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { CoreStart } from 'src/core/public';
import { createKibanaReactContext } from '../../../../../../../src/plugins/kibana_react/public';
import { ApmPluginContextValue } from '../../../context/ApmPluginContext';
import {
mockApmPluginContextValue,
MockApmPluginContextWrapper,
} from '../../../context/ApmPluginContext/MockApmPluginContext';
import { MockUrlParamsContextProvider } from '../../../context/UrlParamsContext/MockUrlParamsContextProvider';
import * as useDynamicIndexPatternHooks from '../../../hooks/useDynamicIndexPattern';
import * as useFetcherHooks from '../../../hooks/useFetcher';
import { FETCH_STATUS } from '../../../hooks/useFetcher';
import * as useAnnotationsHooks from '../../../hooks/use_annotations';
import * as useTransactionBreakdownHooks from '../../../hooks/use_transaction_breakdown';
import { renderWithTheme } from '../../../utils/testHelpers';
import { ServiceOverview } from './';
const KibanaReactContext = createKibanaReactContext({
usageCollection: { reportUiStats: () => {} },
} as Partial<CoreStart>);
function Wrapper({ children }: { children?: ReactNode }) {
const value = ({
...mockApmPluginContextValue,
core: {
...mockApmPluginContextValue.core,
http: {
basePath: { prepend: () => {} },
get: () => {},
},
},
} as unknown) as ApmPluginContextValue;
return (
<MemoryRouter keyLength={0}>
<KibanaReactContext.Provider>
<MockApmPluginContextWrapper value={value}>
<MockUrlParamsContextProvider
params={{ rangeFrom: 'now-15m', rangeTo: 'now' }}
>
{children}
</MockUrlParamsContextProvider>
</MockApmPluginContextWrapper>
</KibanaReactContext.Provider>
</MemoryRouter>
);
}
describe('ServiceOverview', () => {
it('renders', () => {
jest
.spyOn(useAnnotationsHooks, 'useAnnotations')
.mockReturnValue({ annotations: [] });
jest
.spyOn(useDynamicIndexPatternHooks, 'useDynamicIndexPattern')
.mockReturnValue({
indexPattern: undefined,
status: FETCH_STATUS.SUCCESS,
});
jest.spyOn(useFetcherHooks, 'useFetcher').mockReturnValue({
data: {
items: [],
tableOptions: {
pageIndex: 0,
sort: { direction: 'desc', field: 'test field' },
},
totalItemCount: 0,
throughput: [],
},
refetch: () => {},
status: FETCH_STATUS.SUCCESS,
});
jest
.spyOn(useTransactionBreakdownHooks, 'useTransactionBreakdown')
.mockReturnValue({
data: { timeseries: [] },
error: undefined,
status: FETCH_STATUS.SUCCESS,
});
expect(() =>
renderWithTheme(<ServiceOverview serviceName="test service name" />, {
wrapper: Wrapper,
})
).not.toThrowError();
});
});