feat: setup tests env (#85)
This commit is contained in:
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 = {};
|
||||
Reference in New Issue
Block a user