64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
import { server } from '@mocks/jest/server';
|
|
import { screen, waitFor } from '@testing-library/react';
|
|
import { AddExpenseItemButtonHelper, AddExpenseItemFormHelper } from '@tests/helpers';
|
|
|
|
describe('Test AddExpenseItemButton', () => {
|
|
test('should correct render button', () => {
|
|
const { buttonElem } = AddExpenseItemButtonHelper.renderButton();
|
|
|
|
expect(buttonElem).toBeInTheDocument();
|
|
expect(buttonElem).toBeVisible();
|
|
expect(buttonElem).toBeEnabled();
|
|
expect(buttonElem).toHaveTextContent('Добавить элемент');
|
|
|
|
const modal = screen.queryByRole('presentation');
|
|
expect(modal).not.toBeInTheDocument();
|
|
});
|
|
|
|
test('should open modal after click', async () => {
|
|
const { modalElem } = await AddExpenseItemButtonHelper.openModal();
|
|
|
|
expect(modalElem).toBeInTheDocument();
|
|
expect(modalElem).toBeVisible();
|
|
});
|
|
|
|
describe('should close modal after submit and send request', () => {
|
|
let modalElem: HTMLElement;
|
|
const requestSpy = jest.fn();
|
|
|
|
beforeEach(async () => {
|
|
server.use(AddExpenseItemButtonHelper.submitHandler(requestSpy));
|
|
modalElem = (await AddExpenseItemButtonHelper.openModal()).modalElem;
|
|
|
|
await AddExpenseItemFormHelper.fillForm({
|
|
amount: '12',
|
|
count: '1',
|
|
date: '29.08.2025',
|
|
description: 'Описание элемента',
|
|
title: 'Название элемента',
|
|
}, { autoSubmit: false });
|
|
});
|
|
|
|
test('should send correct request', async () => {
|
|
await AddExpenseItemFormHelper.submitForm();
|
|
expect(requestSpy).toHaveBeenCalledTimes(1);
|
|
expect(requestSpy).toHaveBeenCalledWith({
|
|
amount: 12,
|
|
count: 1,
|
|
currency: 'RUB',
|
|
date: '2025-08-29T00:00:00.000Z',
|
|
description: 'Описание элемента',
|
|
payment: null,
|
|
title: 'Название элемента',
|
|
});
|
|
});
|
|
|
|
test('should close modal after submit', async () => {
|
|
await AddExpenseItemFormHelper.submitForm();
|
|
await waitFor(() => {
|
|
expect(modalElem).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
});
|