From 7f4a142158567ac5bb7c753fe49341e3855280d2 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Thu, 27 Feb 2025 18:09:51 +0100 Subject: [PATCH] test(new room list): add test for room cell --- .../rooms/RoomListPanel/RoomListCell-test.tsx | 44 ++++++++++++++++ .../__snapshots__/RoomListCell-test.tsx.snap | 50 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 test/unit-tests/components/views/rooms/RoomListPanel/RoomListCell-test.tsx create mode 100644 test/unit-tests/components/views/rooms/RoomListPanel/__snapshots__/RoomListCell-test.tsx.snap diff --git a/test/unit-tests/components/views/rooms/RoomListPanel/RoomListCell-test.tsx b/test/unit-tests/components/views/rooms/RoomListPanel/RoomListCell-test.tsx new file mode 100644 index 0000000000..3bbde9fb92 --- /dev/null +++ b/test/unit-tests/components/views/rooms/RoomListPanel/RoomListCell-test.tsx @@ -0,0 +1,44 @@ +/* + * Copyright 2025 New Vector 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 React from "react"; +import { type MatrixClient, type Room } from "matrix-js-sdk/src/matrix"; +import { render, screen } from "jest-matrix-react"; +import userEvent from "@testing-library/user-event"; + +import { mkRoom, stubClient } from "../../../../../test-utils"; +import { RoomListCell } from "../../../../../../src/components/views/rooms/RoomListPanel/RoomListCell"; +import DMRoomMap from "../../../../../../src/utils/DMRoomMap"; + +describe("", () => { + let matrixClient: MatrixClient; + let room: Room; + + beforeEach(() => { + matrixClient = stubClient(); + room = mkRoom(matrixClient, "room1"); + + DMRoomMap.makeShared(matrixClient); + jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(null); + }); + + test("should render a room cell", () => { + const onClick = jest.fn(); + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); + }); + + test("should call onClick when clicked", async () => { + const user = userEvent.setup(); + + const onClick = jest.fn(); + render(); + + await user.click(screen.getByRole("button", { name: `Open room ${room.name}` })); + expect(onClick).toHaveBeenCalled(); + }); +}); diff --git a/test/unit-tests/components/views/rooms/RoomListPanel/__snapshots__/RoomListCell-test.tsx.snap b/test/unit-tests/components/views/rooms/RoomListPanel/__snapshots__/RoomListCell-test.tsx.snap new file mode 100644 index 0000000000..cf7c8b854a --- /dev/null +++ b/test/unit-tests/components/views/rooms/RoomListPanel/__snapshots__/RoomListCell-test.tsx.snap @@ -0,0 +1,50 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should render a room cell 1`] = ` + + + +`;