Skip to content

Commit

Permalink
[RTE] Unit tests for RichTextSendBox (#4551)
Browse files Browse the repository at this point in the history
* Tests

* Update tests

* Remove inputbox test for now.

* CC

* CC
  • Loading branch information
palatter authored and mgamis-msft committed May 1, 2024
1 parent a0261b2 commit 7195eb8
Showing 1 changed file with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import React from 'react';
import { RichTextSendBox } from './RichTextSendBox';
/* @conditional-compile-remove(rich-text-editor) */
import { renderWithLocalization, createTestLocale } from '../utils/testUtils';
import { render, waitFor, fireEvent } from '@testing-library/react';
import { screen } from '@testing-library/react';
import { render, waitFor, fireEvent, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { registerIcons } from '@fluentui/react';

Expand All @@ -28,6 +27,58 @@ const icons: {
chevrondown: <></>
};

describe('RichTextSendBox should only call onSendMessage when there is content and it is not disabled', () => {
beforeAll(() => {
registerIcons({
icons: icons
});
});
test('onSendMessage should not be called when message is empty', async () => {
let called = false;
render(
<RichTextSendBox
onSendMessage={async (): Promise<void> => {
called = true;
return Promise.resolve();
}}
/>
);
// Find and click the send button
const sendButton = await screen.findByRole('button', {
name: 'Send message'
});
fireEvent.click(sendButton);
// Check that onSendMessage was not called
expect(called).toBeFalsy();
});
test('onSendMessage should not be called when disabled', async () => {
let called = false;
render(
<RichTextSendBox
disabled={true}
onSendMessage={async (): Promise<void> => {
called = true;
return Promise.resolve();
}}
/>
);
// Find the input field
const editorDiv = screen.queryByTestId('rooster-rich-text-editor');
// fix for an issue when contentEditable is not set to RoosterJS for tests
editorDiv?.setAttribute('contentEditable', 'true');
if (editorDiv === null) {
fail('Editor div not found');
}
// Find and click the send button
const sendButton = await screen.findByRole('button', {
name: 'Send message'
});
fireEvent.click(sendButton);
// Check that onSendMessage was not called
expect(called).toBeFalsy();
});
});

describe('RichTextSendBox should return text correctly', () => {
beforeAll(() => {
registerIcons({
Expand Down

0 comments on commit 7195eb8

Please sign in to comment.