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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user