From e11a9bdc76fe251b265fcdb7fba274a022628ce6 Mon Sep 17 00:00:00 2001 From: Germain Date: Thu, 15 Dec 2022 09:54:00 +0100 Subject: [PATCH] Add tests --- src/components/views/rooms/EventTile.tsx | 2 +- .../components/views/rooms/EventTile-test.tsx | 44 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx index 6ac209b8c50d..41db24c06075 100644 --- a/src/components/views/rooms/EventTile.tsx +++ b/src/components/views/rooms/EventTile.tsx @@ -1320,7 +1320,7 @@ export class UnwrappedEventTile extends React.Component // appease TS highlights: this.props.highlights, highlightLink: this.props.highlightLink, - onHeightChanged: () => this.props.onHeightChanged(), + onHeightChanged: () => this.props.onHeightChanged, permalinkCreator: this.props.permalinkCreator!, }, this.context.showHiddenEvents, diff --git a/test/components/views/rooms/EventTile-test.tsx b/test/components/views/rooms/EventTile-test.tsx index bebec2efc845..c2f4dbde4fca 100644 --- a/test/components/views/rooms/EventTile-test.tsx +++ b/test/components/views/rooms/EventTile-test.tsx @@ -15,7 +15,7 @@ limitations under the License. */ import React from "react"; -import { act, render, screen, waitFor } from "@testing-library/react"; +import { act, fireEvent, render, screen, waitFor } from "@testing-library/react"; import { EventType } from "matrix-js-sdk/src/@types/event"; import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; @@ -28,6 +28,10 @@ import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import SettingsStore from "../../../../src/settings/SettingsStore"; import { getRoomContext, mkEvent, mkMessage, stubClient } from "../../../test-utils"; import { mkThread } from "../../../test-utils/threads"; +import RoomAvatar from "../../../../src/components/views/avatars/RoomAvatar"; +import DMRoomMap from "../../../../src/utils/DMRoomMap"; +import dis from "../../../../src/dispatcher/dispatcher"; +import { Action } from "../../../../src/dispatcher/actions"; describe("EventTile", () => { const ROOM_ID = "!roomId:example.org"; @@ -154,4 +158,42 @@ describe("EventTile", () => { expect(container.getElementsByClassName("mx_NotificationBadge_highlighted")).toHaveLength(1); }); }); + + describe("EventTile in the right panel", () => { + beforeAll(() => { + const dmRoomMap: DMRoomMap = { + getUserIdForRoomId: jest.fn(), + } as unknown as DMRoomMap; + DMRoomMap.setShared(dmRoomMap); + }); + + it("renders the room name for notifications", () => { + const { container } = getComponent({}, TimelineRenderingType.Notification); + expect(container.getElementsByClassName("mx_EventTile_details")[0]).toHaveTextContent( + "@alice:example.org in !roomId:example.org", + ); + }); + + it("renders the sender for the thread list", () => { + const { container } = getComponent({}, TimelineRenderingType.ThreadsList); + expect(container.getElementsByClassName("mx_EventTile_details")[0]).toHaveTextContent("@alice:example.org"); + }); + + it.each([ + [TimelineRenderingType.Notification, Action.ViewRoom], + [TimelineRenderingType.ThreadsList, Action.ShowThread], + ])("type %s dispatches %s", (renderingType, action) => { + jest.spyOn(dis, "dispatch"); + + const { container } = getComponent({}, renderingType); + + fireEvent.click(container.querySelector("li")); + + expect(dis.dispatch).toHaveBeenCalledWith( + expect.objectContaining({ + action, + }), + ); + }); + }); });