Add ESLint Jest (#10261)

This commit is contained in:
Michael Weimann 2023-03-01 16:23:35 +01:00 committed by GitHub
parent db7748b743
commit 5398db21ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
55 changed files with 336 additions and 351 deletions

View file

@ -177,12 +177,12 @@ describe("EditWysiwygComposer", () => {
screen.getByText("Cancel").click();
// Then
expect(spyDispatcher).toBeCalledWith({
expect(spyDispatcher).toHaveBeenCalledWith({
action: Action.EditEvent,
event: null,
timelineRenderingType: defaultRoomContext.timelineRenderingType,
});
expect(spyDispatcher).toBeCalledWith({
expect(spyDispatcher).toHaveBeenCalledWith({
action: Action.FocusSendMessageComposer,
context: defaultRoomContext.timelineRenderingType,
});
@ -215,10 +215,10 @@ describe("EditWysiwygComposer", () => {
"msgtype": "m.text",
};
await waitFor(() =>
expect(mockClient.sendMessage).toBeCalledWith(mockEvent.getRoomId(), null, expectedContent),
expect(mockClient.sendMessage).toHaveBeenCalledWith(mockEvent.getRoomId(), null, expectedContent),
);
expect(spyDispatcher).toBeCalledWith({ action: "message_sent" });
expect(spyDispatcher).toHaveBeenCalledWith({ action: "message_sent" });
});
});

View file

@ -84,7 +84,7 @@ describe("LinkModal", () => {
// Then
await waitFor(() => {
expect(selectionSpy).toHaveBeenCalledWith(defaultValue);
expect(onFinished).toBeCalledTimes(1);
expect(onFinished).toHaveBeenCalledTimes(1);
});
// Then
@ -127,7 +127,7 @@ describe("LinkModal", () => {
// Then
await waitFor(() => {
expect(selectionSpy).toHaveBeenCalledWith(defaultValue);
expect(onFinished).toBeCalledTimes(1);
expect(onFinished).toHaveBeenCalledTimes(1);
});
// Then
@ -142,7 +142,7 @@ describe("LinkModal", () => {
// Then
expect(formattingFunctions.removeLinks).toHaveBeenCalledTimes(1);
expect(onFinished).toBeCalledTimes(1);
expect(onFinished).toHaveBeenCalledTimes(1);
});
it("Should display the link in editing", async () => {

View file

@ -74,7 +74,7 @@ describe("PlainTextComposer", () => {
await userEvent.type(screen.getByRole("textbox"), content);
// Then
expect(onChange).toBeCalledWith(content);
expect(onChange).toHaveBeenCalledWith(content);
});
it("Should call onSend when Enter is pressed when ctrlEnterToSend is false", async () => {
@ -84,7 +84,7 @@ describe("PlainTextComposer", () => {
await userEvent.type(screen.getByRole("textbox"), "{enter}");
// Then it sends a message
expect(onSend).toBeCalledTimes(1);
expect(onSend).toHaveBeenCalledTimes(1);
});
it("Should not call onSend when Enter is pressed when ctrlEnterToSend is true", async () => {
@ -95,7 +95,7 @@ describe("PlainTextComposer", () => {
await userEvent.type(screen.getByRole("textbox"), "{enter}");
// Then it does not send a message
expect(onSend).toBeCalledTimes(0);
expect(onSend).toHaveBeenCalledTimes(0);
});
it("Should only call onSend when ctrl+enter is pressed when ctrlEnterToSend is true on windows", async () => {
@ -109,15 +109,15 @@ describe("PlainTextComposer", () => {
// Then it does NOT send a message on enter
await userEvent.type(textBox, "{enter}");
expect(onSend).toBeCalledTimes(0);
expect(onSend).toHaveBeenCalledTimes(0);
// Then it does NOT send a message on windows+enter
await userEvent.type(textBox, "{meta>}{enter}{meta/}");
expect(onSend).toBeCalledTimes(0);
expect(onSend).toHaveBeenCalledTimes(0);
// Then it does send a message on ctrl+enter
await userEvent.type(textBox, "{control>}{enter}{control/}");
expect(onSend).toBeCalledTimes(1);
expect(onSend).toHaveBeenCalledTimes(1);
});
it("Should only call onSend when cmd+enter is pressed when ctrlEnterToSend is true on mac", async () => {
@ -132,15 +132,15 @@ describe("PlainTextComposer", () => {
// Then it does NOT send a message on enter
await userEvent.type(textBox, "{enter}");
expect(onSend).toBeCalledTimes(0);
expect(onSend).toHaveBeenCalledTimes(0);
// Then it does NOT send a message on ctrl+enter
await userEvent.type(textBox, "{control>}{enter}{control/}");
expect(onSend).toBeCalledTimes(0);
expect(onSend).toHaveBeenCalledTimes(0);
// Then it does send a message on cmd+enter
await userEvent.type(textBox, "{meta>}{enter}{meta/}");
expect(onSend).toBeCalledTimes(1);
expect(onSend).toHaveBeenCalledTimes(1);
});
it("Should insert a newline character when shift enter is pressed when ctrlEnterToSend is false", async () => {
@ -155,7 +155,7 @@ describe("PlainTextComposer", () => {
await userEvent.type(textBox, inputWithShiftEnter);
// Then it does not send a message, but inserts a newline character
expect(onSend).toBeCalledTimes(0);
expect(onSend).toHaveBeenCalledTimes(0);
expect(textBox.innerHTML).toBe(expectedInnerHtml);
});
@ -172,7 +172,7 @@ describe("PlainTextComposer", () => {
await userEvent.type(textBox, keyboardInput);
// Then it does not send a message, but inserts a newline character
expect(onSend).toBeCalledTimes(0);
expect(onSend).toHaveBeenCalledTimes(0);
expect(textBox.innerHTML).toBe(expectedInnerHtml);
});
@ -188,7 +188,7 @@ describe("PlainTextComposer", () => {
await userEvent.type(textBox, "{enter}hello");
// Then it does not send a message, but inserts a newline character
expect(onSend).toBeCalledTimes(0);
expect(onSend).toHaveBeenCalledTimes(0);
expect(textBox).not.toContainHTML(enterThenTypeHtml);
});
@ -204,7 +204,7 @@ describe("PlainTextComposer", () => {
await userEvent.type(textBox, "{enter}");
// Then it does not send a message, but inserts a newline character
expect(onSend).toBeCalledTimes(0);
expect(onSend).toHaveBeenCalledTimes(0);
expect(textBox).not.toContainHTML(defaultEnterHtml);
});

View file

@ -88,10 +88,10 @@ describe("WysiwygComposer", () => {
});
// Then
await waitFor(() => expect(onChange).toBeCalledWith("foo bar"));
await waitFor(() => expect(onChange).toHaveBeenCalledWith("foo bar"));
});
it("Should call onSend when Enter is pressed ", async () => {
it("Should call onSend when Enter is pressed", async () => {
//When
fireEvent(
screen.getByRole("textbox"),
@ -101,18 +101,18 @@ describe("WysiwygComposer", () => {
);
// Then it sends a message
await waitFor(() => expect(onSend).toBeCalledTimes(1));
await waitFor(() => expect(onSend).toHaveBeenCalledTimes(1));
});
it("Should not call onSend when Shift+Enter is pressed ", async () => {
it("Should not call onSend when Shift+Enter is pressed", async () => {
//When
await userEvent.type(screen.getByRole("textbox"), "{shift>}{enter}");
// Then it sends a message
await waitFor(() => expect(onSend).toBeCalledTimes(0));
await waitFor(() => expect(onSend).toHaveBeenCalledTimes(0));
});
it("Should not call onSend when ctrl+Enter is pressed ", async () => {
it("Should not call onSend when ctrl+Enter is pressed", async () => {
//When
// Using userEvent.type or .keyboard wasn't working as expected in the case of ctrl+enter
fireEvent(
@ -124,23 +124,23 @@ describe("WysiwygComposer", () => {
);
// Then it sends a message
await waitFor(() => expect(onSend).toBeCalledTimes(0));
await waitFor(() => expect(onSend).toHaveBeenCalledTimes(0));
});
it("Should not call onSend when alt+Enter is pressed ", async () => {
it("Should not call onSend when alt+Enter is pressed", async () => {
//When
await userEvent.type(screen.getByRole("textbox"), "{alt>}{enter}");
// Then it sends a message
await waitFor(() => expect(onSend).toBeCalledTimes(0));
await waitFor(() => expect(onSend).toHaveBeenCalledTimes(0));
});
it("Should not call onSend when meta+Enter is pressed ", async () => {
it("Should not call onSend when meta+Enter is pressed", async () => {
//When
await userEvent.type(screen.getByRole("textbox"), "{meta>}{enter}");
// Then it sends a message
await waitFor(() => expect(onSend).toBeCalledTimes(0));
await waitFor(() => expect(onSend).toHaveBeenCalledTimes(0));
});
});
@ -172,7 +172,7 @@ describe("WysiwygComposer", () => {
);
// Then it does not send a message
await waitFor(() => expect(onSend).toBeCalledTimes(0));
await waitFor(() => expect(onSend).toHaveBeenCalledTimes(0));
fireEvent(
textbox,
@ -201,7 +201,7 @@ describe("WysiwygComposer", () => {
);
// Then it sends a message
await waitFor(() => expect(onSend).toBeCalledTimes(1));
await waitFor(() => expect(onSend).toHaveBeenCalledTimes(1));
});
});
@ -269,7 +269,7 @@ describe("WysiwygComposer", () => {
});
// Then
expect(spyDispatcher).toBeCalledTimes(0);
expect(spyDispatcher).toHaveBeenCalledTimes(0);
});
it("Should moving when the composer is empty", async () => {
@ -281,7 +281,7 @@ describe("WysiwygComposer", () => {
});
// Then
expect(spyDispatcher).toBeCalledWith({
expect(spyDispatcher).toHaveBeenCalledWith({
action: Action.EditEvent,
event: mockEvent,
timelineRenderingType: defaultRoomContext.timelineRenderingType,
@ -316,7 +316,7 @@ describe("WysiwygComposer", () => {
});
// Then
expect(spyDispatcher).toBeCalledTimes(0);
expect(spyDispatcher).toHaveBeenCalledTimes(0);
});
it("Should not moving when the content has changed", async () => {
@ -340,7 +340,7 @@ describe("WysiwygComposer", () => {
});
// Then
expect(spyDispatcher).toBeCalledTimes(0);
expect(spyDispatcher).toHaveBeenCalledTimes(0);
});
it("Should moving up", async () => {
@ -366,7 +366,7 @@ describe("WysiwygComposer", () => {
// Then
await waitFor(() =>
expect(spyDispatcher).toBeCalledWith({
expect(spyDispatcher).toHaveBeenCalledWith({
action: Action.EditEvent,
event: mockEvent,
timelineRenderingType: defaultRoomContext.timelineRenderingType,
@ -401,7 +401,7 @@ describe("WysiwygComposer", () => {
});
// Then
expect(spyDispatcher).toBeCalledWith({
expect(spyDispatcher).toHaveBeenCalledWith({
action: Action.EditEvent,
event: mockEvent,
timelineRenderingType: defaultRoomContext.timelineRenderingType,
@ -427,7 +427,7 @@ describe("WysiwygComposer", () => {
});
// Then
expect(spyDispatcher).toBeCalledTimes(0);
expect(spyDispatcher).toHaveBeenCalledTimes(0);
});
it("Should not moving when the content has changed", async () => {
@ -451,7 +451,7 @@ describe("WysiwygComposer", () => {
});
// Then
expect(spyDispatcher).toBeCalledTimes(0);
expect(spyDispatcher).toHaveBeenCalledTimes(0);
});
it("Should moving down", async () => {
@ -479,7 +479,7 @@ describe("WysiwygComposer", () => {
// Then
await waitFor(() =>
expect(spyDispatcher).toBeCalledWith({
expect(spyDispatcher).toHaveBeenCalledWith({
action: Action.EditEvent,
event: mockEvent,
timelineRenderingType: defaultRoomContext.timelineRenderingType,
@ -516,7 +516,7 @@ describe("WysiwygComposer", () => {
});
// Then
expect(spyDispatcher).toBeCalledWith({
expect(spyDispatcher).toHaveBeenCalledWith({
action: Action.EditEvent,
event: mockEvent,
timelineRenderingType: defaultRoomContext.timelineRenderingType,
@ -549,7 +549,7 @@ describe("WysiwygComposer", () => {
// Then
await waitFor(() =>
expect(spyDispatcher).toBeCalledWith({
expect(spyDispatcher).toHaveBeenCalledWith({
action: Action.EditEvent,
event: null,
timelineRenderingType: defaultRoomContext.timelineRenderingType,

View file

@ -66,8 +66,8 @@ describe("message", () => {
await sendMessage("", true, { roomContext: defaultRoomContext, mxClient: mockClient, permalinkCreator });
// Then
expect(mockClient.sendMessage).toBeCalledTimes(0);
expect(spyDispatcher).toBeCalledTimes(0);
expect(mockClient.sendMessage).toHaveBeenCalledTimes(0);
expect(spyDispatcher).toHaveBeenCalledTimes(0);
});
it("Should not send message when there is no roomId", async () => {
@ -82,8 +82,8 @@ describe("message", () => {
});
// Then
expect(mockClient.sendMessage).toBeCalledTimes(0);
expect(spyDispatcher).toBeCalledTimes(0);
expect(mockClient.sendMessage).toHaveBeenCalledTimes(0);
expect(spyDispatcher).toHaveBeenCalledTimes(0);
});
describe("calls client.sendMessage with", () => {
@ -108,7 +108,7 @@ describe("message", () => {
});
// Then
expect(mockClient.sendMessage).toBeCalledWith(expect.anything(), null, expect.anything());
expect(mockClient.sendMessage).toHaveBeenCalledWith(expect.anything(), null, expect.anything());
});
it("a null argument if SendMessageParams has relation but rel_type does not match THREAD_RELATION_TYPE.name", async () => {
// When
@ -123,7 +123,7 @@ describe("message", () => {
});
// Then
expect(mockClient.sendMessage).toBeCalledWith(expect.anything(), null, expect.anything());
expect(mockClient.sendMessage).toHaveBeenCalledWith(expect.anything(), null, expect.anything());
});
it("the event_id if SendMessageParams has relation and rel_type matches THREAD_RELATION_TYPE.name", async () => {
@ -139,7 +139,7 @@ describe("message", () => {
});
// Then
expect(mockClient.sendMessage).toBeCalledWith(expect.anything(), "valid_id", expect.anything());
expect(mockClient.sendMessage).toHaveBeenCalledWith(expect.anything(), "valid_id", expect.anything());
});
});
@ -158,8 +158,8 @@ describe("message", () => {
formatted_body: "<i><b>hello</b> world</i>",
msgtype: "m.text",
};
expect(mockClient.sendMessage).toBeCalledWith("myfakeroom", null, expectedContent);
expect(spyDispatcher).toBeCalledWith({ action: "message_sent" });
expect(mockClient.sendMessage).toHaveBeenCalledWith("myfakeroom", null, expectedContent);
expect(spyDispatcher).toHaveBeenCalledWith({ action: "message_sent" });
});
it("Should send reply to html message", async () => {
@ -180,7 +180,7 @@ describe("message", () => {
});
// Then
expect(spyDispatcher).toBeCalledWith({
expect(spyDispatcher).toHaveBeenCalledWith({
action: "reply_to_event",
event: null,
context: defaultRoomContext.timelineRenderingType,
@ -200,7 +200,7 @@ describe("message", () => {
},
},
};
expect(mockClient.sendMessage).toBeCalledWith("myfakeroom", null, expectedContent);
expect(mockClient.sendMessage).toHaveBeenCalledWith("myfakeroom", null, expectedContent);
});
it("Should scroll to bottom after sending a html message", async () => {
@ -213,7 +213,7 @@ describe("message", () => {
});
// Then
expect(spyDispatcher).toBeCalledWith({
expect(spyDispatcher).toHaveBeenCalledWith({
action: "scroll_to_bottom",
timelineRenderingType: defaultRoomContext.timelineRenderingType,
});
@ -224,7 +224,7 @@ describe("message", () => {
await sendMessage("🎉", false, { roomContext: defaultRoomContext, mxClient: mockClient, permalinkCreator });
// Then
expect(spyDispatcher).toBeCalledWith({ action: "effects.confetti" });
expect(spyDispatcher).toHaveBeenCalledWith({ action: "effects.confetti" });
});
});
@ -256,10 +256,10 @@ describe("message", () => {
await editMessage("", { roomContext: defaultRoomContext, mxClient: mockClient, editorStateTransfer });
// Then
expect(mockClient.sendMessage).toBeCalledTimes(0);
expect(mockClient.cancelPendingEvent).toBeCalledTimes(1);
expect(mockCreateRedactEventDialog).toBeCalledTimes(1);
expect(spyDispatcher).toBeCalledTimes(0);
expect(mockClient.sendMessage).toHaveBeenCalledTimes(0);
expect(mockClient.cancelPendingEvent).toHaveBeenCalledTimes(1);
expect(mockCreateRedactEventDialog).toHaveBeenCalledTimes(1);
expect(spyDispatcher).toHaveBeenCalledTimes(0);
});
it("Should do nothing if the content is unmodified", async () => {
@ -271,7 +271,7 @@ describe("message", () => {
});
// Then
expect(mockClient.sendMessage).toBeCalledTimes(0);
expect(mockClient.sendMessage).toHaveBeenCalledTimes(0);
});
it("Should send a message when the content is modified", async () => {
@ -301,8 +301,8 @@ describe("message", () => {
msgtype,
format,
};
expect(mockClient.sendMessage).toBeCalledWith(mockEvent.getRoomId(), null, expectedContent);
expect(spyDispatcher).toBeCalledWith({ action: "message_sent" });
expect(mockClient.sendMessage).toHaveBeenCalledWith(mockEvent.getRoomId(), null, expectedContent);
expect(spyDispatcher).toHaveBeenCalledWith({ action: "message_sent" });
});
});
});