|
1 | 1 | import React from 'react'; |
2 | | -import { fireEvent, render } from '@testing-library/react'; |
| 2 | +import { act, fireEvent, render } from '@testing-library/react'; |
3 | 3 | import '@testing-library/jest-dom'; |
4 | 4 | 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'; |
5 | 9 | import { axe } from '../../../../axe-helper'; |
6 | 10 | expect.extend(toHaveNoViolations); |
7 | 11 |
|
8 | | -import { SendButton } from '../SendButton'; |
9 | | - |
10 | 12 | describe('SendButton', () => { |
11 | 13 | it('should call whatever callback was passed into the sendMessage prop when the button is pressed', async () => { |
12 | 14 | 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 | + }); |
15 | 31 | expect(mock).toHaveBeenCalledTimes(1); |
16 | 32 | const results = await axe(container); |
17 | 33 | expect(results).toHaveNoViolations(); |
|
0 commit comments