2022-06-02 11:25:56 +03:00
|
|
|
/*
|
2023-02-20 17:46:07 +03:00
|
|
|
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
2022-06-02 11:25:56 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
2023-01-05 10:40:09 +03:00
|
|
|
import { act, render, fireEvent } from "@testing-library/react";
|
2023-08-14 11:58:55 +03:00
|
|
|
import {
|
|
|
|
EventType,
|
|
|
|
EventStatus,
|
|
|
|
MatrixEvent,
|
|
|
|
MatrixEventEvent,
|
|
|
|
MsgType,
|
|
|
|
Room,
|
|
|
|
FeatureSupport,
|
|
|
|
Thread,
|
|
|
|
} from "matrix-js-sdk/src/matrix";
|
2022-12-12 14:24:14 +03:00
|
|
|
|
2022-06-02 11:25:56 +03:00
|
|
|
import MessageActionBar from "../../../../src/components/views/messages/MessageActionBar";
|
|
|
|
import {
|
|
|
|
getMockClientWithEventEmitter,
|
|
|
|
mockClientMethodsUser,
|
|
|
|
mockClientMethodsEvents,
|
2022-06-02 18:43:19 +03:00
|
|
|
makeBeaconInfoEvent,
|
2022-06-02 11:25:56 +03:00
|
|
|
} from "../../../test-utils";
|
|
|
|
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
|
|
|
import RoomContext, { TimelineRenderingType } from "../../../../src/contexts/RoomContext";
|
|
|
|
import { IRoomState } from "../../../../src/components/structures/RoomView";
|
|
|
|
import dispatcher from "../../../../src/dispatcher/dispatcher";
|
|
|
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
2022-06-02 18:43:19 +03:00
|
|
|
import { Action } from "../../../../src/dispatcher/actions";
|
2022-12-12 14:24:14 +03:00
|
|
|
|
2022-06-02 11:25:56 +03:00
|
|
|
jest.mock("../../../../src/dispatcher/dispatcher");
|
2022-12-12 14:24:14 +03:00
|
|
|
|
2022-06-02 11:25:56 +03:00
|
|
|
describe("<MessageActionBar />", () => {
|
|
|
|
const userId = "@alice:server.org";
|
|
|
|
const roomId = "!room:server.org";
|
|
|
|
const alicesMessageEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
room_id: roomId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
|
|
|
body: "Hello",
|
|
|
|
},
|
2022-07-15 22:55:11 +03:00
|
|
|
event_id: "$alices_message",
|
2022-06-02 11:25:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const bobsMessageEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: "@bob:server.org",
|
|
|
|
room_id: roomId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
|
|
|
body: "I am bob",
|
|
|
|
},
|
2022-07-15 22:55:11 +03:00
|
|
|
event_id: "$bobs_message",
|
2022-06-02 11:25:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const redactedEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
});
|
|
|
|
redactedEvent.makeRedacted(redactedEvent);
|
|
|
|
|
|
|
|
const client = getMockClientWithEventEmitter({
|
|
|
|
...mockClientMethodsUser(userId),
|
|
|
|
...mockClientMethodsEvents(),
|
|
|
|
getRoom: jest.fn(),
|
|
|
|
});
|
2022-07-15 22:55:11 +03:00
|
|
|
|
|
|
|
const localStorageMock = (() => {
|
2023-02-13 14:39:16 +03:00
|
|
|
let store: Record<string, any> = {};
|
2022-07-15 22:55:11 +03:00
|
|
|
return {
|
|
|
|
getItem: jest.fn().mockImplementation((key) => store[key] ?? null),
|
|
|
|
setItem: jest.fn().mockImplementation((key, value) => {
|
|
|
|
store[key] = value;
|
|
|
|
}),
|
|
|
|
clear: jest.fn().mockImplementation(() => {
|
|
|
|
store = {};
|
|
|
|
}),
|
|
|
|
removeItem: jest.fn().mockImplementation((key) => delete store[key]),
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
Object.defineProperty(window, "localStorage", {
|
|
|
|
value: localStorageMock,
|
|
|
|
writable: true,
|
|
|
|
});
|
|
|
|
|
2022-06-02 11:25:56 +03:00
|
|
|
const room = new Room(roomId, client, userId);
|
|
|
|
jest.spyOn(room, "getPendingEvents").mockReturnValue([]);
|
|
|
|
|
|
|
|
client.getRoom.mockReturnValue(room);
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
getTile: jest.fn(),
|
|
|
|
getReplyChain: jest.fn(),
|
|
|
|
toggleThreadExpanded: jest.fn(),
|
|
|
|
mxEvent: alicesMessageEvent,
|
|
|
|
permalinkCreator: new RoomPermalinkCreator(room),
|
|
|
|
};
|
|
|
|
const defaultRoomContext = {
|
|
|
|
...RoomContext,
|
|
|
|
timelineRenderingType: TimelineRenderingType.Room,
|
|
|
|
canSendMessages: true,
|
|
|
|
canReact: true,
|
|
|
|
} as unknown as IRoomState;
|
|
|
|
const getComponent = (props = {}, roomContext: Partial<IRoomState> = {}) =>
|
|
|
|
render(
|
|
|
|
<RoomContext.Provider value={{ ...defaultRoomContext, ...roomContext }}>
|
|
|
|
<MessageActionBar {...defaultProps} {...props} />
|
|
|
|
</RoomContext.Provider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
alicesMessageEvent.setStatus(EventStatus.SENT);
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
|
|
|
|
jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockRestore();
|
|
|
|
jest.spyOn(SettingsStore, "setValue").mockRestore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("kills event listeners on unmount", () => {
|
|
|
|
const offSpy = jest.spyOn(alicesMessageEvent, "off").mockClear();
|
|
|
|
const wrapper = getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
|
|
|
|
act(() => {
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(offSpy.mock.calls[0][0]).toEqual(MatrixEventEvent.Status);
|
|
|
|
expect(offSpy.mock.calls[1][0]).toEqual(MatrixEventEvent.Decrypted);
|
|
|
|
expect(offSpy.mock.calls[2][0]).toEqual(MatrixEventEvent.BeforeRedaction);
|
|
|
|
|
|
|
|
expect(client.decryptEventIfNeeded).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("decryption", () => {
|
|
|
|
it("decrypts event if needed", () => {
|
|
|
|
getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
expect(client.decryptEventIfNeeded).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("updates component on decrypted event", () => {
|
|
|
|
const decryptingEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessageEncrypted,
|
|
|
|
sender: userId,
|
|
|
|
room_id: roomId,
|
|
|
|
content: {},
|
|
|
|
});
|
|
|
|
jest.spyOn(decryptingEvent, "isBeingDecrypted").mockReturnValue(true);
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: decryptingEvent });
|
|
|
|
|
|
|
|
// still encrypted event is not actionable => no reply button
|
|
|
|
expect(queryByLabelText("Reply")).toBeFalsy();
|
|
|
|
|
|
|
|
act(() => {
|
|
|
|
// ''decrypt'' the event
|
|
|
|
decryptingEvent.event.type = alicesMessageEvent.getType();
|
|
|
|
decryptingEvent.event.content = alicesMessageEvent.getContent();
|
|
|
|
decryptingEvent.emit(MatrixEventEvent.Decrypted, decryptingEvent);
|
|
|
|
});
|
|
|
|
|
|
|
|
// new available actions after decryption
|
|
|
|
expect(queryByLabelText("Reply")).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("status", () => {
|
|
|
|
it("updates component when event status changes", () => {
|
|
|
|
alicesMessageEvent.setStatus(EventStatus.QUEUED);
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
|
|
|
|
// pending event status, cancel action available
|
|
|
|
expect(queryByLabelText("Delete")).toBeTruthy();
|
|
|
|
|
|
|
|
act(() => {
|
|
|
|
alicesMessageEvent.setStatus(EventStatus.SENT);
|
|
|
|
});
|
|
|
|
|
|
|
|
// event is sent, no longer cancelable
|
|
|
|
expect(queryByLabelText("Delete")).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("redaction", () => {
|
|
|
|
// this doesn't do what it's supposed to
|
|
|
|
// because beforeRedaction event is fired... before redaction
|
|
|
|
// event is unchanged at point when this component updates
|
|
|
|
// TODO file bug
|
2023-03-01 18:23:35 +03:00
|
|
|
it.skip("updates component on before redaction event", () => {
|
2022-06-02 11:25:56 +03:00
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
room_id: roomId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
|
|
|
body: "Hello",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: event });
|
|
|
|
|
|
|
|
// no pending redaction => no delete button
|
|
|
|
expect(queryByLabelText("Delete")).toBeFalsy();
|
|
|
|
|
|
|
|
act(() => {
|
|
|
|
const redactionEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomRedaction,
|
|
|
|
sender: userId,
|
|
|
|
room_id: roomId,
|
|
|
|
});
|
|
|
|
redactionEvent.setStatus(EventStatus.QUEUED);
|
|
|
|
event.markLocallyRedacted(redactionEvent);
|
|
|
|
});
|
|
|
|
|
|
|
|
// updated with local redaction event, delete now available
|
|
|
|
expect(queryByLabelText("Delete")).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("options button", () => {
|
|
|
|
it("renders options menu", () => {
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
expect(queryByLabelText("Options")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("opens message context menu on click", () => {
|
2022-08-18 10:18:18 +03:00
|
|
|
const { getByTestId, queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
2023-02-15 16:36:22 +03:00
|
|
|
fireEvent.click(queryByLabelText("Options")!);
|
2022-08-18 10:18:18 +03:00
|
|
|
expect(getByTestId("mx_MessageContextMenu")).toBeTruthy();
|
2022-06-02 11:25:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("reply button", () => {
|
|
|
|
it("renders reply button on own actionable event", () => {
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
expect(queryByLabelText("Reply")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders reply button on others actionable event", () => {
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: bobsMessageEvent }, { canSendMessages: true });
|
|
|
|
expect(queryByLabelText("Reply")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not render reply button on non-actionable event", () => {
|
|
|
|
// redacted event is not actionable
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: redactedEvent });
|
|
|
|
expect(queryByLabelText("Reply")).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not render reply button when user cannot send messaged", () => {
|
|
|
|
// redacted event is not actionable
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: redactedEvent }, { canSendMessages: false });
|
|
|
|
expect(queryByLabelText("Reply")).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("dispatches reply event on click", () => {
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
fireEvent.click(queryByLabelText("Reply")!);
|
2022-06-02 11:25:56 +03:00
|
|
|
|
|
|
|
expect(dispatcher.dispatch).toHaveBeenCalledWith({
|
|
|
|
action: "reply_to_event",
|
|
|
|
event: alicesMessageEvent,
|
|
|
|
context: TimelineRenderingType.Room,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("react button", () => {
|
|
|
|
it("renders react button on own actionable event", () => {
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
expect(queryByLabelText("React")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders react button on others actionable event", () => {
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: bobsMessageEvent });
|
|
|
|
expect(queryByLabelText("React")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not render react button on non-actionable event", () => {
|
|
|
|
// redacted event is not actionable
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: redactedEvent });
|
|
|
|
expect(queryByLabelText("React")).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not render react button when user cannot react", () => {
|
|
|
|
// redacted event is not actionable
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: redactedEvent }, { canReact: false });
|
|
|
|
expect(queryByLabelText("React")).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("opens reaction picker on click", () => {
|
2022-08-18 10:18:18 +03:00
|
|
|
const { queryByLabelText, getByTestId } = getComponent({ mxEvent: alicesMessageEvent });
|
2023-02-15 16:36:22 +03:00
|
|
|
fireEvent.click(queryByLabelText("React")!);
|
2022-08-18 10:18:18 +03:00
|
|
|
expect(getByTestId("mx_EmojiPicker")).toBeTruthy();
|
2022-06-02 11:25:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("cancel button", () => {
|
|
|
|
it("renders cancel button for an event with a cancelable status", () => {
|
|
|
|
alicesMessageEvent.setStatus(EventStatus.QUEUED);
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
expect(queryByLabelText("Delete")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders cancel button for an event with a pending edit", () => {
|
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
room_id: roomId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
|
|
|
body: "Hello",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
event.setStatus(EventStatus.SENT);
|
|
|
|
const replacingEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
room_id: roomId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
|
|
|
body: "replacing event body",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
replacingEvent.setStatus(EventStatus.QUEUED);
|
|
|
|
event.makeReplaced(replacingEvent);
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: event });
|
|
|
|
expect(queryByLabelText("Delete")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders cancel button for an event with a pending redaction", () => {
|
|
|
|
const event = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
room_id: roomId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
|
|
|
body: "Hello",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
event.setStatus(EventStatus.SENT);
|
|
|
|
|
|
|
|
const redactionEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomRedaction,
|
|
|
|
sender: userId,
|
|
|
|
room_id: roomId,
|
|
|
|
});
|
|
|
|
redactionEvent.setStatus(EventStatus.QUEUED);
|
|
|
|
|
|
|
|
event.markLocallyRedacted(redactionEvent);
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: event });
|
|
|
|
expect(queryByLabelText("Delete")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders cancel and retry button for an event with NOT_SENT status", () => {
|
|
|
|
alicesMessageEvent.setStatus(EventStatus.NOT_SENT);
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
expect(queryByLabelText("Retry")).toBeTruthy();
|
|
|
|
expect(queryByLabelText("Delete")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it.todo("unsends event on cancel click");
|
|
|
|
it.todo("retrys event on retry click");
|
|
|
|
});
|
2022-06-02 18:43:19 +03:00
|
|
|
|
|
|
|
describe("thread button", () => {
|
|
|
|
beforeEach(() => {
|
2022-10-06 11:35:06 +03:00
|
|
|
Thread.setServerSideSupport(FeatureSupport.Stable);
|
2022-06-02 18:43:19 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("when threads feature is enabled", () => {
|
|
|
|
it("renders thread button on own actionable event", () => {
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
expect(queryByLabelText("Reply in thread")).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not render thread button for a beacon_info event", () => {
|
|
|
|
const beaconInfoEvent = makeBeaconInfoEvent(userId, roomId);
|
|
|
|
const { queryByLabelText } = getComponent({ mxEvent: beaconInfoEvent });
|
|
|
|
expect(queryByLabelText("Reply in thread")).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("opens thread on click", () => {
|
|
|
|
const { getByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
fireEvent.click(getByLabelText("Reply in thread"));
|
2022-06-02 18:43:19 +03:00
|
|
|
|
2022-07-23 15:13:49 +03:00
|
|
|
expect(dispatcher.dispatch).toHaveBeenCalledWith({
|
|
|
|
action: Action.ShowThread,
|
2022-06-02 18:43:19 +03:00
|
|
|
rootEvent: alicesMessageEvent,
|
|
|
|
push: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("opens parent thread for a thread reply message", () => {
|
|
|
|
const threadReplyEvent = new MatrixEvent({
|
|
|
|
type: EventType.RoomMessage,
|
|
|
|
sender: userId,
|
|
|
|
room_id: roomId,
|
|
|
|
content: {
|
|
|
|
msgtype: MsgType.Text,
|
|
|
|
body: "this is a thread reply",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
// mock the thread stuff
|
2022-06-07 13:16:54 +03:00
|
|
|
jest.spyOn(threadReplyEvent, "isThreadRoot", "get").mockReturnValue(false);
|
2022-06-02 18:43:19 +03:00
|
|
|
// set alicesMessageEvent as the root event
|
|
|
|
jest.spyOn(threadReplyEvent, "getThread").mockReturnValue({
|
|
|
|
rootEvent: alicesMessageEvent,
|
|
|
|
} as unknown as Thread);
|
|
|
|
const { getByLabelText } = getComponent({ mxEvent: threadReplyEvent });
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
fireEvent.click(getByLabelText("Reply in thread"));
|
2022-06-02 18:43:19 +03:00
|
|
|
|
2022-07-23 15:13:49 +03:00
|
|
|
expect(dispatcher.dispatch).toHaveBeenCalledWith({
|
|
|
|
action: Action.ShowThread,
|
2022-06-02 18:43:19 +03:00
|
|
|
rootEvent: alicesMessageEvent,
|
|
|
|
initialEvent: threadReplyEvent,
|
|
|
|
highlighted: true,
|
|
|
|
scroll_into_view: true,
|
|
|
|
push: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-07-15 22:55:11 +03:00
|
|
|
|
2023-06-15 14:02:45 +03:00
|
|
|
it.each([["React"], ["Reply"], ["Reply in thread"], ["Edit"]])(
|
2022-08-18 10:18:18 +03:00
|
|
|
"does not show context menu when right-clicking",
|
|
|
|
(buttonLabel: string) => {
|
|
|
|
// For favourite button
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockReturnValue(true);
|
|
|
|
|
|
|
|
const event = new MouseEvent("contextmenu", {
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true,
|
2022-12-12 14:24:14 +03:00
|
|
|
});
|
2022-08-18 10:18:18 +03:00
|
|
|
event.stopPropagation = jest.fn();
|
|
|
|
event.preventDefault = jest.fn();
|
2022-12-12 14:24:14 +03:00
|
|
|
|
2022-08-18 10:18:18 +03:00
|
|
|
const { queryByTestId, queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
2023-02-15 16:36:22 +03:00
|
|
|
fireEvent(queryByLabelText(buttonLabel)!, event);
|
2022-08-18 10:18:18 +03:00
|
|
|
expect(event.stopPropagation).toHaveBeenCalled();
|
|
|
|
expect(event.preventDefault).toHaveBeenCalled();
|
|
|
|
expect(queryByTestId("mx_MessageContextMenu")).toBeFalsy();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it("does shows context menu when right-clicking options", () => {
|
|
|
|
const { queryByTestId, queryByLabelText } = getComponent({ mxEvent: alicesMessageEvent });
|
2023-02-15 16:36:22 +03:00
|
|
|
fireEvent.contextMenu(queryByLabelText("Options")!);
|
2022-08-18 10:18:18 +03:00
|
|
|
expect(queryByTestId("mx_MessageContextMenu")).toBeTruthy();
|
|
|
|
});
|
2022-06-02 11:25:56 +03:00
|
|
|
});
|