2022-12-23 16:44:01 +01:00
|
|
|
/*
|
2024-09-09 15:57:16 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-12-23 16:44:01 +01:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 15:57:16 +02: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-12-23 16:44:01 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { Feature, ServerSupport } from "matrix-js-sdk/src/feature";
|
|
|
|
import { MatrixClient, MatrixEvent, RelationType } from "matrix-js-sdk/src/matrix";
|
2024-11-04 12:34:00 +01:00
|
|
|
import { screen, act } from "jest-matrix-react";
|
2022-12-23 16:44:01 +01:00
|
|
|
import userEvent from "@testing-library/user-event";
|
|
|
|
|
2024-10-15 15:57:26 +02:00
|
|
|
import { flushPromises, mkEvent, stubClient } from "../../../../test-utils";
|
2022-12-23 16:44:01 +01:00
|
|
|
import { mkVoiceBroadcastInfoStateEvent } from "../../../voice-broadcast/utils/test-utils";
|
2024-10-15 15:57:26 +02:00
|
|
|
import { VoiceBroadcastInfoState } from "../../../../../src/voice-broadcast";
|
|
|
|
import { createRedactEventDialog } from "../../../../../src/components/views/dialogs/ConfirmRedactDialog";
|
2022-12-23 16:44:01 +01:00
|
|
|
|
|
|
|
describe("ConfirmRedactDialog", () => {
|
|
|
|
const roomId = "!room:example.com";
|
|
|
|
let client: MatrixClient;
|
|
|
|
let mxEvent: MatrixEvent;
|
|
|
|
|
|
|
|
const setUpVoiceBroadcastStartedEvent = () => {
|
|
|
|
mxEvent = mkVoiceBroadcastInfoStateEvent(
|
|
|
|
roomId,
|
|
|
|
VoiceBroadcastInfoState.Started,
|
|
|
|
client.getUserId()!,
|
|
|
|
client.deviceId!,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const confirmDeleteVoiceBroadcastStartedEvent = async () => {
|
2024-11-04 12:34:00 +01:00
|
|
|
act(() => createRedactEventDialog({ mxEvent }));
|
2022-12-23 16:44:01 +01:00
|
|
|
// double-flush promises required for the dialog to show up
|
|
|
|
await flushPromises();
|
|
|
|
await flushPromises();
|
|
|
|
|
2024-11-04 12:34:00 +01:00
|
|
|
await userEvent.click(await screen.findByTestId("dialog-primary-button"));
|
2022-12-23 16:44:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
client = stubClient();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should raise an error for an event without ID", async () => {
|
|
|
|
mxEvent = mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "m.room.message",
|
|
|
|
room: roomId,
|
|
|
|
content: {},
|
|
|
|
user: client.getSafeUserId(),
|
|
|
|
});
|
|
|
|
jest.spyOn(mxEvent, "getId").mockReturnValue(undefined);
|
2023-07-13 17:19:44 +02:00
|
|
|
await expect(confirmDeleteVoiceBroadcastStartedEvent()).rejects.toThrow("cannot redact event without ID");
|
2022-12-23 16:44:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should raise an error for an event without room-ID", async () => {
|
|
|
|
mxEvent = mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: "m.room.message",
|
|
|
|
room: roomId,
|
|
|
|
content: {},
|
|
|
|
user: client.getSafeUserId(),
|
|
|
|
});
|
|
|
|
jest.spyOn(mxEvent, "getRoomId").mockReturnValue(undefined);
|
2023-07-13 17:19:44 +02:00
|
|
|
await expect(confirmDeleteVoiceBroadcastStartedEvent()).rejects.toThrow(
|
|
|
|
`cannot redact event ${mxEvent.getId()} without room ID`,
|
|
|
|
);
|
2022-12-23 16:44:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("when redacting a voice broadcast started event", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setUpVoiceBroadcastStartedEvent();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and the server does not support relation based redactions", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
client.canSupport.set(Feature.RelationBasedRedactions, ServerSupport.Unsupported);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and displaying and confirm the dialog for a voice broadcast", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await confirmDeleteVoiceBroadcastStartedEvent();
|
|
|
|
});
|
|
|
|
|
2023-06-07 15:24:01 +02:00
|
|
|
it("should call redact without `with_rel_types`", () => {
|
2022-12-23 16:44:01 +01:00
|
|
|
expect(client.redactEvent).toHaveBeenCalledWith(roomId, mxEvent.getId(), undefined, {});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and the server supports relation based redactions", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
client.canSupport.set(Feature.RelationBasedRedactions, ServerSupport.Unstable);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and displaying and confirm the dialog for a voice broadcast", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await confirmDeleteVoiceBroadcastStartedEvent();
|
|
|
|
});
|
|
|
|
|
2023-06-07 15:24:01 +02:00
|
|
|
it("should call redact with `with_rel_types`", () => {
|
2022-12-23 16:44:01 +01:00
|
|
|
expect(client.redactEvent).toHaveBeenCalledWith(roomId, mxEvent.getId(), undefined, {
|
2023-06-07 15:24:01 +02:00
|
|
|
with_rel_types: [RelationType.Reference],
|
2022-12-23 16:44:01 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|