Skip to content

Commit 165f4be

Browse files
committed
test: adjust SendButton.test.js
1 parent d78353a commit 165f4be

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/components/MessageInput/__tests__/SendButton.test.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
import React from 'react';
2-
import { fireEvent, render } from '@testing-library/react';
2+
import { act, fireEvent, render } from '@testing-library/react';
33
import '@testing-library/jest-dom';
44
import { toHaveNoViolations } from 'jest-axe';
5+
import { SendButton } from '../SendButton';
6+
import { Channel } from '../../Channel';
7+
import { Chat } from '../../Chat';
8+
import { initClientWithChannels } from '../../../mock-builders';
59
import { axe } from '../../../../axe-helper';
610
expect.extend(toHaveNoViolations);
711

8-
import { SendButton } from '../SendButton';
9-
1012
describe('SendButton', () => {
1113
it('should call whatever callback was passed into the sendMessage prop when the button is pressed', async () => {
1214
const mock = jest.fn();
13-
const { container, getByTitle } = render(<SendButton sendMessage={mock} />);
14-
fireEvent.click(getByTitle('Send'));
15+
const {
16+
channels: [channel],
17+
client,
18+
} = await initClientWithChannels();
19+
channel.messageComposer.textComposer.setText('Enable the button');
20+
const { container, getByTitle } = render(
21+
<Chat client={client}>
22+
<Channel channel={channel}>
23+
<SendButton sendMessage={mock} />
24+
</Channel>
25+
</Chat>,
26+
);
27+
channel.messageComposer.textComposer.setText('X');
28+
await act(async () => {
29+
await fireEvent.click(getByTitle('Send'));
30+
});
1531
expect(mock).toHaveBeenCalledTimes(1);
1632
const results = await axe(container);
1733
expect(results).toHaveNoViolations();

0 commit comments

Comments
 (0)