2022-03-04 16:53:22 +01:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
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 * as React from "react";
|
2023-01-10 15:51:20 +01:00
|
|
|
import { EventType, MatrixEvent, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
2022-09-16 11:10:33 +02:00
|
|
|
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
|
2023-01-10 15:51:20 +01:00
|
|
|
import { act, render, screen } from "@testing-library/react";
|
|
|
|
import userEvent from "@testing-library/user-event";
|
|
|
|
|
|
|
|
import {
|
|
|
|
createTestClient,
|
|
|
|
filterConsole,
|
|
|
|
flushPromises,
|
|
|
|
mkEvent,
|
|
|
|
mkStubRoom,
|
|
|
|
mockPlatformPeg,
|
|
|
|
stubClient,
|
|
|
|
} from "../../../test-utils";
|
|
|
|
import MessageComposer from "../../../../src/components/views/rooms/MessageComposer";
|
2022-03-04 16:53:22 +01:00
|
|
|
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
|
|
|
import RoomContext from "../../../../src/contexts/RoomContext";
|
2022-03-21 10:03:03 +01:00
|
|
|
import { IRoomState } from "../../../../src/components/structures/RoomView";
|
|
|
|
import ResizeNotifier from "../../../../src/utils/ResizeNotifier";
|
|
|
|
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
2022-08-11 17:51:24 +02:00
|
|
|
import { LocalRoom } from "../../../../src/models/LocalRoom";
|
2022-09-16 11:10:33 +02: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 15:51:20 +01:00
|
|
|
import { addTextToComposerRTL } from "../../../test-utils/composer";
|
2022-09-16 11:10:33 +02:00
|
|
|
import UIStore, { UI_EVENTS } from "../../../../src/stores/UIStore";
|
2023-01-10 15:51:20 +01: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";
|
|
|
|
import Modal from "../../../../src/Modal";
|
|
|
|
|
|
|
|
jest.mock("../../../../src/components/views/rooms/wysiwyg_composer", () => ({
|
|
|
|
SendWysiwygComposer: jest.fn().mockImplementation(() => <div data-testid="wysiwyg-composer" />),
|
|
|
|
}));
|
|
|
|
|
|
|
|
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"),
|
|
|
|
MatrixClientPeg.get(),
|
|
|
|
state,
|
|
|
|
);
|
|
|
|
SdkContextClass.instance.voiceBroadcastRecordingsStore.setCurrent(recording);
|
|
|
|
};
|
|
|
|
|
|
|
|
const waitForModal = async (): Promise<void> => {
|
|
|
|
await flushPromises();
|
|
|
|
await flushPromises();
|
|
|
|
};
|
|
|
|
|
|
|
|
const shouldClearModal = async (): Promise<void> => {
|
|
|
|
afterEach(async () => {
|
|
|
|
Modal.closeCurrentModal("force");
|
|
|
|
await waitForModal();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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 17:36:18 +02:00
|
|
|
|
2022-03-04 16:53:22 +01:00
|
|
|
describe("MessageComposer", () => {
|
|
|
|
stubClient();
|
|
|
|
const cli = createTestClient();
|
|
|
|
|
2023-01-10 15:51:20 +01:00
|
|
|
filterConsole("Starting load of AsyncWrapper for modal");
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockPlatformPeg();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
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 17:51:24 +02:00
|
|
|
describe("for a Room", () => {
|
|
|
|
const room = mkStubRoom("!roomId:server", "Room 1", cli);
|
|
|
|
|
|
|
|
it("Renders a SendMessageComposer and MessageComposerButtons by default", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
wrapAndRender({ room });
|
|
|
|
expect(screen.getByLabelText("Send a message…")).toBeInTheDocument();
|
2022-08-11 17:51:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Does not render a SendMessageComposer or MessageComposerButtons when user has no permission", () => {
|
2023-01-10 15:51:20 +01: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 17:51:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Does not render a SendMessageComposer or MessageComposerButtons when room is tombstoned", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
wrapAndRender(
|
2022-12-12 12:24:14 +01: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 17:51:24 +02:00
|
|
|
|
2023-01-10 15:51:20 +01: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 17:51:24 +02:00
|
|
|
});
|
2022-09-16 11:10:33 +02:00
|
|
|
|
|
|
|
describe("when receiving a »reply_to_event«", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
let roomContext: IRoomState;
|
2022-09-16 11:10:33 +02:00
|
|
|
let resizeNotifier: ResizeNotifier;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
resizeNotifier = {
|
|
|
|
notifyTimelineHeightChanged: jest.fn(),
|
|
|
|
} as unknown as ResizeNotifier;
|
2023-01-10 15:51:20 +01:00
|
|
|
roomContext = wrapAndRender({
|
2022-09-16 11:10:33 +02:00
|
|
|
room,
|
|
|
|
resizeNotifier,
|
2023-01-10 15:51:20 +01:00
|
|
|
}).roomContext;
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should call notifyTimelineHeightChanged() for the same context", () => {
|
|
|
|
dis.dispatch({
|
|
|
|
action: "reply_to_event",
|
2023-01-10 15:51:20 +01:00
|
|
|
context: roomContext.timelineRenderingType,
|
2022-09-16 11:10:33 +02: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 15:51:20 +01:00
|
|
|
buttonLabel: "Sticker",
|
2022-09-16 11:10:33 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
setting: "MessageComposerInput.showPollsButton",
|
2023-01-10 15:51:20 +01:00
|
|
|
buttonLabel: "Poll",
|
2022-09-16 11:10:33 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
setting: Features.VoiceBroadcast,
|
2023-01-10 15:51:20 +01:00
|
|
|
buttonLabel: "Voice broadcast",
|
2022-09-16 11:10:33 +02:00
|
|
|
},
|
2023-01-10 15:51:20 +01:00
|
|
|
].forEach(({ setting, buttonLabel }) => {
|
2022-09-16 11:10:33 +02:00
|
|
|
[true, false].forEach((value: boolean) => {
|
|
|
|
describe(`when ${setting} = ${value}`, () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
beforeEach(async () => {
|
2022-09-16 11:10:33 +02:00
|
|
|
SettingsStore.setValue(setting, null, SettingLevel.DEVICE, value);
|
2023-01-10 15:51:20 +01:00
|
|
|
wrapAndRender({ room });
|
|
|
|
await act(async () => {
|
|
|
|
await userEvent.click(screen.getByLabelText("More options"));
|
|
|
|
});
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
|
2023-01-10 15:51:20 +01:00
|
|
|
it(`should${value || "not"} display the button`, () => {
|
|
|
|
if (value) {
|
|
|
|
expect(screen.getByLabelText(buttonLabel)).toBeInTheDocument();
|
|
|
|
} else {
|
|
|
|
expect(screen.queryByLabelText(buttonLabel)).not.toBeInTheDocument();
|
|
|
|
}
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe(`and setting ${setting} to ${!value}`, () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
// simulate settings update
|
|
|
|
await SettingsStore.setValue(setting, null, SettingLevel.DEVICE, !value);
|
2022-12-12 12:24:14 +01:00
|
|
|
dis.dispatch(
|
|
|
|
{
|
|
|
|
action: Action.SettingUpdated,
|
|
|
|
settingName: setting,
|
|
|
|
newValue: !value,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
|
2023-01-10 15:51:20 +01:00
|
|
|
it(`should${!value || "not"} display the button`, () => {
|
|
|
|
if (!value) {
|
|
|
|
expect(screen.getByLabelText(buttonLabel)).toBeInTheDocument();
|
|
|
|
} else {
|
|
|
|
expect(screen.queryByLabelText(buttonLabel)).not.toBeInTheDocument();
|
|
|
|
}
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not render the send button", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
wrapAndRender({ room });
|
|
|
|
expect(screen.queryByLabelText("Send message")).not.toBeInTheDocument();
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("when a message has been entered", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
beforeEach(async () => {
|
|
|
|
const renderResult = wrapAndRender({ room }).renderResult;
|
|
|
|
await addTextToComposerRTL(renderResult, "Hello");
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should render the send button", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
expect(screen.getByLabelText("Send message")).toBeInTheDocument();
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("UIStore interactions", () => {
|
|
|
|
let resizeCallback: Function;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(UIStore.instance, "on").mockImplementation((_event: string, listener: Function): any => {
|
|
|
|
resizeCallback = listener;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when a non-resize event occurred in UIStore", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
beforeEach(async () => {
|
|
|
|
wrapAndRender({ room });
|
|
|
|
await openStickerPicker();
|
2022-09-16 11:10:33 +02:00
|
|
|
resizeCallback("test", {});
|
|
|
|
});
|
|
|
|
|
2023-01-10 15:51:20 +01:00
|
|
|
it("should still display the sticker picker", () => {
|
|
|
|
expect(screen.getByText("You don't currently have any stickerpacks enabled")).toBeInTheDocument();
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when a resize to narrow event occurred in UIStore", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
beforeEach(async () => {
|
|
|
|
wrapAndRender({ room }, true, true);
|
|
|
|
await openStickerPicker();
|
2022-09-16 11:10:33 +02:00
|
|
|
resizeCallback(UI_EVENTS.Resize, {});
|
|
|
|
});
|
|
|
|
|
2023-01-10 15:51:20 +01: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 11:10:33 +02:00
|
|
|
});
|
|
|
|
|
2023-01-10 15:51:20 +01:00
|
|
|
it("should close the sticker picker", () => {
|
|
|
|
expect(
|
|
|
|
screen.queryByText("You don't currently have any stickerpacks enabled"),
|
|
|
|
).not.toBeInTheDocument();
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when a resize to non-narrow event occurred in UIStore", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
beforeEach(async () => {
|
|
|
|
wrapAndRender({ room }, true, false);
|
|
|
|
await openStickerPicker();
|
2022-09-16 11:10:33 +02:00
|
|
|
resizeCallback(UI_EVENTS.Resize, {});
|
|
|
|
});
|
|
|
|
|
2023-01-10 15:51:20 +01: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 11:10:33 +02:00
|
|
|
});
|
|
|
|
|
2023-01-10 15:51:20 +01:00
|
|
|
it("should close the sticker picker", () => {
|
|
|
|
expect(
|
|
|
|
screen.queryByText("You don't currently have any stickerpacks enabled"),
|
|
|
|
).not.toBeInTheDocument();
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("when not replying to an event", () => {
|
|
|
|
it("should pass the expected placeholder to SendMessageComposer", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
wrapAndRender({ room });
|
|
|
|
expect(screen.getByLabelText("Send a message…")).toBeInTheDocument();
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("and an e2e status it should pass the expected placeholder to SendMessageComposer", () => {
|
2023-01-10 15:51:20 +01:00
|
|
|
wrapAndRender({
|
2022-09-16 11:10:33 +02:00
|
|
|
room,
|
|
|
|
e2eStatus: E2EStatus.Normal,
|
|
|
|
});
|
2023-01-10 15:51:20 +01:00
|
|
|
expect(screen.getByLabelText("Send an encrypted message…")).toBeInTheDocument();
|
2022-09-16 11:10:33 +02: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 15:51:20 +01:00
|
|
|
wrapAndRender(props);
|
|
|
|
expect(screen.getByLabelText(expected)).toBeInTheDocument();
|
2022-09-16 11:10:33 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const setEncrypted = () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
props.e2eStatus = E2EStatus.Normal;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
replyToEvent = mkEvent({
|
|
|
|
event: true,
|
2023-01-10 15:51:20 +01:00
|
|
|
type: EventType.RoomMessage,
|
2022-09-16 11:10:33 +02:00
|
|
|
user: cli.getUserId(),
|
|
|
|
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 15:51:20 +01:00
|
|
|
|
|
|
|
describe("when clicking start a voice message", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
wrapAndRender({ room });
|
|
|
|
await startVoiceMessage();
|
|
|
|
await flushPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
shouldClearModal();
|
|
|
|
|
|
|
|
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();
|
|
|
|
await waitForModal();
|
|
|
|
});
|
|
|
|
|
|
|
|
shouldClearModal();
|
|
|
|
|
|
|
|
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();
|
|
|
|
await waitForModal();
|
|
|
|
});
|
|
|
|
|
|
|
|
shouldClearModal();
|
|
|
|
|
|
|
|
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 16:53:22 +01:00
|
|
|
});
|
|
|
|
|
2022-08-11 17:51:24 +02:00
|
|
|
describe("for a LocalRoom", () => {
|
2022-09-16 11:10:33 +02:00
|
|
|
const localRoom = new LocalRoom("!room:example.com", cli, cli.getUserId()!);
|
2022-03-04 16:53:22 +01:00
|
|
|
|
2023-01-10 15:51:20 +01: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 17:51:24 +02:00
|
|
|
});
|
2022-03-04 16:53:22 +01:00
|
|
|
});
|
2022-10-10 17:36:18 +02:00
|
|
|
|
2023-01-10 15:51:20 +01:00
|
|
|
it("should render SendWysiwygComposer when enabled", () => {
|
2022-10-10 17:36:18 +02:00
|
|
|
const room = mkStubRoom("!roomId:server", "Room 1", cli);
|
|
|
|
SettingsStore.setValue("feature_wysiwyg_composer", null, SettingLevel.DEVICE, true);
|
2022-10-10 17:42:15 +02:00
|
|
|
|
2023-01-10 15:51:20 +01:00
|
|
|
wrapAndRender({ room });
|
|
|
|
expect(screen.getByTestId("wysiwyg-composer")).toBeInTheDocument();
|
2022-10-10 17:36:18 +02:00
|
|
|
});
|
2022-03-04 16:53:22 +01:00
|
|
|
});
|
|
|
|
|
2022-08-11 17:51:24 +02:00
|
|
|
function wrapAndRender(
|
|
|
|
props: Partial<React.ComponentProps<typeof MessageComposer>> = {},
|
|
|
|
canSendMessages = true,
|
2022-09-16 11:10:33 +02:00
|
|
|
narrow = false,
|
2022-08-11 17:51:24 +02:00
|
|
|
tombstone?: MatrixEvent,
|
2023-01-10 15:51:20 +01:00
|
|
|
) {
|
2022-03-04 16:53:22 +01:00
|
|
|
const mockClient = MatrixClientPeg.get();
|
|
|
|
const roomId = "myroomid";
|
2022-08-11 17:51:24 +02:00
|
|
|
const room: any = props.room || {
|
2022-03-04 16:53:22 +01:00
|
|
|
currentState: undefined,
|
|
|
|
roomId,
|
|
|
|
client: mockClient,
|
2022-12-12 12:24:14 +01:00
|
|
|
getMember: function (userId: string): RoomMember {
|
2022-03-04 16:53:22 +01:00
|
|
|
return new RoomMember(roomId, userId);
|
|
|
|
},
|
|
|
|
};
|
2022-03-21 10:03:03 +01:00
|
|
|
|
2023-01-10 15:51:20 +01:00
|
|
|
const roomContext = {
|
2022-09-16 11:10:33 +02:00
|
|
|
room,
|
|
|
|
canSendMessages,
|
|
|
|
tombstone,
|
|
|
|
narrow,
|
2022-03-21 10:03:03 +01:00
|
|
|
} as unknown as IRoomState;
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
room,
|
|
|
|
resizeNotifier: new ResizeNotifier(),
|
|
|
|
permalinkCreator: new RoomPermalinkCreator(room),
|
|
|
|
};
|
|
|
|
|
2023-01-10 15:51:20 +01:00
|
|
|
return {
|
|
|
|
renderResult: render(
|
|
|
|
<MatrixClientContext.Provider value={mockClient}>
|
|
|
|
<RoomContext.Provider value={roomContext}>
|
|
|
|
<MessageComposer {...defaultProps} {...props} />
|
|
|
|
</RoomContext.Provider>
|
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
),
|
|
|
|
roomContext,
|
|
|
|
};
|
2022-03-04 16:53:22 +01:00
|
|
|
}
|