59 lines
1.9 KiB
TypeScript

import { server } from '@mocks/jest/server';
import { screen, waitFor } from '@testing-library/react';
import { EditCashButtonHelper, EditCashFormHelper } from '@tests/helpers';
describe('Test EditCashButton', () => {
test('should correct render button', () => {
const { buttonElem } = EditCashButtonHelper.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 EditCashButtonHelper.openModal();
expect(modalElem).toBeInTheDocument();
expect(modalElem).toBeVisible();
});
describe('should close modal after submit and send request', () => {
let modalElem: HTMLElement;
let submitButtonElem: HTMLElement;
const requestSpy = jest.fn();
beforeEach(async () => {
server.use(EditCashButtonHelper.submitHandler(requestSpy));
modalElem = (await EditCashButtonHelper.openModal()).modalElem;
submitButtonElem = EditCashFormHelper.getFormElements().submitButtonElem;
await EditCashFormHelper.fillForm({
balance: 999,
name: 'Наличные',
}, { autoSubmit: false });
});
test('should send correct request', async () => {
await EditCashFormHelper.submitForm();
expect(requestSpy).toHaveBeenCalledTimes(1);
expect(requestSpy).toHaveBeenCalledWith({
balance: 999,
name: 'Наличные',
});
});
test('should close modal after submit', async () => {
expect(submitButtonElem).toBeEnabled();
await EditCashFormHelper.submitForm();
await waitFor(() => {
expect(modalElem).not.toBeInTheDocument();
});
});
});
});