60 lines
1.2 KiB
TypeScript
60 lines
1.2 KiB
TypeScript
import { cashList } from '@mocks/browser/data';
|
|
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 {
|
|
EditCashBody,
|
|
EditCashPath,
|
|
EditCashResponse,
|
|
} from '@/entity/cash';
|
|
|
|
import { EditCashButton } from '@/features/cash/EditCashButton';
|
|
import { DataTestId } from '@/shared/constants';
|
|
|
|
const cash = cashList[0];
|
|
|
|
const renderButton = () => {
|
|
render(
|
|
<EditCashButton cash={cash} />,
|
|
{ wrapper: createAppWrapper() },
|
|
);
|
|
|
|
const buttonElem = screen.getByTestId(DataTestId.EDIT_CASH_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<
|
|
EditCashPath,
|
|
EditCashBody,
|
|
EditCashResponse
|
|
>(
|
|
`/cash/${cash.id}`,
|
|
async ({ request }) => {
|
|
const body = await request.json();
|
|
requestSpy(body);
|
|
|
|
return HttpResponse.json(cash);
|
|
},
|
|
);
|
|
|
|
export const EditCashButtonHelper = {
|
|
openModal,
|
|
renderButton,
|
|
submitHandler,
|
|
};
|