1 import '@testing-library/jest-dom';
3 import '@proton/testing/lib/mockMatchMedia';
4 import '@proton/testing/lib/mockUnleash';
6 // Silence warnings on expect to throw https://github.com/testing-library/react-testing-library/issues/157
7 // console.error = () => {};
8 // console.warn = () => {};
10 // Getting ReferenceError: TextDecoder is not defined without
12 window
.ResizeObserver
= jest
.fn().mockImplementation(() => ({
15 disconnect
: jest
.fn(),
18 // JSDom does not include a full implementation of webcrypto
19 const crypto
= require('crypto').webcrypto
;
20 global
.crypto
.subtle
= crypto
.subtle
;
22 // Do not start crypto worker pool, let the single tests setup/mock the CryptoProxy as needed
23 jest
.mock('@proton/shared/lib/helpers/setupCryptoWorker', () => ({
25 loadCryptoWorker
: jest
.fn(),
28 // We mock @proton/wallet & @proton/andromeda to avoid wasm call in tests since Jest don't support wasm for now
29 jest
.mock('@proton/wallet', () => ({
34 jest
.mock('@proton/andromeda', () => ({
36 WasmProtonWalletApiClient
: jest
.fn(),
39 // Globally mocked @proton/components modules
40 jest
.mock('@proton/components/hooks/useEventManager.ts', () => {
41 const subscribe
= jest
.fn();
42 const call
= jest
.fn();
43 const stop
= jest
.fn();
44 const start
= jest
.fn();
46 const result
= () => {
47 return { subscribe
, call
, stop
, start
};
50 result
.subscribe
= subscribe
;
58 // Globally mocked upload helper (standard requests are mocked through context)
59 jest
.mock('./src/app/helpers/upload');
61 global
.MutationObserver
= class {
62 disconnect() {} // eslint-disable-line
63 observe() {} // eslint-disable-line
66 // Mock backdrop container because it's always rendered, and it's rendered in a portal which causes issues with the hook renderer
67 jest
.mock('@proton/components/components/modalTwo/BackdropContainer', () => ({
72 // Silence JDOM warnings triggered by emoji-mart
73 HTMLCanvasElement
.prototype.getContext
= jest
.fn();
75 jest
.mock('@proton/shared/lib/i18n/dateFnLocales', () => ({
79 jest
.mock('@proton/shared/lib/pow/wasmWorkerWrapper.ts', () => ({
83 jest
.mock('@proton/shared/lib/pow/pbkdfWorkerWrapper.ts', () => ({
87 jest
.mock('@proton/llm/lib/hooks/useAssistant.tsx', () => {
90 useAssistant
: jest
.fn(() => ({
92 cancelDownloadModel
: jest
.fn(),
93 cancelRunningAction
: jest
.fn(),
94 canRunAssistant
: false,
95 canUseAssistant
: false,
96 closeAssistant
: jest
.fn(),
98 downloadPaused
: false,
99 downloadReceivedBytes
: 0,
101 generateResult
: jest
.fn(),
102 hasCompatibleBrowser
: false,
103 hasCompatibleHardware
: false,
104 initAssistant
: jest
.fn(),
105 isGeneratingResult
: false,
106 isModelDownloaded
: false,
107 isModelDownloading
: false,
108 isModelLoadedOnGPU
: false,
109 isModelLoadingOnGPU
: false,
110 openAssistant
: jest
.fn(),
111 openedAssistants
: [],
112 resetAssistantState
: jest
.fn(),
113 resumeDownloadModel
: jest
.fn(),
114 setAssistantStatus
: jest
.fn(),
115 unloadModelOnGPU
: jest
.fn(),
116 getIsStickyAssistant
: jest
.fn(),
121 jest
.mock('proton-mail/components/list/tip/useTips.tsx', () => ({
123 default: jest
.fn().mockReturnValue({}),
126 jest
.mock('@proton/account/securityCheckup/listener', () => ({
128 securityCheckupListener
: jest
.fn().mockReturnValue({}),