70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
import { createAppWrapper } from '@mocks/jest/wrappers';
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { http, HttpResponse } from 'msw';
|
|
|
|
import type {
|
|
EditIncomeItemBody,
|
|
EditIncomeItemPath,
|
|
EditIncomeItemSuccessResponse,
|
|
IncomeListItem,
|
|
} from '@/entity/incomes/item';
|
|
|
|
import { EditIncomeItemButton } from '@/features/incomes/items/EditIncomeItemButton';
|
|
import { DataTestId } from '@/shared/constants';
|
|
|
|
const incomeItem: IncomeListItem = {
|
|
amount: 12,
|
|
createdAt: '2025-08-29T07:57:40.503Z',
|
|
currency: 'RUB',
|
|
date: '2025-08-22T00:00:03.000Z',
|
|
description: 'Mock description',
|
|
id: '51a44dc0-597b-49b9-85bb-e0bcd42db3f6',
|
|
incomeListId: '10cc093c-3875-4d33-a40a-df526266e262',
|
|
title: 'Mock item',
|
|
updatedAt: '2025-08-29T07:57:40.503Z',
|
|
};
|
|
|
|
const renderButton = () => {
|
|
render(
|
|
<EditIncomeItemButton item={incomeItem} />,
|
|
{ wrapper: createAppWrapper() },
|
|
);
|
|
|
|
const buttonElem = screen.getByTestId(DataTestId.EDIT_INCOME_ITEM_BUTTON);
|
|
|
|
return {
|
|
buttonElem,
|
|
};
|
|
};
|
|
|
|
const openModal = async () => {
|
|
const { buttonElem } = renderButton();
|
|
await userEvent.click(buttonElem);
|
|
const modalElem = screen.getByRole('presentation');
|
|
|
|
return {
|
|
modalElem,
|
|
};
|
|
};
|
|
|
|
const submitHandler = (requestSpy: jest.Mock) => http.patch<
|
|
EditIncomeItemPath,
|
|
EditIncomeItemBody,
|
|
EditIncomeItemSuccessResponse
|
|
>(
|
|
`/incomes/list/${incomeItem.incomeListId}/items/${incomeItem.id}`,
|
|
async ({ request }) => {
|
|
const body = await request.json();
|
|
requestSpy(body);
|
|
|
|
return HttpResponse.json(incomeItem);
|
|
},
|
|
);
|
|
|
|
export const EditIncomeItemButtonHelper = {
|
|
openModal,
|
|
renderButton,
|
|
submitHandler,
|
|
};
|