RoomList: fix room scroll when clicked in thread activity centre (#34179)

* Make room list handles `show_room_tile` in `Action.ViewRoom`

* Add e2e test to scroll the room list when a room in tac is clicked
This commit is contained in:
Florian Duros
2026-07-08 11:41:10 +00:00
committed by GitHub
parent bf1b77116d
commit d5932851cb
3 changed files with 155 additions and 34 deletions
@@ -1328,4 +1328,70 @@ describe("RoomListViewModel", () => {
expect(tagRoom).not.toHaveBeenCalled();
});
});
describe("show_room_tile scroll", () => {
beforeEach(() => {
// Dispatching ViewRoom is also handled by the global RoomViewStore, which calls
// MatrixClientPeg.safeGet(); stubClient sets up the peg so that doesn't throw.
stubClient();
});
it("should scroll a room into view in a flat list", async () => {
viewModel = new RoomListViewModel({ client: matrixClient });
const scrollSpy = jest.fn();
viewModel.setScrollToIndex(scrollSpy);
dispatcher.dispatch({
action: Action.ViewRoom,
room_id: "!room2:server",
show_room_tile: true,
metricsTrigger: undefined,
});
// Flat list: entry index == room index.
await waitFor(() => expect(scrollSpy).toHaveBeenCalledWith(1));
});
it("should scroll a room into view in a grouped list, accounting for section headers", async () => {
const favRoom1 = mkStubRoom("!fav1:server", "Fav 1", matrixClient);
const favRoom2 = mkStubRoom("!fav2:server", "Fav 2", matrixClient);
const regularRoom1 = mkStubRoom("!reg1:server", "Reg 1", matrixClient);
jest.spyOn(RoomListStoreV3.instance, "getSortedRoomsInActiveSpace").mockReturnValue({
spaceId: "home",
sections: [
{ tag: DefaultTagID.Favourite, rooms: [favRoom1, favRoom2] },
{ tag: CHATS_TAG, rooms: [regularRoom1] },
],
});
viewModel = new RoomListViewModel({ client: matrixClient });
const scrollSpy = jest.fn();
viewModel.setScrollToIndex(scrollSpy);
dispatcher.dispatch({
action: Action.ViewRoom,
room_id: "!reg1:server",
show_room_tile: true,
metricsTrigger: undefined,
});
// Entry space: [Fav header(0), fav1(1), fav2(2), Chats header(3), reg1(4)]
await waitFor(() => expect(scrollSpy).toHaveBeenCalledWith(4));
});
it("should not scroll when the room is not in the current list", async () => {
viewModel = new RoomListViewModel({ client: matrixClient });
const scrollSpy = jest.fn();
viewModel.setScrollToIndex(scrollSpy);
dispatcher.dispatch({
action: Action.ViewRoom,
room_id: "!room3:server",
show_room_tile: true,
metricsTrigger: undefined,
});
await waitFor(() => expect(scrollSpy).toHaveBeenCalledWith(2));
expect(scrollSpy).toHaveBeenCalledTimes(1);
});
});
});