-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathmocks.ts
More file actions
96 lines (89 loc) · 2.8 KB
/
Copy pathmocks.ts
File metadata and controls
96 lines (89 loc) · 2.8 KB
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
95
96
import type { ComponentType, ReactNode } from 'react'
import * as React from 'react'
jest.mock('@auth0/auth0-react', () => ({
Auth0Provider: ({ children }: { children: ReactNode }) => children,
withAuthenticationRequired: (component: ComponentType) => component,
useAuth0: () => {
return {
isLoading: false,
user: { sub: 'foobar' },
isAuthenticated: true,
logout: jest.fn(),
loginWithPopup: jest.fn(),
getAccessTokenSilently: jest.fn(),
}
},
}))
jest.mock('@tanstack/react-router', () => {
const React = jest.requireActual('react')
const navigateMock = jest.fn()
return {
...jest.requireActual('@tanstack/react-router'),
useParams: jest.fn(() => ({
organizationId: '',
projectId: '',
environmentId: '',
serviceId: '',
clusterId: '',
applicationId: '',
databaseId: '',
})),
useNavigate: jest.fn(() => navigateMock),
useLocation: jest.fn(() => ({
pathname: '/',
search: '',
})),
useRouter: jest.fn(() => ({
buildLocation: jest.fn(() => ({
href: '/',
})),
})),
useMatches: jest.fn(() => []),
useSearch: jest.fn(() => ({})),
useMatchRoute: jest.fn(() => () => false),
Link: React.forwardRef(
(
{ children, ...props }: { children?: React.ReactNode; [key: string]: unknown },
ref: React.Ref<HTMLAnchorElement>
) => React.createElement('a', { ref, ...props }, children)
),
}
})
jest.mock('@uidotdev/usehooks', () => ({
useDocumentTitle: jest.fn(),
useClickAway: jest.fn(),
useCopyToClipboard: () => [jest.fn(), jest.fn()],
useDebounce: () => [jest.fn(), jest.fn()],
// Params are implicitly `any` and needed for the tests
// eslint-disable-next-line @typescript-eslint/no-explicit-any
useLocalStorage: (_: any, intialValue: any) => [intialValue, jest.fn()],
useNetworkState: () => ({
effectiveType: '4g',
downlink: 10,
rtt: 50,
saveData: false,
online: true,
type: 'wifi',
}),
}))
// Mocks required for the devops-copilot feature to prevent Jest from choking on ESM modules
// Mock 'mermaid' (used in devops-copilot visual rendering)
jest.mock('mermaid', () => ({
initialize: jest.fn(),
render: jest.fn(() => Promise.resolve({ svg: '' })),
}))
// Mock 'react-markdown' (used to render Markdown content in devops-copilot)
jest.mock('react-markdown', () => ({
__esModule: true,
default: ({ children }: { children: string }) => children,
}))
// Mock 'materialDark' theme from 'react-syntax-highlighter' (used in code blocks in devops-copilot)
jest.mock('react-syntax-highlighter/dist/esm/styles/prism', () => ({
__esModule: true,
materialDark: {},
}))
// Mock 'remark-gfm' (used with react-markdown in devops-copilot)
jest.mock('remark-gfm', () => ({
__esModule: true,
default: () => () => {},
}))