223a861535
* Move E2ePadlock to shared components * Add storybook images * Move translation to shared components * Fix E2ePadlock story accessibility * Update E2eMessageSharedIcon test for padlock role
60 lines
2.3 KiB
TypeScript
60 lines
2.3 KiB
TypeScript
/*
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import { render, waitFor } from "jest-matrix-react";
|
|
import React from "react";
|
|
import { mocked } from "jest-mock";
|
|
import { type RoomMember, type RoomState } from "matrix-js-sdk/src/matrix";
|
|
|
|
import { E2eMessageSharedIcon } from "../../../../../../src/components/views/rooms/EventTile/E2eMessageSharedIcon.tsx";
|
|
import { createTestClient, mkStubRoom, withClientContextRenderOptions } from "../../../../../test-utils";
|
|
|
|
describe("E2eMessageSharedIcon", () => {
|
|
it("renders correctly for a known user", async () => {
|
|
const mockClient = createTestClient();
|
|
const mockMember = { rawDisplayName: "Bob" } as RoomMember;
|
|
const mockState = {
|
|
getMember: (userId) => {
|
|
expect(userId).toEqual("@bob:example.com");
|
|
return mockMember;
|
|
},
|
|
} as RoomState;
|
|
const mockRoom = mkStubRoom("!roomId", undefined, mockClient, mockState);
|
|
mocked(mockClient.getRoom).mockImplementation((roomId) => {
|
|
expect(roomId).toEqual("!roomId");
|
|
return mockRoom;
|
|
});
|
|
|
|
const result = render(
|
|
<E2eMessageSharedIcon keyForwardingUserId="@bob:example.com" roomId="!roomId" />,
|
|
withClientContextRenderOptions(mockClient),
|
|
);
|
|
|
|
await waitFor(() =>
|
|
expect(result.container.firstChild).toHaveAccessibleName(
|
|
"Bob (@bob:example.com) shared this message since you were not in the room when it was sent.",
|
|
),
|
|
);
|
|
expect(result.container).toMatchSnapshot();
|
|
});
|
|
|
|
it("renders correctly for an unknown user", async () => {
|
|
const mockClient = createTestClient();
|
|
const result = render(
|
|
<E2eMessageSharedIcon keyForwardingUserId="@bob:example.com" roomId="!roomId" />,
|
|
withClientContextRenderOptions(mockClient),
|
|
);
|
|
|
|
await waitFor(() =>
|
|
expect(result.container.firstChild).toHaveAccessibleName(
|
|
"@bob:example.com (@bob:example.com) shared this message since you were not in the room when it was sent.",
|
|
),
|
|
);
|
|
expect(result.container).toMatchSnapshot();
|
|
});
|
|
});
|