56 lines
1.2 KiB
TypeScript
56 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 { AdCashResponse, AddCashBody } from '@/entity/cash';
|
|
|
|
import { AddCashButton } from '@/features/cash/AddCashButton';
|
|
import { DataTestId } from '@/shared/constants';
|
|
|
|
const cash = cashList[0];
|
|
|
|
const renderButton = () => {
|
|
render(
|
|
<AddCashButton />,
|
|
{ wrapper: createAppWrapper() },
|
|
);
|
|
|
|
const buttonElem = screen.getByTestId(DataTestId.ADD_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.post<
|
|
never,
|
|
AddCashBody,
|
|
AdCashResponse
|
|
>(
|
|
'/cash',
|
|
async ({ request }) => {
|
|
const body = await request.json();
|
|
requestSpy(body);
|
|
|
|
return HttpResponse.json(cash);
|
|
},
|
|
);
|
|
|
|
export const AddCashButtonHelper = {
|
|
openModal,
|
|
renderButton,
|
|
submitHandler,
|
|
};
|