-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetupTests.ts
More file actions
127 lines (110 loc) · 3.2 KB
/
Copy pathsetupTests.ts
File metadata and controls
127 lines (110 loc) · 3.2 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import 'mock-local-storage';
import '@testing-library/jest-dom';
import { vi } from 'vitest';
vi.mock('react-secure-storage', () => ({
default: {
setItem: vi.fn(() => Promise.resolve()),
getItem: vi.fn(() => Promise.resolve('')),
removeItem: vi.fn(() => Promise.resolve()),
clear: vi.fn(() => Promise.resolve()),
},
}));
vi.mock('shared/utils/encryption', async () => ({
__esModule: true,
...(await vi.importActual('shared/utils/encryption')),
}));
vi.spyOn(global.console, 'warn').mockImplementation((message) => {
if (typeof message === 'string' && message.includes('You have provided an out-of-range value'))
return;
return message;
});
vi.spyOn(global.console, 'error').mockImplementation((message) => {
if (
typeof message === 'string' &&
(message.includes('A component is changing an uncontrolled input to be controlled') ||
message.includes('`children` must be passed'))
)
return;
return message;
});
vi.mock('shared/components/FormComponents/EditorController/Editor/Editor.styles', async () => {
const actual = await vi.importActual<typeof import('./__mocks__/EditorController')>(
'./__mocks__/EditorController',
);
return {
StyledMdEditor: actual.StyledMdEditor,
};
});
vi.mock('axios', () => {
const mockPost = vi.fn();
const mockGet = vi.fn();
const mockDelete = vi.fn();
const mockPut = vi.fn();
const mockIsAxiosError = vi.fn();
// Create shared mock instance for axios.create()
const mockInstance = {
post: mockPost,
get: mockGet,
delete: mockDelete,
put: mockPut,
};
return {
default: {
create: () => mockInstance,
post: mockPost,
get: mockGet,
delete: mockDelete,
put: mockPut,
isAxiosError: mockIsAxiosError,
},
};
});
// Global mock for useFeatureFlags - Vitest requires this due to different hoisting behavior than Jest
// In Jest (develop branch), individual test mocks work without a global mock due to automatic hoisting
// In Vitest, we need a default implementation to prevent "Cannot destructure" errors
vi.mock('shared/hooks/useFeatureFlags', () => ({
useFeatureFlags: vi.fn(() => ({
featureFlags: {
enableActivityAssign: true,
enableParticipantMultiInformant: true,
enableMfa: false,
enableAdminAnnouncementBanner: false,
enableAuditLogs: true,
},
resetLDContext: vi.fn(),
})),
}));
// Mock mixpanel-browser to prevent real Mixpanel SDK calls in tests
vi.mock('mixpanel-browser', () => ({
default: {
init: vi.fn(),
track: vi.fn(),
identify: vi.fn(),
reset: vi.fn(),
track_pageview: vi.fn(),
people: {
set: vi.fn(),
},
},
}));
// Global mock for Mixpanel analytics
// Mock both the index and the actual file to ensure coverage
const mockMixpanelObject = {
init: vi.fn(),
track: vi.fn(),
login: vi.fn(),
logout: vi.fn(),
trackPageView: vi.fn(),
updateProfile: vi.fn(),
};
vi.mock('shared/utils/mixpanel/mixpanel', () => ({
Mixpanel: mockMixpanelObject,
}));
vi.mock('shared/utils/mixpanel', async () => {
const actual =
await vi.importActual<typeof import('shared/utils/mixpanel')>('shared/utils/mixpanel');
return {
...actual,
Mixpanel: mockMixpanelObject,
};
});