RoomList: add back Favourites and Low Priority filters when sections are disabled (#34162)

* Add back Favourites and Low Priority filter into shared components

* Wireup RoomList.showSections and filters in room list vm

* Add e2e test for filters and showSection setting
This commit is contained in:
Florian Duros
2026-07-09 10:25:45 +00:00
committed by GitHub
parent 707d5a4353
commit f21a3f5413
6 changed files with 155 additions and 2 deletions
@@ -350,6 +350,75 @@ describe("RoomListViewModel", () => {
"!room3:server",
]);
});
describe("Favourites and Low Priority filters (RoomList.showSections)", () => {
function mockShowSections(showSections: boolean): void {
jest.spyOn(SettingsStore, "getValue").mockImplementation((setting) => {
if (setting === "RoomList.showSections") return showSections;
if (setting === "RoomList.CustomSectionData") return {};
if (setting === "RoomList.OrderedCustomSections") return [];
return undefined as any;
});
}
it("hides the Favourites and Low Priority filters when sections are enabled", () => {
mockShowSections(true);
viewModel = new RoomListViewModel({ client: matrixClient });
const { filterIds } = viewModel.getSnapshot();
expect(filterIds).not.toContain("favourite");
expect(filterIds).not.toContain("low_priority");
});
it("shows the Favourites and Low Priority filters when sections are disabled", () => {
mockShowSections(false);
viewModel = new RoomListViewModel({ client: matrixClient });
const { filterIds } = viewModel.getSnapshot();
expect(filterIds).toContain("favourite");
expect(filterIds).toContain("low_priority");
});
it("recomputes the filters and clears the active filter when the setting changes", () => {
let showSections = false;
let watchCallback: () => void = () => {};
jest.spyOn(SettingsStore, "getValue").mockImplementation((setting) => {
if (setting === "RoomList.showSections") return showSections;
if (setting === "RoomList.CustomSectionData") return {};
if (setting === "RoomList.OrderedCustomSections") return [];
return undefined as any;
});
jest.spyOn(SettingsStore, "watchSetting").mockImplementation((setting, _room, callback) => {
if (setting === "RoomList.showSections") watchCallback = callback as () => void;
return "watcher-id";
});
viewModel = new RoomListViewModel({ client: matrixClient });
expect(viewModel.getSnapshot().filterIds).toContain("favourite");
// Activate the Favourites filter
jest.spyOn(RoomListStoreV3.instance, "getSortedRoomsInActiveSpace").mockReturnValue({
spaceId: "home",
sections: [{ tag: CHATS_TAG, rooms: [room1] }],
filterKeys: [FilterEnum.FavouriteFilter],
});
viewModel.onToggleFilter("favourite");
expect(viewModel.getSnapshot().activeFilterId).toBe("favourite");
// Enabling sections hides the Favourites filter and resets the active filter
showSections = true;
jest.spyOn(RoomListStoreV3.instance, "getSortedRoomsInActiveSpace").mockReturnValue({
spaceId: "home",
sections: [{ tag: CHATS_TAG, rooms: [room1, room2, room3] }],
});
watchCallback();
const snapshot = viewModel.getSnapshot();
expect(snapshot.filterIds).not.toContain("favourite");
expect(snapshot.filterIds).not.toContain("low_priority");
expect(snapshot.activeFilterId).toBeUndefined();
});
});
});
describe("Room item view models", () => {