From 4fb20df80e1803385bfde21d03ec06c5720c1c30 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Fri, 25 Oct 2024 18:22:11 -0400 Subject: [PATCH] add test for not showing shield --- .../components/views/rooms/EventTile-test.tsx | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/test/unit-tests/components/views/rooms/EventTile-test.tsx b/test/unit-tests/components/views/rooms/EventTile-test.tsx index 7554c83ef00..b97253f4118 100644 --- a/test/unit-tests/components/views/rooms/EventTile-test.tsx +++ b/test/unit-tests/components/views/rooms/EventTile-test.tsx @@ -19,7 +19,14 @@ import { Room, TweakName, } from "matrix-js-sdk/src/matrix"; -import { CryptoApi, EventEncryptionInfo, EventShieldColour, EventShieldReason } from "matrix-js-sdk/src/crypto-api"; +import { + CryptoApi, + DecryptionFailureCode, + EventEncryptionInfo, + EventShieldColour, + EventShieldReason, +} from "matrix-js-sdk/src/crypto-api"; +import { DecryptionError } from "matrix-js-sdk/src/crypto"; import { mkEncryptedMatrixEvent } from "matrix-js-sdk/src/testing"; import EventTile, { EventTileProps } from "../../../../../src/components/views/rooms/EventTile"; @@ -350,6 +357,34 @@ describe("EventTile", () => { "mx_EventTile_e2eIcon_decryption_failure", ); }); + + it("should not show a shield for previously-verified users", async () => { + mxEvent = mkEvent({ + type: "m.room.encrypted", + room: room.roomId, + user: "@alice:example.org", + event: true, + content: {}, + }); + + const mockCrypto = { + decryptEvent: async (_ev): Promise => { + throw new DecryptionError( + DecryptionFailureCode.SENDER_IDENTITY_PREVIOUSLY_VERIFIED, + "The sender identity is unverified, but was previously verified.", + ); + }, + } as Parameters[0]; + await mxEvent.attemptDecryption(mockCrypto); + + const { container } = getComponent(); + await act(flushPromises); + + const eventTiles = container.getElementsByClassName("mx_EventTile"); + expect(eventTiles).toHaveLength(1); + + expect(container.getElementsByClassName("mx_EventTile_e2eIcon")).toHaveLength(0); + }); }); it("should update the warning when the event is edited", async () => {