feat: setup tests env (#85)
This commit is contained in:
parent
b2a067a644
commit
88242c5681
18
__mocks__/app-context-mock.tsx
Normal file
18
__mocks__/app-context-mock.tsx
Normal file
@ -0,0 +1,18 @@
|
||||
import React, { PropsWithChildren } from 'react';
|
||||
import { jest } from '@jest/globals';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import { ChakraProvider, theme as chakraTheme } from '@chakra-ui/react';
|
||||
import { Provider } from 'react-redux';
|
||||
|
||||
import ErrorBoundary from '../src/components/ErrorBoundary';
|
||||
import { store } from '../src/__data__/store';
|
||||
|
||||
export const AppContext = jest.fn(({ children }: PropsWithChildren) => (
|
||||
<Provider store={store}>
|
||||
<ChakraProvider theme={chakraTheme}>
|
||||
<ErrorBoundary>
|
||||
<BrowserRouter>{children}</BrowserRouter>
|
||||
</ErrorBoundary>
|
||||
</ChakraProvider>
|
||||
</Provider>
|
||||
));
|
18
__mocks__/brojs-cli-mock.ts
Normal file
18
__mocks__/brojs-cli-mock.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { jest } from '@jest/globals';
|
||||
|
||||
jest.mock('@brojs/cli', () => ({
|
||||
getConfigValue: jest.fn(() => '/api'),
|
||||
getFeatures: jest.fn(() => ({
|
||||
['order-view-status-polling']: { value: '3000' }
|
||||
})),
|
||||
getNavigationValue: jest.fn((navKey: string) => {
|
||||
switch (navKey) {
|
||||
case 'dry-wash.main':
|
||||
return '/dry-wash';
|
||||
case 'dry-wash.order.create':
|
||||
return '/order';
|
||||
case 'dry-wash.order.view':
|
||||
return '/order/:orderId';
|
||||
}
|
||||
}),
|
||||
}));
|
6
__mocks__/lottiefiles-mock.tsx
Normal file
6
__mocks__/lottiefiles-mock.tsx
Normal file
@ -0,0 +1,6 @@
|
||||
import { jest } from '@jest/globals';
|
||||
import React from 'react';
|
||||
|
||||
jest.mock('@lottiefiles/react-lottie-player', () => ({
|
||||
Player: jest.fn(() => <></>),
|
||||
}));
|
@ -1,9 +1,13 @@
|
||||
import localeRu from '../locales/ru.json';
|
||||
|
||||
module.exports = {
|
||||
useTranslation: (_, { keyPrefix }) => {
|
||||
useTranslation: (_, options) => {
|
||||
const { keyPrefix } = options ?? {};
|
||||
return {
|
||||
t: (key: string) => localeRu[`${keyPrefix}.${key}`],
|
||||
t: keyPrefix ? (key: string) => localeRu[`${keyPrefix}.${key}`] : undefined,
|
||||
i18n: {
|
||||
language: 'ru'
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
11
__mocks__/react-yandex-maps-mock.tsx
Normal file
11
__mocks__/react-yandex-maps-mock.tsx
Normal file
@ -0,0 +1,11 @@
|
||||
import { jest } from '@jest/globals';
|
||||
import React from 'react';
|
||||
|
||||
jest.mock('@pbe/react-yandex-maps', () => ({
|
||||
YMaps: jest.fn(() => <></>),
|
||||
Map: jest.fn(() => <></>),
|
||||
Placemark: jest.fn(() => <></>),
|
||||
GeolocationControl: jest.fn(() => <></>),
|
||||
ZoomControl: jest.fn(() => <></>),
|
||||
withYMaps: jest.fn(() => <></>),
|
||||
}));
|
20
__mocks__/server/handlers.ts
Normal file
20
__mocks__/server/handlers.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { http, delay, HttpResponse } from 'msw';
|
||||
|
||||
import OrderPendingMock from '../../stubs/json/landing-order-view/id1-success-pending.json';
|
||||
import OrderErrorMock from '../../stubs/json/landing-order-view/id1-error.json';
|
||||
|
||||
export const handlers = [
|
||||
http.get('/api/order/:id', async ({ params }) => {
|
||||
await delay();
|
||||
|
||||
const { id } = params;
|
||||
if (id === 'id1') {
|
||||
return HttpResponse.json(OrderPendingMock);
|
||||
}
|
||||
|
||||
return new HttpResponse(null, {
|
||||
status: 500,
|
||||
statusText: OrderErrorMock.message
|
||||
});
|
||||
})
|
||||
];
|
5
__mocks__/server/server.ts
Normal file
5
__mocks__/server/server.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { setupServer } from 'msw/node';
|
||||
|
||||
import { handlers } from './handlers';
|
||||
|
||||
export const server = setupServer(...handlers);
|
1
__mocks__/style-mock.ts
Normal file
1
__mocks__/style-mock.ts
Normal file
@ -0,0 +1 @@
|
||||
module.exports = {};
|
@ -1,4 +1,5 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
transform: {
|
||||
'^.+\\.tsx?$': 'babel-jest',
|
||||
},
|
||||
@ -8,7 +9,8 @@ module.exports = {
|
||||
collectCoverage: true,
|
||||
clearMocks: true,
|
||||
moduleNameMapper: {
|
||||
'\\.(svg|webp)$': '<rootDir>/__mocks__/file',
|
||||
'\\.(svg|webp)$': '<rootDir>/__mocks__/file-mock',
|
||||
'\\.(css|scss)$': '<rootDir>/__mocks__/style-mock',
|
||||
'react-i18next': '<rootDir>/__mocks__/react-i18next',
|
||||
},
|
||||
testEnvironmentOptions: {
|
||||
@ -16,4 +18,5 @@ module.exports = {
|
||||
},
|
||||
testEnvironment: 'jest-fixed-jsdom',
|
||||
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/e2e'],
|
||||
setupFilesAfterEnv: ['<rootDir>/jest-preset-it/jest.setup.js', '<rootDir>/__mocks__/brojs-cli-mock.ts', '<rootDir>/__mocks__/lottiefiles-mock.tsx'],
|
||||
};
|
||||
|
5
jest-preset-it/jest.setup.js
Normal file
5
jest-preset-it/jest.setup.js
Normal file
@ -0,0 +1,5 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, no-undef
|
||||
require('@testing-library/jest-dom');
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
global.__webpack_public_path__ = '';
|
30718
package-lock.json
generated
30718
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -58,8 +58,11 @@
|
||||
"@eslint/js": "^9.14.0",
|
||||
"@playwright/test": "^1.50.1",
|
||||
"@stylistic/eslint-plugin": "^2.10.1",
|
||||
"@testing-library/jest-dom": "^6.6.3",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/node": "^22.13.1",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"@types/testing-library__jest-dom": "^5.14.9",
|
||||
"eslint": "^9.14.0",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-react": "^7.37.2",
|
||||
|
Loading…
Reference in New Issue
Block a user