Remove SpaceStore singleton (#34088)
* Remove dead code * Remove LegacyCallHandler singleton Route via SDKContext to cut import cycles * Remove SpaceStore singleton Route via SDKContext to cut import cycles * Fix tests * Fix tests * Fix tests * Fix tests * Iterate * Post-merge fixup * Iterate
This commit is contained in:
@@ -34,7 +34,7 @@ import { TimelineRenderingType } from "../../../src/contexts/RoomContext";
|
||||
import { MatrixDispatcher } from "../../../src/dispatcher/dispatcher";
|
||||
import { UPDATE_EVENT } from "../../../src/stores/AsyncStore";
|
||||
import { type ActiveRoomChangedPayload } from "../../../src/dispatcher/payloads/ActiveRoomChangedPayload";
|
||||
import { SpaceStoreClass } from "../../../src/stores/spaces/SpaceStore";
|
||||
import SpaceStore from "../../../src/stores/spaces/SpaceStore";
|
||||
import { TestSDKContext } from "../TestSDKContext";
|
||||
import { type ViewRoomPayload } from "../../../src/dispatcher/payloads/ViewRoomPayload";
|
||||
import Modal from "../../../src/Modal";
|
||||
@@ -60,7 +60,7 @@ const MockPosthogAnalytics = <jest.Mock<PosthogAnalytics>>(<unknown>PosthogAnaly
|
||||
jest.mock("../../../src/SlidingSyncManager");
|
||||
const MockSlidingSyncManager = <jest.Mock<SlidingSyncManager>>(<unknown>SlidingSyncManager);
|
||||
jest.mock("../../../src/stores/spaces/SpaceStore");
|
||||
const MockSpaceStore = <jest.Mock<SpaceStoreClass>>(<unknown>SpaceStoreClass);
|
||||
const MockSpaceStore = <jest.Mock<SpaceStore>>(<unknown>SpaceStore);
|
||||
|
||||
// mock VoiceRecording because it contains all the audio APIs
|
||||
jest.mock("../../../src/audio/VoiceRecording", () => ({
|
||||
|
||||
@@ -24,7 +24,6 @@ import { mkEvent, mkMessage, mkSpace, mkStubRoom, stubClient, upsertRoomStateEve
|
||||
import { getMockedRooms } from "./skip-list/getMockedRooms";
|
||||
import { AlphabeticSorter } from "../../../../src/stores/room-list-v3/skip-list/sorters/AlphabeticSorter";
|
||||
import dispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
|
||||
import { MetaSpace, UPDATE_SELECTED_SPACE } from "../../../../src/stores/spaces";
|
||||
import { DefaultTagID } from "../../../../src/stores/room-list-v3/skip-list/tag";
|
||||
import { FilterEnum } from "../../../../src/stores/room-list-v3/skip-list/filters";
|
||||
@@ -37,6 +36,7 @@ import * as utilsRLS from "../../../../src/stores/room-list-v3/utils.ts";
|
||||
import { Action } from "../../../../src/dispatcher/actions";
|
||||
import { SettingLevel } from "../../../../src/settings/SettingLevel.ts";
|
||||
import { CHATS_TAG } from "../../../../src/stores/room-list-v3/section";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass.ts";
|
||||
|
||||
describe("RoomListStoreV3", () => {
|
||||
async function getRoomListStore() {
|
||||
@@ -54,9 +54,13 @@ describe("RoomListStoreV3", () => {
|
||||
cb(0);
|
||||
return 0;
|
||||
});
|
||||
jest.spyOn(SpaceStore.instance, "isRoomInSpace").mockImplementation((space) => space === MetaSpace.Home);
|
||||
jest.spyOn(SpaceStore.instance, "activeSpace", "get").mockImplementation(() => MetaSpace.Home);
|
||||
jest.spyOn(SpaceStore.instance, "storeReadyPromise", "get").mockImplementation(() => Promise.resolve());
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "isRoomInSpace").mockImplementation(
|
||||
(space) => space === MetaSpace.Home,
|
||||
);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "activeSpace", "get").mockImplementation(() => MetaSpace.Home);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "storeReadyPromise", "get").mockImplementation(() =>
|
||||
Promise.resolve(),
|
||||
);
|
||||
jest.spyOn(RoomNotificationStateStore.instance, "getRoomState").mockImplementation((room) => {
|
||||
const state = {
|
||||
isUnread: false,
|
||||
@@ -448,12 +452,14 @@ describe("RoomListStoreV3", () => {
|
||||
}
|
||||
|
||||
function setupMocks(spaceRoom: Room, roomIds: string[]) {
|
||||
jest.spyOn(SpaceStore.instance, "isRoomInSpace").mockImplementation((space, id) => {
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "isRoomInSpace").mockImplementation((space, id) => {
|
||||
if (space === MetaSpace.Home && !roomIds.includes(id)) return true;
|
||||
if (space === spaceRoom.roomId && roomIds.includes(id)) return true;
|
||||
return false;
|
||||
});
|
||||
jest.spyOn(SpaceStore.instance, "activeSpace", "get").mockImplementation(() => spaceRoom.roomId);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "activeSpace", "get").mockImplementation(
|
||||
() => spaceRoom.roomId,
|
||||
);
|
||||
}
|
||||
|
||||
function getClientAndRooms() {
|
||||
@@ -497,7 +503,7 @@ describe("RoomListStoreV3", () => {
|
||||
const { spaceRoom, roomIds } = createSpace(rooms, [6, 8, 13, 27, 75], client);
|
||||
|
||||
// Mock the space store
|
||||
jest.spyOn(SpaceStore.instance, "isRoomInSpace").mockImplementation((space, id) => {
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "isRoomInSpace").mockImplementation((space, id) => {
|
||||
if (space === MetaSpace.Home && !roomIds.includes(id)) return true;
|
||||
if (space === spaceRoom.roomId && roomIds.includes(id)) return true;
|
||||
return false;
|
||||
@@ -518,8 +524,10 @@ describe("RoomListStoreV3", () => {
|
||||
}
|
||||
|
||||
// Lets switch to the space
|
||||
jest.spyOn(SpaceStore.instance, "activeSpace", "get").mockImplementation(() => spaceRoom.roomId);
|
||||
SpaceStore.instance.emit(UPDATE_SELECTED_SPACE);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "activeSpace", "get").mockImplementation(
|
||||
() => spaceRoom.roomId,
|
||||
);
|
||||
SDKContextClass.instance.spaceStore.emit(UPDATE_SELECTED_SPACE);
|
||||
expect(fn).toHaveBeenCalled();
|
||||
const result2 = store
|
||||
.getSortedRoomsInActiveSpace()
|
||||
@@ -1152,11 +1160,11 @@ describe("RoomListStoreV3", () => {
|
||||
|
||||
const spaceRoomId = "!space1:matrix.org";
|
||||
const inSpaceIds = [3, 10, 20].map((i) => rooms[i].roomId);
|
||||
jest.spyOn(SpaceStore.instance, "isRoomInSpace").mockImplementation((space, id) => {
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "isRoomInSpace").mockImplementation((space, id) => {
|
||||
if (space === spaceRoomId && inSpaceIds.includes(id)) return true;
|
||||
return false;
|
||||
});
|
||||
jest.spyOn(SpaceStore.instance, "activeSpace", "get").mockImplementation(() => spaceRoomId);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "activeSpace", "get").mockImplementation(() => spaceRoomId);
|
||||
|
||||
const store = new RoomListStoreV3Class(dispatcher);
|
||||
await store.start();
|
||||
|
||||
@@ -25,7 +25,7 @@ import { CreateSectionDialog } from "../../../../src/components/views/dialogs/Cr
|
||||
import { RemoveSectionDialog } from "../../../../src/components/views/dialogs/RemoveSectionDialog";
|
||||
import { DefaultTagID } from "../../../../src/stores/room-list-v3/skip-list/tag";
|
||||
import { MetaSpace } from "../../../../src/stores/spaces";
|
||||
import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass.ts";
|
||||
|
||||
describe("section", () => {
|
||||
afterEach(() => {
|
||||
@@ -39,8 +39,8 @@ describe("section", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
// Default: no known spaces
|
||||
jest.spyOn(SpaceStore.instance, "enabledMetaSpaces", "get").mockReturnValue([]);
|
||||
jest.spyOn(SpaceStore.instance, "spacePanelSpaces", "get").mockReturnValue([]);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "enabledMetaSpaces", "get").mockReturnValue([]);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "spacePanelSpaces", "get").mockReturnValue([]);
|
||||
});
|
||||
|
||||
it.each([null, false, 42, "string", []] as const)("returns an empty object when the raw value is %p", (raw) => {
|
||||
@@ -80,7 +80,9 @@ describe("section", () => {
|
||||
});
|
||||
|
||||
it("keeps spaceId when the meta-space is enabled", () => {
|
||||
jest.spyOn(SpaceStore.instance, "enabledMetaSpaces", "get").mockReturnValue([MetaSpace.Home]);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "enabledMetaSpaces", "get").mockReturnValue([
|
||||
MetaSpace.Home,
|
||||
]);
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue({
|
||||
[validTag]: { ...validEntry, spaceId: MetaSpace.Home },
|
||||
});
|
||||
@@ -89,7 +91,9 @@ describe("section", () => {
|
||||
|
||||
it("keeps spaceId when the real space room exists", () => {
|
||||
const spaceId = "!space:server";
|
||||
jest.spyOn(SpaceStore.instance, "spacePanelSpaces", "get").mockReturnValue([{ roomId: spaceId } as Room]);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "spacePanelSpaces", "get").mockReturnValue([
|
||||
{ roomId: spaceId } as Room,
|
||||
]);
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue({
|
||||
[validTag]: { ...validEntry, spaceId },
|
||||
});
|
||||
@@ -101,8 +105,8 @@ describe("section", () => {
|
||||
const tag = "element.io.section.abc";
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SpaceStore.instance, "enabledMetaSpaces", "get").mockReturnValue([]);
|
||||
jest.spyOn(SpaceStore.instance, "spacePanelSpaces", "get").mockReturnValue([]);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "enabledMetaSpaces", "get").mockReturnValue([]);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "spacePanelSpaces", "get").mockReturnValue([]);
|
||||
});
|
||||
|
||||
it("returns an empty array when the raw value is not an array", () => {
|
||||
@@ -131,8 +135,8 @@ describe("section", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue(null);
|
||||
jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined);
|
||||
jest.spyOn(SpaceStore.instance, "enabledMetaSpaces", "get").mockReturnValue([]);
|
||||
jest.spyOn(SpaceStore.instance, "spacePanelSpaces", "get").mockReturnValue([]);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "enabledMetaSpaces", "get").mockReturnValue([]);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "spacePanelSpaces", "get").mockReturnValue([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
||||
@@ -15,12 +15,12 @@ import { RoomSkipList } from "../../../../../src/stores/room-list-v3/skip-list/R
|
||||
import { RecencySorter } from "../../../../../src/stores/room-list-v3/skip-list/sorters/RecencySorter";
|
||||
import { AlphabeticSorter } from "../../../../../src/stores/room-list-v3/skip-list/sorters/AlphabeticSorter";
|
||||
import { getMockedRooms } from "./getMockedRooms";
|
||||
import SpaceStore from "../../../../../src/stores/spaces/SpaceStore";
|
||||
import { MetaSpace } from "../../../../../src/stores/spaces";
|
||||
import { RoomNotificationStateStore } from "../../../../../src/stores/notifications/RoomNotificationStateStore";
|
||||
import { FavouriteFilter } from "../../../../../src/stores/room-list-v3/skip-list/filters/FavouriteFilter";
|
||||
import { FilterEnum } from "../../../../../src/stores/room-list-v3/skip-list/filters";
|
||||
import { DefaultTagID } from "../../../../../src/stores/room-list-v3/skip-list/tag";
|
||||
import { SDKContextClass } from "../../../../../src/contexts/SDKContextClass.ts";
|
||||
|
||||
describe("RoomSkipList", () => {
|
||||
function generateSkipList(roomCount?: number): {
|
||||
@@ -38,9 +38,13 @@ describe("RoomSkipList", () => {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SpaceStore.instance, "isRoomInSpace").mockImplementation((space) => space === MetaSpace.Home);
|
||||
jest.spyOn(SpaceStore.instance, "activeSpace", "get").mockImplementation(() => MetaSpace.Home);
|
||||
jest.spyOn(SpaceStore.instance, "storeReadyPromise", "get").mockImplementation(() => Promise.resolve());
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "isRoomInSpace").mockImplementation(
|
||||
(space) => space === MetaSpace.Home,
|
||||
);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "activeSpace", "get").mockImplementation(() => MetaSpace.Home);
|
||||
jest.spyOn(SDKContextClass.instance.spaceStore, "storeReadyPromise", "get").mockImplementation(() =>
|
||||
Promise.resolve(),
|
||||
);
|
||||
jest.spyOn(RoomNotificationStateStore.instance, "getRoomState").mockImplementation(() => {
|
||||
const state = {
|
||||
mute: false,
|
||||
|
||||
Reference in New Issue
Block a user