Fix link creation with backward selection (#9986)

Fix link creation with backward selection
This commit is contained in:
Florian Duros 2023-01-26 11:08:23 +01:00 committed by GitHub
parent 222f8a919d
commit 406edfc27d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 5 deletions

View file

@ -299,6 +299,7 @@ describe("SendWysiwygComposer", () => {
anchorOffset: 2,
focusNode: textNode,
focusOffset: 2,
isForward: true,
});
// the event is not automatically fired by jest
document.dispatchEvent(new CustomEvent("selectionchange"));
@ -308,6 +309,32 @@ describe("SendWysiwygComposer", () => {
// Then
await waitFor(() => expect(screen.getByRole("textbox")).toHaveTextContent(/wo🦫rd/));
});
it("Should add an emoji when a word is selected", async () => {
// When
screen.getByRole("textbox").focus();
screen.getByRole("textbox").innerHTML = "word";
fireEvent.input(screen.getByRole("textbox"), {
data: "word",
inputType: "insertText",
});
const textNode = screen.getByRole("textbox").firstChild;
await setSelection({
anchorNode: textNode,
anchorOffset: 3,
focusNode: textNode,
focusOffset: 2,
isForward: false,
});
// the event is not automatically fired by jest
document.dispatchEvent(new CustomEvent("selectionchange"));
emojiButton.click();
// Then
await waitFor(() => expect(screen.getByRole("textbox")).toHaveTextContent(/wo🦫d/));
});
},
);
});

View file

@ -35,6 +35,7 @@ describe("LinkModal", () => {
anchorNode: null,
focusOffset: 3,
anchorOffset: 4,
isForward: true,
};
const customRender = (isTextEnabled: boolean, onClose: () => void, isEditing = false) => {