Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit e11a9bd

Browse files
committed
Add tests
1 parent dd7a7a2 commit e11a9bd

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/components/views/rooms/EventTile.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
13201320
// appease TS
13211321
highlights: this.props.highlights,
13221322
highlightLink: this.props.highlightLink,
1323-
onHeightChanged: () => this.props.onHeightChanged(),
1323+
onHeightChanged: () => this.props.onHeightChanged,
13241324
permalinkCreator: this.props.permalinkCreator!,
13251325
},
13261326
this.context.showHiddenEvents,

test/components/views/rooms/EventTile-test.tsx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import React from "react";
18-
import { act, render, screen, waitFor } from "@testing-library/react";
18+
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
1919
import { EventType } from "matrix-js-sdk/src/@types/event";
2020
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client";
2121
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
@@ -28,6 +28,10 @@ import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
2828
import SettingsStore from "../../../../src/settings/SettingsStore";
2929
import { getRoomContext, mkEvent, mkMessage, stubClient } from "../../../test-utils";
3030
import { mkThread } from "../../../test-utils/threads";
31+
import RoomAvatar from "../../../../src/components/views/avatars/RoomAvatar";
32+
import DMRoomMap from "../../../../src/utils/DMRoomMap";
33+
import dis from "../../../../src/dispatcher/dispatcher";
34+
import { Action } from "../../../../src/dispatcher/actions";
3135

3236
describe("EventTile", () => {
3337
const ROOM_ID = "!roomId:example.org";
@@ -154,4 +158,42 @@ describe("EventTile", () => {
154158
expect(container.getElementsByClassName("mx_NotificationBadge_highlighted")).toHaveLength(1);
155159
});
156160
});
161+
162+
describe("EventTile in the right panel", () => {
163+
beforeAll(() => {
164+
const dmRoomMap: DMRoomMap = {
165+
getUserIdForRoomId: jest.fn(),
166+
} as unknown as DMRoomMap;
167+
DMRoomMap.setShared(dmRoomMap);
168+
});
169+
170+
it("renders the room name for notifications", () => {
171+
const { container } = getComponent({}, TimelineRenderingType.Notification);
172+
expect(container.getElementsByClassName("mx_EventTile_details")[0]).toHaveTextContent(
173+
"@alice:example.org in !roomId:example.org",
174+
);
175+
});
176+
177+
it("renders the sender for the thread list", () => {
178+
const { container } = getComponent({}, TimelineRenderingType.ThreadsList);
179+
expect(container.getElementsByClassName("mx_EventTile_details")[0]).toHaveTextContent("@alice:example.org");
180+
});
181+
182+
it.each([
183+
[TimelineRenderingType.Notification, Action.ViewRoom],
184+
[TimelineRenderingType.ThreadsList, Action.ShowThread],
185+
])("type %s dispatches %s", (renderingType, action) => {
186+
jest.spyOn(dis, "dispatch");
187+
188+
const { container } = getComponent({}, renderingType);
189+
190+
fireEvent.click(container.querySelector("li"));
191+
192+
expect(dis.dispatch).toHaveBeenCalledWith(
193+
expect.objectContaining({
194+
action,
195+
}),
196+
);
197+
});
198+
});
157199
});

0 commit comments

Comments
 (0)