49 lines
1.0 KiB
TypeScript
49 lines
1.0 KiB
TypeScript
import { cashList } from '@mocks/browser/data';
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import type { DeleteCashFormProps } from '@/entity/cash';
|
|
|
|
import { DeleteCashForm } from '@/entity/cash';
|
|
import { DataTestId } from '@/shared/constants';
|
|
|
|
const cash = cashList[0];
|
|
|
|
const renderForm = (props?: Partial<DeleteCashFormProps>) => {
|
|
const onSubmit = jest.fn();
|
|
|
|
render(
|
|
<DeleteCashForm
|
|
cash={cash}
|
|
onSubmit={onSubmit}
|
|
{...props}
|
|
/>,
|
|
);
|
|
|
|
return {
|
|
onSubmit,
|
|
};
|
|
};
|
|
|
|
const getFormElements = () => {
|
|
const formElem = screen.getByTestId(DataTestId.DELETE_CASH_FORM);
|
|
const submitButtonElem = screen.getByTestId(DataTestId.DELETE_CASH_SUBMIT_BUTTON);
|
|
|
|
return {
|
|
formElem,
|
|
submitButtonElem,
|
|
};
|
|
};
|
|
|
|
const submitForm = async () => {
|
|
const { submitButtonElem } = getFormElements();
|
|
await userEvent.click(submitButtonElem);
|
|
};
|
|
|
|
export const DeleteCashFormHelper = {
|
|
cash,
|
|
getFormElements,
|
|
renderForm,
|
|
submitForm,
|
|
};
|