Add room topic and animation (#11352)

* Create useRoomName hook

Mark RoomName component as deprecated

* Pass out-of-band data to relevant RoomHeader component

* Mark LegacyRoomHeader as deprecated

* Fix incorrect search&replace in _RoomHeader.pcss

* lintfix

* Mark room as optional in room topic hook

* Fix i18n

* Discard use of useCallback

* Change export of useRoomName

* fix ts issue

* lints

* Add room topic to room header

* lintfix

* lintfix & clamp to one line

* Revert optimisations to DecoratedRoomAvatar

* Add test for opening the room summary

* Make transition honour prefer-reduced-motion

* Fallback when room is undefined

* fix snapshot
This commit is contained in:
Germain 2023-08-02 11:54:06 +01:00 committed by GitHub
parent 8166306e0f
commit 33299af5c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 123 additions and 40 deletions

View file

@ -15,23 +15,35 @@ limitations under the License.
*/
import React from "react";
import { Mocked } from "jest-mock";
import { render } from "@testing-library/react";
import { Room } from "matrix-js-sdk/src/models/room";
import { EventType, MatrixEvent, PendingEventOrdering } from "matrix-js-sdk/src/matrix";
import userEvent from "@testing-library/user-event";
import { stubClient } from "../../../test-utils";
import RoomHeader from "../../../../src/components/views/rooms/RoomHeader";
import type { MatrixClient } from "matrix-js-sdk/src/client";
import DMRoomMap from "../../../../src/utils/DMRoomMap";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore";
import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases";
describe("Roomeader", () => {
let client: Mocked<MatrixClient>;
let room: Room;
const ROOM_ID = "!1:example.org";
let setCardSpy: jest.SpyInstance | undefined;
beforeEach(async () => {
stubClient();
room = new Room(ROOM_ID, client, "@alice:example.org");
room = new Room(ROOM_ID, MatrixClientPeg.get()!, "@alice:example.org", {
pendingEventOrdering: PendingEventOrdering.Detached,
});
DMRoomMap.setShared({
getUserIdForRoomId: jest.fn(),
} as unknown as DMRoomMap);
setCardSpy = jest.spyOn(RightPanelStore.instance, "setCard");
});
it("renders with no props", () => {
@ -55,4 +67,29 @@ describe("Roomeader", () => {
);
expect(container).toHaveTextContent(OOB_NAME);
});
it("renders the room topic", async () => {
const TOPIC = "Hello World!";
const roomTopic = new MatrixEvent({
type: EventType.RoomTopic,
event_id: "$00002",
room_id: room.roomId,
sender: "@alice:example.com",
origin_server_ts: 1,
content: { topic: TOPIC },
state_key: "",
});
await room.addLiveEvents([roomTopic]);
const { container } = render(<RoomHeader room={room} />);
expect(container).toHaveTextContent(TOPIC);
});
it("opens the room summary", async () => {
const { container } = render(<RoomHeader room={room} />);
await userEvent.click(container.firstChild! as Element);
expect(setCardSpy).toHaveBeenCalledWith({ phase: RightPanelPhases.RoomSummary });
});
});