2022-03-04 15:53:22 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-03-04 15:53:22 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-03-04 15:53:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import * as React from "react";
|
2023-08-14 08:58:55 +00:00
|
|
|
import { EventType, MatrixEvent, Room, RoomMember, THREAD_RELATION_TYPE } from "matrix-js-sdk/src/matrix";
|
2024-08-22 12:54:01 +00:00
|
|
|
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
2023-01-10 14:51:20 +00:00
|
|
|
import userEvent from "@testing-library/user-event";
|
|
|
|
|
|
|
|
import {
|
2023-03-24 19:39:24 +00:00
|
|
|
clearAllModals,
|
2023-01-10 14:51:20 +00:00
|
|
|
createTestClient,
|
|
|
|
flushPromises,
|
|
|
|
mkEvent,
|
|
|
|
mkStubRoom,
|
|
|
|
mockPlatformPeg,
|
|
|
|
stubClient,
|
2023-03-24 19:39:24 +00:00
|
|
|
waitEnoughCyclesForModal,
|
2023-01-10 14:51:20 +00:00
|
|
|
} from "../../../test-utils";
|
|
|
|
import MessageComposer from "../../../../src/components/views/rooms/MessageComposer";
|
2022-03-04 15:53:22 +00:00
|
|
|
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
|
|
|
import RoomContext from "../../../../src/contexts/RoomContext";
|
2022-03-21 09:03:03 +00:00
|
|
|
import { IRoomState } from "../../../../src/components/structures/RoomView";
|
|
|
|
import ResizeNotifier from "../../../../src/utils/ResizeNotifier";
|
|
|
|
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
2022-08-11 15:51:24 +00:00
|
|
|
import { LocalRoom } from "../../../../src/models/LocalRoom";
|
2022-09-16 09:10:33 +00:00
|
|
|
import { Features } from "../../../../src/settings/Settings";
|
|
|
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
|
|
|
import { SettingLevel } from "../../../../src/settings/SettingLevel";
|
|
|
|
import dis from "../../../../src/dispatcher/dispatcher";
|
|
|
|
import { E2EStatus } from "../../../../src/utils/ShieldUtils";
|
2023-01-10 14:51:20 +00:00
|
|
|
import { addTextToComposerRTL } from "../../../test-utils/composer";
|
2022-09-16 09:10:33 +00:00
|
|
|
import UIStore, { UI_EVENTS } from "../../../../src/stores/UIStore";
|
2023-01-10 14:51:20 +00:00
|
|
|
import { Action } from "../../../../src/dispatcher/actions";
|
|
|
|
import { VoiceBroadcastInfoState, VoiceBroadcastRecording } from "../../../../src/voice-broadcast";
|
|
|
|
import { mkVoiceBroadcastInfoStateEvent } from "../../../voice-broadcast/utils/test-utils";
|
|
|
|
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
|
|
|
|
|
|
|
const openStickerPicker = async (): Promise<void> => {
|
|
|
|
await act(async () => {
|
|
|
|
await userEvent.click(screen.getByLabelText("More options"));
|
|
|
|
await userEvent.click(screen.getByLabelText("Sticker"));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const startVoiceMessage = async (): Promise<void> => {
|
|
|
|
await act(async () => {
|
|
|
|
await userEvent.click(screen.getByLabelText("More options"));
|
|
|
|
await userEvent.click(screen.getByLabelText("Voice Message"));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const setCurrentBroadcastRecording = (room: Room, state: VoiceBroadcastInfoState): void => {
|
|
|
|
const recording = new VoiceBroadcastRecording(
|
|
|
|
mkVoiceBroadcastInfoStateEvent(room.roomId, state, "@user:example.com", "ABC123"),
|
2023-06-05 17:12:23 +00:00
|
|
|
MatrixClientPeg.safeGet(),
|
2023-01-10 14:51:20 +00:00
|
|
|
state,
|
|
|
|
);
|
|
|
|
SdkContextClass.instance.voiceBroadcastRecordingsStore.setCurrent(recording);
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectVoiceMessageRecordingTriggered = (): void => {
|
|
|
|
// Checking for the voice message dialog text, if no mic can be found.
|
|
|
|
// By this we know at least that starting a voice message was triggered.
|
|
|
|
expect(screen.getByText("No microphone found")).toBeInTheDocument();
|
|
|
|
};
|
2022-10-10 15:36:18 +00:00
|
|
|
|
2022-03-04 15:53:22 +00:00
|
|
|
describe("MessageComposer", () => {
|
|
|
|
stubClient();
|
|
|
|
const cli = createTestClient();
|
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
mockPlatformPeg();
|
|
|
|
});
|
|
|
|
|
2024-08-22 12:54:01 +00:00
|
|
|
afterEach(async () => {
|
|
|
|
await clearAllModals();
|
2023-01-10 14:51:20 +00:00
|
|
|
jest.useRealTimers();
|
|
|
|
|
|
|
|
SdkContextClass.instance.voiceBroadcastRecordingsStore.clearCurrent();
|
|
|
|
|
|
|
|
// restore settings
|
|
|
|
act(() => {
|
|
|
|
[
|
|
|
|
"MessageComposerInput.showStickersButton",
|
|
|
|
"MessageComposerInput.showPollsButton",
|
|
|
|
Features.VoiceBroadcast,
|
|
|
|
"feature_wysiwyg_composer",
|
|
|
|
].forEach((setting: string): void => {
|
|
|
|
SettingsStore.setValue(setting, null, SettingLevel.DEVICE, SettingsStore.getDefaultValue(setting));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-08-11 15:51:24 +00:00
|
|
|
describe("for a Room", () => {
|
|
|
|
const room = mkStubRoom("!roomId:server", "Room 1", cli);
|
|
|
|
|
|
|
|
it("Renders a SendMessageComposer and MessageComposerButtons by default", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
wrapAndRender({ room });
|
|
|
|
expect(screen.getByLabelText("Send a message…")).toBeInTheDocument();
|
2022-08-11 15:51:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Does not render a SendMessageComposer or MessageComposerButtons when user has no permission", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
wrapAndRender({ room }, false);
|
|
|
|
expect(screen.queryByLabelText("Send a message…")).not.toBeInTheDocument();
|
|
|
|
expect(screen.getByText("You do not have permission to post to this room")).toBeInTheDocument();
|
2022-08-11 15:51:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Does not render a SendMessageComposer or MessageComposerButtons when room is tombstoned", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
wrapAndRender(
|
2022-12-12 11:24:14 +00:00
|
|
|
{ room },
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "m.room.tombstone",
|
|
|
|
room: room.roomId,
|
|
|
|
user: "@user1:server",
|
|
|
|
skey: "",
|
|
|
|
content: {},
|
|
|
|
ts: Date.now(),
|
|
|
|
}),
|
|
|
|
);
|
2022-08-11 15:51:24 +00:00
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
expect(screen.queryByLabelText("Send a message…")).not.toBeInTheDocument();
|
|
|
|
expect(screen.getByText("This room has been replaced and is no longer active.")).toBeInTheDocument();
|
2022-08-11 15:51:24 +00:00
|
|
|
});
|
2022-09-16 09:10:33 +00:00
|
|
|
|
|
|
|
describe("when receiving a »reply_to_event«", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
let roomContext: IRoomState;
|
2022-09-16 09:10:33 +00:00
|
|
|
let resizeNotifier: ResizeNotifier;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
resizeNotifier = {
|
|
|
|
notifyTimelineHeightChanged: jest.fn(),
|
|
|
|
} as unknown as ResizeNotifier;
|
2023-01-10 14:51:20 +00:00
|
|
|
roomContext = wrapAndRender({
|
2022-09-16 09:10:33 +00:00
|
|
|
room,
|
|
|
|
resizeNotifier,
|
2023-01-10 14:51:20 +00:00
|
|
|
}).roomContext;
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should call notifyTimelineHeightChanged() for the same context", () => {
|
|
|
|
dis.dispatch({
|
|
|
|
action: "reply_to_event",
|
2023-01-10 14:51:20 +00:00
|
|
|
context: roomContext.timelineRenderingType,
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
jest.advanceTimersByTime(150);
|
|
|
|
expect(resizeNotifier.notifyTimelineHeightChanged).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not call notifyTimelineHeightChanged() for a different context", () => {
|
|
|
|
dis.dispatch({
|
|
|
|
action: "reply_to_event",
|
|
|
|
context: "test",
|
|
|
|
});
|
|
|
|
|
|
|
|
jest.advanceTimersByTime(150);
|
|
|
|
expect(resizeNotifier.notifyTimelineHeightChanged).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// test button display depending on settings
|
|
|
|
[
|
|
|
|
{
|
|
|
|
setting: "MessageComposerInput.showStickersButton",
|
2023-01-10 14:51:20 +00:00
|
|
|
buttonLabel: "Sticker",
|
2022-09-16 09:10:33 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
setting: "MessageComposerInput.showPollsButton",
|
2023-01-10 14:51:20 +00:00
|
|
|
buttonLabel: "Poll",
|
2022-09-16 09:10:33 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
setting: Features.VoiceBroadcast,
|
2023-01-10 14:51:20 +00:00
|
|
|
buttonLabel: "Voice broadcast",
|
2022-09-16 09:10:33 +00:00
|
|
|
},
|
2023-01-10 14:51:20 +00:00
|
|
|
].forEach(({ setting, buttonLabel }) => {
|
2022-09-16 09:10:33 +00:00
|
|
|
[true, false].forEach((value: boolean) => {
|
|
|
|
describe(`when ${setting} = ${value}`, () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
beforeEach(async () => {
|
2022-09-16 09:10:33 +00:00
|
|
|
SettingsStore.setValue(setting, null, SettingLevel.DEVICE, value);
|
2023-01-10 14:51:20 +00:00
|
|
|
wrapAndRender({ room });
|
|
|
|
await act(async () => {
|
|
|
|
await userEvent.click(screen.getByLabelText("More options"));
|
|
|
|
});
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
it(`should${value || "not"} display the button`, () => {
|
|
|
|
if (value) {
|
2023-03-07 13:58:10 +00:00
|
|
|
// eslint-disable-next-line jest/no-conditional-expect
|
2023-01-10 14:51:20 +00:00
|
|
|
expect(screen.getByLabelText(buttonLabel)).toBeInTheDocument();
|
|
|
|
} else {
|
2023-03-07 13:58:10 +00:00
|
|
|
// eslint-disable-next-line jest/no-conditional-expect
|
2023-01-10 14:51:20 +00:00
|
|
|
expect(screen.queryByLabelText(buttonLabel)).not.toBeInTheDocument();
|
|
|
|
}
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe(`and setting ${setting} to ${!value}`, () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
// simulate settings update
|
|
|
|
await SettingsStore.setValue(setting, null, SettingLevel.DEVICE, !value);
|
2022-12-12 11:24:14 +00:00
|
|
|
dis.dispatch(
|
|
|
|
{
|
|
|
|
action: Action.SettingUpdated,
|
|
|
|
settingName: setting,
|
|
|
|
newValue: !value,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
it(`should${!value || "not"} display the button`, () => {
|
|
|
|
if (!value) {
|
2023-03-07 13:58:10 +00:00
|
|
|
// eslint-disable-next-line jest/no-conditional-expect
|
2023-01-10 14:51:20 +00:00
|
|
|
expect(screen.getByLabelText(buttonLabel)).toBeInTheDocument();
|
|
|
|
} else {
|
2023-03-07 13:58:10 +00:00
|
|
|
// eslint-disable-next-line jest/no-conditional-expect
|
2023-01-10 14:51:20 +00:00
|
|
|
expect(screen.queryByLabelText(buttonLabel)).not.toBeInTheDocument();
|
|
|
|
}
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not render the send button", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
wrapAndRender({ room });
|
|
|
|
expect(screen.queryByLabelText("Send message")).not.toBeInTheDocument();
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("when a message has been entered", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
const renderResult = wrapAndRender({ room }).renderResult;
|
|
|
|
await addTextToComposerRTL(renderResult, "Hello");
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should render the send button", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
expect(screen.getByLabelText("Send message")).toBeInTheDocument();
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("UIStore interactions", () => {
|
|
|
|
let resizeCallback: Function;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-05-12 08:49:37 +00:00
|
|
|
jest.spyOn(UIStore.instance, "on").mockImplementation(
|
|
|
|
(_event: string | symbol, listener: Function): any => {
|
|
|
|
resizeCallback = listener;
|
|
|
|
},
|
|
|
|
);
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("when a non-resize event occurred in UIStore", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
wrapAndRender({ room });
|
|
|
|
await openStickerPicker();
|
2022-09-16 09:10:33 +00:00
|
|
|
resizeCallback("test", {});
|
|
|
|
});
|
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
it("should still display the sticker picker", () => {
|
|
|
|
expect(screen.getByText("You don't currently have any stickerpacks enabled")).toBeInTheDocument();
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when a resize to narrow event occurred in UIStore", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
wrapAndRender({ room }, true, true);
|
|
|
|
await openStickerPicker();
|
2022-09-16 09:10:33 +00:00
|
|
|
resizeCallback(UI_EVENTS.Resize, {});
|
|
|
|
});
|
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
it("should close the menu", () => {
|
|
|
|
expect(screen.queryByLabelText("Sticker")).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not show the attachment button", () => {
|
|
|
|
expect(screen.queryByLabelText("Attachment")).not.toBeInTheDocument();
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
it("should close the sticker picker", () => {
|
|
|
|
expect(
|
|
|
|
screen.queryByText("You don't currently have any stickerpacks enabled"),
|
|
|
|
).not.toBeInTheDocument();
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when a resize to non-narrow event occurred in UIStore", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
wrapAndRender({ room }, true, false);
|
|
|
|
await openStickerPicker();
|
2022-09-16 09:10:33 +00:00
|
|
|
resizeCallback(UI_EVENTS.Resize, {});
|
|
|
|
});
|
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
it("should close the menu", () => {
|
|
|
|
expect(screen.queryByLabelText("Sticker")).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should show the attachment button", () => {
|
|
|
|
expect(screen.getByLabelText("Attachment")).toBeInTheDocument();
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
it("should close the sticker picker", () => {
|
|
|
|
expect(
|
|
|
|
screen.queryByText("You don't currently have any stickerpacks enabled"),
|
|
|
|
).not.toBeInTheDocument();
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when not replying to an event", () => {
|
|
|
|
it("should pass the expected placeholder to SendMessageComposer", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
wrapAndRender({ room });
|
|
|
|
expect(screen.getByLabelText("Send a message…")).toBeInTheDocument();
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("and an e2e status it should pass the expected placeholder to SendMessageComposer", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
wrapAndRender({
|
2022-09-16 09:10:33 +00:00
|
|
|
room,
|
|
|
|
e2eStatus: E2EStatus.Normal,
|
|
|
|
});
|
2023-01-10 14:51:20 +00:00
|
|
|
expect(screen.getByLabelText("Send an encrypted message…")).toBeInTheDocument();
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when replying to an event", () => {
|
|
|
|
let replyToEvent: MatrixEvent;
|
|
|
|
let props: Partial<React.ComponentProps<typeof MessageComposer>>;
|
|
|
|
|
|
|
|
const checkPlaceholder = (expected: string) => {
|
|
|
|
it("should pass the expected placeholder to SendMessageComposer", () => {
|
2023-01-10 14:51:20 +00:00
|
|
|
wrapAndRender(props);
|
|
|
|
expect(screen.getByLabelText(expected)).toBeInTheDocument();
|
2022-09-16 09:10:33 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const setEncrypted = () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
props.e2eStatus = E2EStatus.Normal;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
replyToEvent = mkEvent({
|
|
|
|
event: true,
|
2023-01-10 14:51:20 +00:00
|
|
|
type: EventType.RoomMessage,
|
2023-02-16 09:38:44 +00:00
|
|
|
user: cli.getUserId()!,
|
2022-09-16 09:10:33 +00:00
|
|
|
content: {},
|
|
|
|
});
|
|
|
|
|
|
|
|
props = {
|
|
|
|
room,
|
|
|
|
replyToEvent,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("without encryption", () => {
|
|
|
|
checkPlaceholder("Send a reply…");
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("with encryption", () => {
|
|
|
|
setEncrypted();
|
|
|
|
checkPlaceholder("Send an encrypted reply…");
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("with a non-thread relation", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
props.relation = { rel_type: "test" };
|
|
|
|
});
|
|
|
|
|
|
|
|
checkPlaceholder("Send a reply…");
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("that is a thread", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
props.relation = { rel_type: THREAD_RELATION_TYPE.name };
|
|
|
|
});
|
|
|
|
|
|
|
|
checkPlaceholder("Reply to thread…");
|
|
|
|
|
|
|
|
describe("with encryption", () => {
|
|
|
|
setEncrypted();
|
|
|
|
checkPlaceholder("Reply to encrypted thread…");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-01-10 14:51:20 +00:00
|
|
|
|
|
|
|
describe("when clicking start a voice message", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
wrapAndRender({ room });
|
|
|
|
await startVoiceMessage();
|
|
|
|
await flushPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should try to start a voice message", () => {
|
|
|
|
expectVoiceMessageRecordingTriggered();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when recording a voice broadcast and trying to start a voice message", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
setCurrentBroadcastRecording(room, VoiceBroadcastInfoState.Started);
|
|
|
|
wrapAndRender({ room });
|
|
|
|
await startVoiceMessage();
|
2023-03-24 19:39:24 +00:00
|
|
|
await waitEnoughCyclesForModal();
|
2023-01-10 14:51:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should not start a voice message and display the info dialog", async () => {
|
|
|
|
expect(screen.queryByLabelText("Stop recording")).not.toBeInTheDocument();
|
|
|
|
expect(screen.getByText("Can't start voice message")).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when there is a stopped voice broadcast recording and trying to start a voice message", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
setCurrentBroadcastRecording(room, VoiceBroadcastInfoState.Stopped);
|
|
|
|
wrapAndRender({ room });
|
|
|
|
await startVoiceMessage();
|
2023-03-24 19:39:24 +00:00
|
|
|
await waitEnoughCyclesForModal();
|
2023-01-10 14:51:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should try to start a voice message and should not display the info dialog", async () => {
|
|
|
|
expect(screen.queryByText("Can't start voice message")).not.toBeInTheDocument();
|
|
|
|
expectVoiceMessageRecordingTriggered();
|
|
|
|
});
|
|
|
|
});
|
2022-03-04 15:53:22 +00:00
|
|
|
});
|
|
|
|
|
2022-08-11 15:51:24 +00:00
|
|
|
describe("for a LocalRoom", () => {
|
2022-09-16 09:10:33 +00:00
|
|
|
const localRoom = new LocalRoom("!room:example.com", cli, cli.getUserId()!);
|
2022-03-04 15:53:22 +00:00
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
it("should not show the stickers button", async () => {
|
|
|
|
wrapAndRender({ room: localRoom });
|
|
|
|
await act(async () => {
|
|
|
|
await userEvent.click(screen.getByLabelText("More options"));
|
|
|
|
});
|
|
|
|
expect(screen.queryByLabelText("Sticker")).not.toBeInTheDocument();
|
2022-08-11 15:51:24 +00:00
|
|
|
});
|
2022-03-04 15:53:22 +00:00
|
|
|
});
|
2022-10-10 15:36:18 +00:00
|
|
|
|
2024-08-22 12:54:01 +00:00
|
|
|
it("wysiwyg correctly persists state to and from localStorage", async () => {
|
2022-10-10 15:36:18 +00:00
|
|
|
const room = mkStubRoom("!roomId:server", "Room 1", cli);
|
2024-08-22 12:54:01 +00:00
|
|
|
const messageText = "Test Text";
|
|
|
|
await SettingsStore.setValue("feature_wysiwyg_composer", null, SettingLevel.DEVICE, true);
|
|
|
|
const { renderResult, rawComponent } = wrapAndRender({ room });
|
|
|
|
const { unmount, rerender } = renderResult;
|
2022-10-10 15:42:15 +00:00
|
|
|
|
2024-08-22 12:54:01 +00:00
|
|
|
await act(async () => {
|
|
|
|
await flushPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
const key = `mx_wysiwyg_state_${room.roomId}`;
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
await userEvent.click(screen.getByRole("textbox"));
|
|
|
|
});
|
|
|
|
fireEvent.input(screen.getByRole("textbox"), {
|
|
|
|
data: messageText,
|
|
|
|
inputType: "insertText",
|
|
|
|
});
|
|
|
|
|
|
|
|
await waitFor(() => expect(screen.getByRole("textbox")).toHaveTextContent(messageText));
|
|
|
|
|
|
|
|
// Wait for event dispatch to happen
|
|
|
|
await act(async () => {
|
|
|
|
await flushPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
// assert there is state persisted
|
|
|
|
expect(localStorage.getItem(key)).toBeNull();
|
|
|
|
|
|
|
|
// ensure the right state was persisted to localStorage
|
|
|
|
unmount();
|
|
|
|
|
|
|
|
// assert the persisted state
|
|
|
|
expect(JSON.parse(localStorage.getItem(key)!)).toStrictEqual({
|
|
|
|
content: messageText,
|
|
|
|
isRichText: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
// ensure the correct state is re-loaded
|
|
|
|
rerender(rawComponent);
|
|
|
|
await waitFor(() => expect(screen.getByRole("textbox")).toHaveTextContent(messageText));
|
|
|
|
}, 10000);
|
2022-03-04 15:53:22 +00:00
|
|
|
});
|
|
|
|
|
2022-08-11 15:51:24 +00:00
|
|
|
function wrapAndRender(
|
|
|
|
props: Partial<React.ComponentProps<typeof MessageComposer>> = {},
|
|
|
|
canSendMessages = true,
|
2022-09-16 09:10:33 +00:00
|
|
|
narrow = false,
|
2022-08-11 15:51:24 +00:00
|
|
|
tombstone?: MatrixEvent,
|
2023-01-10 14:51:20 +00:00
|
|
|
) {
|
2023-06-05 17:12:23 +00:00
|
|
|
const mockClient = MatrixClientPeg.safeGet();
|
2022-03-04 15:53:22 +00:00
|
|
|
const roomId = "myroomid";
|
2022-08-11 15:51:24 +00:00
|
|
|
const room: any = props.room || {
|
2022-03-04 15:53:22 +00:00
|
|
|
currentState: undefined,
|
|
|
|
roomId,
|
|
|
|
client: mockClient,
|
2022-12-12 11:24:14 +00:00
|
|
|
getMember: function (userId: string): RoomMember {
|
2022-03-04 15:53:22 +00:00
|
|
|
return new RoomMember(roomId, userId);
|
|
|
|
},
|
|
|
|
};
|
2022-03-21 09:03:03 +00:00
|
|
|
|
2023-01-10 14:51:20 +00:00
|
|
|
const roomContext = {
|
2022-09-16 09:10:33 +00:00
|
|
|
room,
|
|
|
|
canSendMessages,
|
|
|
|
tombstone,
|
|
|
|
narrow,
|
2022-03-21 09:03:03 +00:00
|
|
|
} as unknown as IRoomState;
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
room,
|
|
|
|
resizeNotifier: new ResizeNotifier(),
|
|
|
|
permalinkCreator: new RoomPermalinkCreator(room),
|
|
|
|
};
|
|
|
|
|
2024-08-22 12:54:01 +00:00
|
|
|
const getRawComponent = (props = {}, context = roomContext, client = mockClient) => (
|
|
|
|
<MatrixClientContext.Provider value={client}>
|
|
|
|
<RoomContext.Provider value={context}>
|
|
|
|
<MessageComposer {...defaultProps} {...props} />
|
|
|
|
</RoomContext.Provider>
|
|
|
|
</MatrixClientContext.Provider>
|
|
|
|
);
|
2023-01-10 14:51:20 +00:00
|
|
|
return {
|
2024-08-22 12:54:01 +00:00
|
|
|
rawComponent: getRawComponent(props, roomContext, mockClient),
|
|
|
|
renderResult: render(getRawComponent(props, roomContext, mockClient)),
|
2023-01-10 14:51:20 +00:00
|
|
|
roomContext,
|
|
|
|
};
|
2022-03-04 15:53:22 +00:00
|
|
|
}
|