Replace MatrixClient.isRoomEncrypted by MatrixClient.CryptoApi.isEncryptionEnabledInRoom in EventTile.tsx

This commit is contained in:
Florian Duros 2024-11-21 10:31:55 +01:00
parent b907ec380f
commit dc53178ea6
No known key found for this signature in database
GPG key ID: A5BBB4041B493F15
4 changed files with 60 additions and 4 deletions

View file

@ -32,6 +32,7 @@ import {
mkEvent,
mkMessage,
mkStubRoom,
mockClientMethodsCrypto,
mockPlatformPeg,
} from "../../../../test-utils";
import { TILE_SERVER_WK_KEY } from "../../../../../src/utils/WellKnownUtils";
@ -67,7 +68,6 @@ describe("ForwardDialog", () => {
getAccountData: jest.fn().mockReturnValue(accountDataEvent),
getPushActionsForEvent: jest.fn(),
mxcUrlToHttp: jest.fn().mockReturnValue(""),
isRoomEncrypted: jest.fn().mockReturnValue(false),
getProfileInfo: jest.fn().mockResolvedValue({
displayname: "Alice",
}),
@ -76,6 +76,7 @@ describe("ForwardDialog", () => {
getClientWellKnown: jest.fn().mockReturnValue({
[TILE_SERVER_WK_KEY.name]: { map_style_url: "maps.com" },
}),
...mockClientMethodsCrypto(),
});
const defaultRooms = ["a", "A", "b"].map((name) => mkStubRoom(name, name, mockClient));

View file

@ -10,6 +10,7 @@ import * as React from "react";
import { act, fireEvent, render, screen, waitFor } from "jest-matrix-react";
import { mocked } from "jest-mock";
import {
EventTimeline,
EventType,
IEventDecryptionResult,
MatrixClient,
@ -17,6 +18,7 @@ import {
NotificationCountType,
PendingEventOrdering,
Room,
RoomStateEvent,
TweakName,
} from "matrix-js-sdk/src/matrix";
import {
@ -243,6 +245,7 @@ describe("EventTile", () => {
const mockCrypto = {
// a mocked version of getEncryptionInfoForEvent which will pick its result from `eventToEncryptionInfoMap`
getEncryptionInfoForEvent: async (event: MatrixEvent) => eventToEncryptionInfoMap.get(event.getId()!)!,
isEncryptionEnabledInRoom: jest.fn().mockResolvedValue(false),
} as unknown as CryptoApi;
client.getCrypto = () => mockCrypto;
});
@ -434,7 +437,7 @@ describe("EventTile", () => {
});
it("should update the warning when the event is replaced with an unencrypted one", async () => {
jest.spyOn(client, "isRoomEncrypted").mockReturnValue(true);
jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true);
// we start out with an event from the trusted device
mxEvent = await mkEncryptedMatrixEvent({
@ -578,4 +581,27 @@ describe("EventTile", () => {
});
});
});
it("should display the not encrypted status for an unencrypted event when the room becomes encrypted", async () => {
jest.spyOn(client.getCrypto()!, "getEncryptionInfoForEvent").mockResolvedValue({
shieldColour: EventShieldColour.NONE,
shieldReason: null,
});
getComponent();
await flushPromises();
// The room and the event are unencrypted, the tile should not show the not encrypted status
expect(screen.queryByText("Not encrypted")).toBeNull();
// The room is now encrypted
jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true);
// Emit a state event to trigger a re-render
const roomState = room!.getLiveTimeline().getState(EventTimeline.FORWARDS)!;
act(() => {
roomState.emit(RoomStateEvent.Events, new MatrixEvent({ type: EventType.RoomEncryption }), roomState, null);
});
// The event tile should now show the not encrypted status
await waitFor(() => expect(screen.getByText("Not encrypted")).toBeInTheDocument());
});
});