62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import type { DeleteIncomeItemFormProps } from '@/entity/incomes/item';
|
|
|
|
import { DeleteIncomeItemForm } from '@/entity/incomes/item';
|
|
import { DataTestId } from '@/shared/constants';
|
|
|
|
const incomeItem = {
|
|
amount: 12,
|
|
createdAt: '2025-08-29T07:57:40.503Z',
|
|
currency: 'RUB',
|
|
date: '2025-08-22T00:00:00.000Z',
|
|
description: 'Mock description',
|
|
id: '51a44dc0-597b-49b9-85bb-e0bcd42db3f6',
|
|
incomeListId: '10cc093c-3875-4d33-a40a-df526266e262',
|
|
target: null,
|
|
title: 'Mock item',
|
|
updatedAt: '2025-08-29T07:57:40.503Z',
|
|
};
|
|
|
|
const renderForm = (props?: Partial<DeleteIncomeItemFormProps>) => {
|
|
const onSubmit = jest.fn();
|
|
|
|
render(
|
|
<DeleteIncomeItemForm
|
|
onSubmit={onSubmit}
|
|
{...props}
|
|
/>,
|
|
);
|
|
|
|
const submitButtonElem = screen.getByText('Удалить');
|
|
|
|
return {
|
|
onSubmit,
|
|
submitButtonElem,
|
|
};
|
|
};
|
|
|
|
const getFormElements = () => {
|
|
const formElem = screen.getByTestId(DataTestId.DELETE_INCOME_ITEM_FORM);
|
|
const submitButtonElem = screen.getByTestId(DataTestId.DELETE_INCOME_ITEM_SUBMIT_BUTTON);
|
|
|
|
return {
|
|
formElem,
|
|
submitButtonElem,
|
|
};
|
|
};
|
|
|
|
const submitForm = async () => {
|
|
const { submitButtonElem } = getFormElements();
|
|
|
|
await userEvent.click(submitButtonElem);
|
|
};
|
|
|
|
export const DeleteIncomeItemFormHelper = {
|
|
getFormElements,
|
|
incomeItem,
|
|
renderForm,
|
|
submitForm,
|
|
};
|