import React from 'react';
import renderer from 'react-test-renderer';
import { fireEvent, render, act } from '@testing-library/react';
import '@testing-library/jest-dom';
import { CommentField, CommentFieldProps } from './CommentField';
import { FeedProvider } from '../context';
describe('CommentField', () => {
it('renders with default props', () => {
const tree = renderer.create().toJSON();
expect(tree).toMatchInlineSnapshot(`
`);
});
it('renders with image and placeholder', () => {
const tree = renderer
.create(
,
)
.toJSON();
expect(tree).toMatchInlineSnapshot(`
`);
});
it('changes value onChange and after button click', async () => {
const onAddReaction = jest.fn();
const successFn = jest.fn();
const { getByPlaceholderText, getByText } = render(
// @ts-expect-error
,
);
const text = 'test';
const button = getByText('Post');
const textarea = getByPlaceholderText('textarea');
fireEvent.change(textarea, { target: { value: text } });
expect(textarea).toHaveValue(text);
// eslint-disable-next-line require-await
await act(async () => {
fireEvent.click(button);
});
expect(onAddReaction).toHaveBeenCalledWith('comment', {}, { text }, { targetFeeds: undefined });
expect(successFn).toHaveBeenCalled();
expect(textarea).toHaveValue('');
});
});