Fix selection

This commit is contained in:
Florian Duros 2022-10-26 14:53:44 +02:00
parent d001ddebbc
commit f1610dae3d
No known key found for this signature in database
GPG key ID: 9700AA5870258A0B
7 changed files with 31 additions and 11 deletions

View file

@ -186,6 +186,7 @@ describe('EditWysiwygComposer', () => {
it('Should focus when receiving an Action.FocusEditMessageComposer action', async () => {
// Given we don't have focus
customRender();
screen.getByLabelText('Bold').focus();
expect(screen.getByRole('textbox')).not.toHaveFocus();
// When we send the right action
@ -201,6 +202,7 @@ describe('EditWysiwygComposer', () => {
it('Should not focus when disabled', async () => {
// Given we don't have focus and we are disabled
customRender(true);
screen.getByLabelText('Bold').focus();
expect(screen.getByRole('textbox')).not.toHaveFocus();
// When we send an action that would cause us to get focus

View file

@ -81,6 +81,7 @@ describe('SendWysiwygComposer', () => {
it('Should focus when receiving an Action.FocusSendMessageComposer action', async () => {
// Given we don't have focus
customRender(jest.fn(), jest.fn());
screen.getByLabelText('Bold').focus();
expect(screen.getByRole('textbox')).not.toHaveFocus();
// When we send the right action
@ -96,6 +97,7 @@ describe('SendWysiwygComposer', () => {
it('Should focus and clear when receiving an Action.ClearAndFocusSendMessageComposer', async () => {
// Given we don't have focus
customRender(jest.fn(), jest.fn());
screen.getByLabelText('Bold').focus();
expect(screen.getByRole('textbox')).not.toHaveFocus();
// When we send the right action
@ -112,6 +114,7 @@ describe('SendWysiwygComposer', () => {
it('Should focus when receiving a reply_to_event action', async () => {
// Given we don't have focus
customRender(jest.fn(), jest.fn());
screen.getByLabelText('Bold').focus();
expect(screen.getByRole('textbox')).not.toHaveFocus();
// When we send the right action

View file

@ -73,11 +73,15 @@ describe('WysiwygComposer', () => {
const defaultRoomContext: IRoomState = getRoomContext(mockRoom, {});
const customRender = (onChange = (_content: string) => void 0, onSend = () => void 0, disabled = false) => {
const customRender = (
onChange = (_content: string) => void 0,
onSend = () => void 0,
disabled = false,
initialContent?: string) => {
return render(
<MatrixClientContext.Provider value={mockClient}>
<RoomContext.Provider value={defaultRoomContext}>
<WysiwygComposer onChange={onChange} onSend={onSend} disabled={disabled} />
<WysiwygComposer onChange={onChange} onSend={onSend} disabled={disabled} initialContent={initialContent} />
</RoomContext.Provider>
</MatrixClientContext.Provider>,
);
@ -91,6 +95,14 @@ describe('WysiwygComposer', () => {
expect(screen.getByRole('textbox')).toHaveAttribute('contentEditable', "false");
});
it('Should have focus', () => {
// When
customRender(jest.fn(), jest.fn(), false);
// Then
expect(screen.getByRole('textbox')).toHaveFocus();
});
it('Should call onChange handler', (done) => {
const html = '<b>html</b>';
customRender((content) => {
@ -104,7 +116,7 @@ describe('WysiwygComposer', () => {
const onSend = jest.fn();
customRender(jest.fn(), onSend);
// When we tell its inputEventProcesser that the user pressed Enter
// When we tell its inputEventProcessor that the user pressed Enter
const event = new InputEvent("insertParagraph", { inputType: "insertParagraph" });
const wysiwyg = { actions: { clear: () => {} } } as Wysiwyg;
inputEventProcessor(event, wysiwyg);