feature/testArm #87
@ -6,7 +6,7 @@ test.beforeEach('check server is up', async ({ page }) => {
|
||||
const makeOrderText = page.getByText('Сделать заказ', { exact: true });
|
||||
await expect(makeOrderText).toBeVisible();
|
||||
} catch (error) {
|
||||
console.error('server not up');
|
||||
console.error('server not up', error);
|
||||
test.skip();
|
||||
}
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { FetchBaseQueryError } from "@reduxjs/toolkit/query";
|
||||
import { FetchBaseQueryError } from '@reduxjs/toolkit/query';
|
||||
|
||||
import { BaseResponse } from "../../models/api";
|
||||
import { BaseResponse } from '../../models/api';
|
||||
|
||||
export const extractBodyFromResponse = <Body>(response: BaseResponse<Body>) => {
|
||||
if (response.success) {
|
||||
@ -8,8 +8,14 @@ export const extractBodyFromResponse = <Body>(response: BaseResponse<Body>) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const extractErrorMessageFromResponse = ({ data }: FetchBaseQueryError) => {
|
||||
if (typeof data === 'object' && 'message' in data && typeof data.message === 'string') {
|
||||
export const extractErrorMessageFromResponse = ({
|
||||
data,
|
||||
}: FetchBaseQueryError) => {
|
||||
if (
|
||||
typeof data === 'object' &&
|
||||
'message' in data &&
|
||||
typeof data.message === 'string'
|
||||
) {
|
||||
return data.message;
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Arm Page render 1`] = `
|
||||
exports[`order page получение списка заказов 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="css-1yeiifd"
|
||||
@ -32,6 +32,7 @@ exports[`Arm Page render 1`] = `
|
||||
/>
|
||||
<a
|
||||
class="chakra-button css-1kg18wp"
|
||||
data-testid="master-button"
|
||||
href="/auth/login"
|
||||
>
|
||||
Мастера
|
||||
@ -74,173 +75,7 @@ exports[`Arm Page render 1`] = `
|
||||
<p
|
||||
class="chakra-text css-52ukzg"
|
||||
>
|
||||
09.02.2025
|
||||
</p>
|
||||
<button
|
||||
class="chakra-button css-ez23ye"
|
||||
type="button"
|
||||
>
|
||||
<svg
|
||||
class="chakra-icon css-onkibi"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
d="M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<table
|
||||
class="chakra-table css-5605sr"
|
||||
>
|
||||
<thead
|
||||
class="css-0"
|
||||
>
|
||||
<tr
|
||||
class="css-0"
|
||||
>
|
||||
<th
|
||||
class="css-1szkfps"
|
||||
>
|
||||
Номер машины
|
||||
</th>
|
||||
<th
|
||||
class="css-1szkfps"
|
||||
>
|
||||
Дата заказа
|
||||
</th>
|
||||
<th
|
||||
class="css-1szkfps"
|
||||
>
|
||||
Статус
|
||||
</th>
|
||||
<th
|
||||
class="css-1szkfps"
|
||||
>
|
||||
Мастер
|
||||
</th>
|
||||
<th
|
||||
class="css-1szkfps"
|
||||
>
|
||||
Телефон
|
||||
</th>
|
||||
<th
|
||||
class="css-1szkfps"
|
||||
>
|
||||
Расположение
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody
|
||||
class="css-0"
|
||||
>
|
||||
<tr
|
||||
class="css-0"
|
||||
>
|
||||
<td
|
||||
class="css-1v9gmks"
|
||||
colspan="6"
|
||||
>
|
||||
<div
|
||||
class="chakra-spinner css-1j92705"
|
||||
>
|
||||
<span
|
||||
class="css-8b45rq"
|
||||
>
|
||||
Loading...
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
hidden=""
|
||||
id="__chakra_env"
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Arm Page render 2`] = `
|
||||
<div>
|
||||
<div
|
||||
class="css-1yeiifd"
|
||||
>
|
||||
<div
|
||||
class="css-13owfwq"
|
||||
>
|
||||
<h2
|
||||
class="chakra-heading css-173d1bl"
|
||||
>
|
||||
Сухой мастер
|
||||
</h2>
|
||||
<div
|
||||
class="chakra-stack css-1cggwyz"
|
||||
>
|
||||
<hr
|
||||
aria-orientation="horizontal"
|
||||
class="chakra-divider css-svjswr"
|
||||
/>
|
||||
<a
|
||||
class="chakra-button css-1kg18wp"
|
||||
href="/auth/login"
|
||||
>
|
||||
Заказы
|
||||
</a>
|
||||
<hr
|
||||
aria-orientation="horizontal"
|
||||
class="chakra-divider css-svjswr"
|
||||
/>
|
||||
<a
|
||||
class="chakra-button css-1kg18wp"
|
||||
href="/auth/login"
|
||||
>
|
||||
Мастера
|
||||
</a>
|
||||
<hr
|
||||
aria-orientation="horizontal"
|
||||
class="chakra-divider css-svjswr"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="css-jiwy8d"
|
||||
>
|
||||
<div
|
||||
class="css-1glkkdp"
|
||||
>
|
||||
<h2
|
||||
class="chakra-heading css-1xer3cv"
|
||||
>
|
||||
Заказы
|
||||
</h2>
|
||||
<div
|
||||
class="css-1u3smh"
|
||||
>
|
||||
<button
|
||||
class="chakra-button css-ez23ye"
|
||||
type="button"
|
||||
>
|
||||
<svg
|
||||
class="chakra-icon css-onkibi"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
<p
|
||||
class="chakra-text css-52ukzg"
|
||||
>
|
||||
09.02.2025
|
||||
2/16/2025
|
||||
</p>
|
||||
<button
|
||||
class="chakra-button css-ez23ye"
|
98
src/pages/__tests__/masters.test.tsx
Normal file
98
src/pages/__tests__/masters.test.tsx
Normal file
@ -0,0 +1,98 @@
|
||||
import * as React from 'react';
|
||||
import {
|
||||
describe,
|
||||
it,
|
||||
expect,
|
||||
jest,
|
||||
beforeAll,
|
||||
afterEach,
|
||||
afterAll,
|
||||
} from '@jest/globals';
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { ChakraProvider, theme as chakraTheme } from '@chakra-ui/react';
|
||||
import { Provider } from 'react-redux';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
|
||||
import ErrorBoundary from '../../components/ErrorBoundary';
|
||||
import { store } from '../../__data__/store';
|
||||
import Page from '../arm';
|
||||
|
||||
const server = setupServer(
|
||||
http.get('/api/arm/masters', () => {
|
||||
return HttpResponse.json({
|
||||
success: true,
|
||||
body: [
|
||||
{
|
||||
id: '4545423234',
|
||||
name: 'Иван Иванов',
|
||||
phone: '+7 900 123 45 67',
|
||||
},
|
||||
{
|
||||
name: 'Олег Макаров',
|
||||
phone: '79001234567',
|
||||
id: '23423442',
|
||||
},
|
||||
{
|
||||
id: '345354234',
|
||||
name: 'Иван Галкин',
|
||||
schedule: [
|
||||
{
|
||||
id: 'order1',
|
||||
startWashTime: '2024-11-24T10:30:00.000Z',
|
||||
endWashTime: '2024-11-24T16:30:00.000Z',
|
||||
},
|
||||
{
|
||||
id: 'order2',
|
||||
startWashTime: '2024-11-24T11:30:00.000Z',
|
||||
endWashTime: '2024-11-24T17:30:00.000Z',
|
||||
},
|
||||
],
|
||||
phone: '+7 900 123 45 67',
|
||||
},
|
||||
],
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
jest.mock('@brojs/cli', () => {
|
||||
return {
|
||||
getNavigationValue: (key: string) =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
require('../../../bro.config').navigations[key],
|
||||
getConfigValue: () => '/api',
|
||||
};
|
||||
});
|
||||
|
||||
describe('Master Page', () => {
|
||||
beforeAll(() => server.listen());
|
||||
afterEach(() => server.resetHandlers());
|
||||
afterAll(() => server.close());
|
||||
|
||||
it('render ', async () => {
|
||||
server.events.on('request:start', ({ request }) => {
|
||||
console.log('Outgoing:', request.method, request.url);
|
||||
});
|
||||
|
||||
const { container } = render(
|
||||
<Provider store={store}>
|
||||
<ChakraProvider theme={chakraTheme}>
|
||||
<ErrorBoundary>
|
||||
<BrowserRouter>
|
||||
<Page mockUser={{ name: 'ilnaz' }} />
|
||||
</BrowserRouter>
|
||||
</ErrorBoundary>
|
||||
</ChakraProvider>
|
||||
</Provider>,
|
||||
);
|
||||
|
||||
const button = await waitFor(() => screen.getByTestId('master-button'));
|
||||
|
||||
fireEvent.click(button);
|
||||
|
||||
await waitFor(() => screen.getByText('Иван Иванов'));
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
});
|
@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import * as React from 'react';
|
||||
import {
|
||||
describe,
|
||||
it,
|
||||
@ -98,12 +98,12 @@ jest.mock('@brojs/cli', () => {
|
||||
};
|
||||
});
|
||||
|
||||
describe('Arm Page', () => {
|
||||
describe('order page', () => {
|
||||
beforeAll(() => server.listen());
|
||||
afterEach(() => server.resetHandlers());
|
||||
afterAll(() => server.close());
|
||||
|
||||
it('render ', async () => {
|
||||
it('получение списка заказов ', async () => {
|
||||
server.events.on('request:start', ({ request }) => {
|
||||
console.log('Outgoing:', request.method, request.url);
|
||||
});
|
||||
@ -120,8 +120,6 @@ describe('Arm Page', () => {
|
||||
</Provider>,
|
||||
);
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
await waitFor(() => screen.getByText('A123BC'));
|
||||
|
||||
expect(container).toMatchSnapshot();
|
Loading…
Reference in New Issue
Block a user