diff --git a/apps/web/jest.config.ts b/apps/web/jest.config.ts index b01778758a..68bdeb4902 100644 --- a/apps/web/jest.config.ts +++ b/apps/web/jest.config.ts @@ -59,7 +59,7 @@ const config: Config = { // Coverage chokes on type definition files "!/src/**/*.d.ts", ], - coverageReporters: ["text-summary", "lcov"], + coverageReporters: ["text-summary", ["lcov", { projectRoot: "../../" }]], prettierPath: null, moduleDirectories: ["node_modules", "test/test-utils"], }; diff --git a/apps/web/src/viewmodels/room-list/RoomListViewModel.ts b/apps/web/src/viewmodels/room-list/RoomListViewModel.ts index 21a8177bd3..926735ccfc 100644 --- a/apps/web/src/viewmodels/room-list/RoomListViewModel.ts +++ b/apps/web/src/viewmodels/room-list/RoomListViewModel.ts @@ -699,7 +699,7 @@ function computeSections( ...section, rooms: isSectionExpanded(section.tag) ? section.rooms : [], })); - const isFlatList = sections.length === 1 && sections[0].tag === CHATS_TAG; + const isFlatList = sections.length === 0 || (sections.length === 1 && sections[0].tag === CHATS_TAG); return { sections, isFlatList }; } diff --git a/apps/web/test/viewmodels/room-list/RoomListViewModel-test.tsx b/apps/web/test/viewmodels/room-list/RoomListViewModel-test.tsx index 1fcb848ef1..aea7c94ea8 100644 --- a/apps/web/test/viewmodels/room-list/RoomListViewModel-test.tsx +++ b/apps/web/test/viewmodels/room-list/RoomListViewModel-test.tsx @@ -99,6 +99,7 @@ describe("RoomListViewModel", () => { expect(viewModel.getSnapshot().sections).toEqual([]); expect(viewModel.getSnapshot().isRoomListEmpty).toBe(true); + expect(viewModel.getSnapshot().isFlatList).toBe(true); }); it("should set canCreateRoom based on user rights", () => { @@ -754,6 +755,22 @@ describe("RoomListViewModel", () => { expect(viewModel.getSnapshot().sections[0].id).toBe(CHATS_TAG); }); + it("should be a flat list when the room list is empty", () => { + jest.spyOn(RoomListStoreV3.instance, "getSortedRoomsInActiveSpace").mockReturnValue({ + spaceId: "home", + sections: [ + { tag: DefaultTagID.Favourite, rooms: [] }, + { tag: CHATS_TAG, rooms: [] }, + { tag: DefaultTagID.LowPriority, rooms: [] }, + ], + }); + + viewModel = new RoomListViewModel({ client: matrixClient }); + + expect(viewModel.getSnapshot().isFlatList).toBe(true); + expect(viewModel.getSnapshot().sections).toHaveLength(0); + }); + it("should exclude favourite and low_priority from filter list", () => { viewModel = new RoomListViewModel({ client: matrixClient }); @@ -1106,12 +1123,15 @@ describe("RoomListViewModel", () => { }); }); - it("should dispatch collapseSection=undefined when it is a flat list", () => { + it.each([ + { label: "flat list", chatsRooms: true }, + { label: "empty room list", chatsRooms: false }, + ])("should dispatch collapseSection=undefined when it is a $label", ({ chatsRooms }) => { jest.spyOn(RoomListStoreV3.instance, "getSortedRoomsInActiveSpace").mockReturnValue({ spaceId: "home", sections: [ { tag: DefaultTagID.Favourite, rooms: [] }, - { tag: CHATS_TAG, rooms: [regularRoom1] }, + { tag: CHATS_TAG, rooms: chatsRooms ? [regularRoom1] : [] }, { tag: DefaultTagID.LowPriority, rooms: [] }, ], });