chore(docs): adjust settings copy
[ProtonMail-WebClient.git] / applications / mail / jest.setup.js
blobe9e5cb885ef4abcd6f6923be6a2bbcaaa2e7e691
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(() => ({
13     observe: jest.fn(),
14     unobserve: jest.fn(),
15     disconnect: jest.fn(),
16 }));
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', () => ({
24     __esModule: true,
25     loadCryptoWorker: jest.fn(),
26 }));
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', () => ({
30     __esModule: true,
31     walletReducers: {},
32 }));
34 jest.mock('@proton/andromeda', () => ({
35     __esModule: true,
36     WasmProtonWalletApiClient: jest.fn(),
37 }));
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 };
48     };
50     result.subscribe = subscribe;
51     result.call = call;
52     result.stop = stop;
53     result.start = start;
55     return result;
56 });
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', () => ({
68     __esModule: true,
69     default: () => null,
70 }));
72 // Silence JDOM warnings triggered by emoji-mart
73 HTMLCanvasElement.prototype.getContext = jest.fn();
75 jest.mock('@proton/shared/lib/i18n/dateFnLocales', () => ({
76     __esModule: true,
77 }));
79 jest.mock('@proton/shared/lib/pow/wasmWorkerWrapper.ts', () => ({
80     __esModule: true,
81 }));
83 jest.mock('@proton/shared/lib/pow/pbkdfWorkerWrapper.ts', () => ({
84     __esModule: true,
85 }));
87 jest.mock('@proton/llm/lib/hooks/useAssistant.tsx', () => {
88     return {
89         __esModule: true,
90         useAssistant: jest.fn(() => ({
91             assistantConfig: {},
92             cancelDownloadModel: jest.fn(),
93             cancelRunningAction: jest.fn(),
94             canRunAssistant: false,
95             canUseAssistant: false,
96             closeAssistant: jest.fn(),
97             downloadModelSize: 0,
98             downloadPaused: false,
99             downloadReceivedBytes: 0,
100             errors: [],
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(),
117         })),
118     };
121 jest.mock('proton-mail/components/list/tip/useTips.tsx', () => ({
122     __esModule: true,
123     default: jest.fn().mockReturnValue({}),
124 }));
126 jest.mock('@proton/account/securityCheckup/listener', () => ({
127     __esModule: true,
128     securityCheckupListener: jest.fn().mockReturnValue({}),
129 }));