Skip to content

Commit ff194ec

Browse files
committed
Update room list vm tests
1 parent f8edefa commit ff194ec

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

apps/web/test/viewmodels/room-list/RoomListViewModel-test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ import { DefaultTagID } from "../../../src/stores/room-list-v3/skip-list/tag";
2929
import SettingsStore from "../../../src/settings/SettingsStore";
3030
import { tagRoom } from "../../../src/utils/room/tagRoom";
3131
import { getSectionTagForRoom } from "../../../src/utils/room/getSectionTagForRoom";
32-
import { CHATS_TAG, CUSTOM_SECTION_TAG_PREFIX } from "../../../src/stores/room-list-v3/section";
32+
import {
33+
CHATS_TAG,
34+
CUSTOM_SECTION_TAG_PREFIX,
35+
type SectionExpansionState,
36+
} from "../../../src/stores/room-list-v3/section";
3337
import { MetaSpace } from "../../../src/stores/spaces";
3438
import { RoomNotificationStateStore } from "../../../src/stores/notifications/RoomNotificationStateStore";
3539
import { type RoomNotificationState } from "../../../src/stores/notifications/RoomNotificationState";
@@ -55,9 +59,27 @@ describe("RoomListViewModel", () => {
5559
let room2: Room;
5660
let room3: Room;
5761
let viewModel: RoomListViewModel;
62+
// In-memory backing store for the persisted section expansion setting, reset each test so
63+
// collapse state does not leak between tests and writes round-trip synchronously.
64+
let sectionExpansionState: SectionExpansionState;
5865

5966
beforeEach(() => {
6067
matrixClient = createTestClient();
68+
69+
sectionExpansionState = {};
70+
const realGetValue = SettingsStore.getValue.bind(SettingsStore);
71+
jest.spyOn(SettingsStore, "getValue").mockImplementation((setting, roomId, excludeDefault) => {
72+
if (setting === "RoomList.SectionExpansionState") return sectionExpansionState;
73+
return realGetValue(setting, roomId, excludeDefault);
74+
});
75+
const realSetValue = SettingsStore.setValue.bind(SettingsStore);
76+
jest.spyOn(SettingsStore, "setValue").mockImplementation(async (setting, roomId, level, value) => {
77+
if (setting === "RoomList.SectionExpansionState") {
78+
sectionExpansionState = value as SectionExpansionState;
79+
return;
80+
}
81+
return realSetValue(setting, roomId, level, value);
82+
});
6183
sdkContext = new TestSDKContext();
6284
sdkContext._client = matrixClient;
6385
room1 = mkStubRoom("!room1:server", "Room 1", matrixClient);
@@ -428,6 +450,7 @@ describe("RoomListViewModel", () => {
428450
if (setting === "RoomList.showSections") return showSections;
429451
if (setting === "RoomList.CustomSectionData") return {};
430452
if (setting === "RoomList.OrderedCustomSections") return [];
453+
if (setting === "RoomList.SectionExpansionState") return {};
431454
return undefined as any;
432455
});
433456
}
@@ -465,6 +488,7 @@ describe("RoomListViewModel", () => {
465488
if (setting === "RoomList.showSections") return showSections;
466489
if (setting === "RoomList.CustomSectionData") return {};
467490
if (setting === "RoomList.OrderedCustomSections") return [];
491+
if (setting === "RoomList.SectionExpansionState") return {};
468492
return undefined as any;
469493
});
470494
jest.spyOn(SettingsStore, "watchSetting").mockImplementation((setting, _room, callback) => {

0 commit comments

Comments
 (0)