New room list: fix public room icon visibility when filter change (#29737)

* fix: recompute public variable when room changes in room list item view model

* test: add test to check that isPublic is computed correctly when the room changes
This commit is contained in:
Florian Duros
2025-04-14 13:59:31 +02:00
committed by GitHub
parent 2e71ec748f
commit 7ce0a76414
2 changed files with 17 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ import {
type User,
UserEvent,
} from "matrix-js-sdk/src/matrix";
import { useState } from "react";
import { useEffect, useState } from "react";
import { useTypedEventEmitter } from "../../../hooks/useEventEmitter";
import DMRoomMap from "../../../utils/DMRoomMap";
@@ -82,6 +82,11 @@ function useIsPublic(room: Room): boolean {
setIsPublic(isRoomPublic(_room));
});
// Reset the value when the room changes
useEffect(() => {
setIsPublic(isRoomPublic(room));
}, [room]);
return isPublic;
}

View File

@@ -63,6 +63,17 @@ describe("RoomAvatarViewModel", () => {
expect(vm.current.hasDecoration).toBe(true);
});
it("should recompute isPublic when room changed", async () => {
const { result: vm, rerender } = renderHook((props) => useRoomAvatarViewModel(props), { initialProps: room });
expect(vm.current.isPublic).toBe(false);
const publicRoom = mkStubRoom("roomId2", "roomName2", matrixClient);
jest.spyOn(publicRoom, "getJoinRule").mockReturnValue(JoinRule.Public);
rerender(publicRoom);
await waitFor(() => expect(vm.current.isPublic).toBe(true));
});
describe("presence", () => {
let user: User;