feat: add tests

This commit is contained in:
2025-02-02 13:52:22 +03:00
parent 12982cdf9e
commit 1dd14caed2
8 changed files with 537 additions and 32 deletions

View File

@@ -0,0 +1,325 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Arm Page render 1`] = `
<div>
<div
class="css-1yeiifd"
>
<div
class="css-1fp6kaj"
>
<h2
class="chakra-heading css-9q1d0h"
>
title
</h2>
<div
class="chakra-stack css-1oen434"
>
<hr
aria-orientation="horizontal"
class="chakra-divider css-1upb9tn"
/>
<a
class="chakra-button css-uxt1e8"
href="/auth/login"
>
orders
</a>
<hr
aria-orientation="horizontal"
class="chakra-divider css-1upb9tn"
/>
<a
class="chakra-button css-uxt1e8"
href="/auth/login"
>
master
</a>
<hr
aria-orientation="horizontal"
class="chakra-divider css-1upb9tn"
/>
</div>
</div>
<div
class="css-sy55x5"
>
<div
class="css-hpgf8j"
>
<h2
class="chakra-heading css-r7q7qr"
>
title
</h2>
<div
class="css-1me9tx"
>
<button
class="chakra-button css-4xx2wk"
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-1bntq7d"
>
2/2/2025
</p>
<button
class="chakra-button css-4xx2wk"
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-0"
>
<thead
class="css-0"
>
<tr
class="css-0"
>
<th
class="css-0"
>
table.header.carNumber
</th>
<th
class="css-0"
>
table.header.orderDate
</th>
<th
class="css-0"
>
table.header.status
</th>
<th
class="css-0"
>
table.header.masters
</th>
<th
class="css-0"
>
table.header.telephone
</th>
<th
class="css-0"
>
table.header.location
</th>
</tr>
</thead>
<tbody
class="css-0"
>
<tr
class="css-0"
>
<td
class="css-12rlgei"
colspan="6"
>
<div
class="chakra-spinner css-1y7joxr"
>
<span
class="css-8b45rq"
>
Loading...
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
`;
exports[`Arm Page render 2`] = `
<div>
<div
class="css-1yeiifd"
>
<div
class="css-1fp6kaj"
>
<h2
class="chakra-heading css-9q1d0h"
>
title
</h2>
<div
class="chakra-stack css-1oen434"
>
<hr
aria-orientation="horizontal"
class="chakra-divider css-1upb9tn"
/>
<a
class="chakra-button css-uxt1e8"
href="/auth/login"
>
orders
</a>
<hr
aria-orientation="horizontal"
class="chakra-divider css-1upb9tn"
/>
<a
class="chakra-button css-uxt1e8"
href="/auth/login"
>
master
</a>
<hr
aria-orientation="horizontal"
class="chakra-divider css-1upb9tn"
/>
</div>
</div>
<div
class="css-sy55x5"
>
<div
class="css-hpgf8j"
>
<h2
class="chakra-heading css-r7q7qr"
>
title
</h2>
<div
class="css-1me9tx"
>
<button
class="chakra-button css-4xx2wk"
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-1bntq7d"
>
2/2/2025
</p>
<button
class="chakra-button css-4xx2wk"
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-0"
>
<thead
class="css-0"
>
<tr
class="css-0"
>
<th
class="css-0"
>
table.header.carNumber
</th>
<th
class="css-0"
>
table.header.orderDate
</th>
<th
class="css-0"
>
table.header.status
</th>
<th
class="css-0"
>
table.header.masters
</th>
<th
class="css-0"
>
table.header.telephone
</th>
<th
class="css-0"
>
table.header.location
</th>
</tr>
</thead>
<tbody
class="css-0"
>
<tr
class="css-0"
>
<td
class="css-12rlgei"
colspan="6"
>
<div
class="chakra-spinner css-1y7joxr"
>
<span
class="css-8b45rq"
>
Loading...
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
`;

View File

@@ -0,0 +1,130 @@
import React from 'react';
import {
describe,
it,
expect,
jest,
beforeAll,
afterEach,
afterAll,
} from '@jest/globals';
import { render, screen, waitFor } from '@testing-library/react';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import { BrowserRouter } from 'react-router-dom';
import Page from '../arm';
const server = setupServer(
http.post('/api/arm/orders', () => {
return HttpResponse.json({
success: true,
body: [
{
id: 'order1',
carNumber: 'A123BC',
startWashTime: '2024-11-24T10:30:00.000Z',
endWashTime: '2024-11-24T16:30:00.000Z',
orderDate: '2024-11-24T08:41:46.366Z',
status: 'pending',
phone: '79001234563',
location: 'Казань, ул. Баумана, 1',
master: {
name: 'Олег Макаров',
phone: '79001234567',
id: '23423442',
},
notes: '',
},
{
id: 'order2',
carNumber: 'A245BC',
startWashTime: '2024-11-24T11:30:00.000Z',
endWashTime: '2024-11-24T17:30:00.000Z',
orderDate: '2024-11-24T07:40:46.366Z',
status: 'progress',
phone: '79001234567',
location: 'Казань, ул. Баумана, 43',
master: [],
notes: '',
},
],
});
}),
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('react-i18next', () => {
return {
useTranslation: () => {
return {
t: (key: never) => `${key}`,
i18n: {},
};
},
};
});
jest.mock('@brojs/cli', () => {
return {
getNavigationValue: () => '/auth/login',
getConfigValue: () => '/api',
};
});
describe('Arm 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(
<BrowserRouter>
<Page mockUser={{ name: 'ilnaz' }} />
</BrowserRouter>,
);
expect(container).toMatchSnapshot();
await waitFor(() => screen.getByText('A123BC'));
expect(container).toMatchSnapshot();
});
});

View File

@@ -6,8 +6,12 @@ import LayoutArm from '../../components/LayoutArm';
import authLogin from '../../keycloak';
import { URLs } from '../../__data__/urls';
const Page = () => {
const [user, setUser] = useState(null);
interface PageProps {
mockUser?: { name: string };
}
const Page = ({ mockUser }: PageProps) => {
const [user, setUser] = useState(mockUser || null);
const navigate = useNavigate();