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:
@@ -18,7 +18,6 @@ import { shouldShowComponent } from "../../../../../src/customisations/helpers/U
|
||||
import { UIComponent } from "../../../../../src/settings/UIFeature";
|
||||
import { mkStubRoom, wrapInMatrixClientContext, wrapInSdkContext } from "../../../../test-utils";
|
||||
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||
import SpaceStore from "../../../../../src/stores/spaces/SpaceStore";
|
||||
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||
import { type SpaceNotificationState } from "../../../../../src/stores/notifications/SpaceNotificationState";
|
||||
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
||||
@@ -99,10 +98,9 @@ jest.mock("../../../../../src/stores/spaces/SpaceStore", () => {
|
||||
getNotificationState = () => null as SpaceNotificationState | null;
|
||||
setActiveSpace = jest.fn();
|
||||
moveRootSpace = jest.fn();
|
||||
start = jest.fn();
|
||||
}
|
||||
return {
|
||||
instance: new MockSpaceStore(),
|
||||
};
|
||||
return MockSpaceStore;
|
||||
});
|
||||
|
||||
jest.mock("../../../../../src/customisations/helpers/UIComponents", () => ({
|
||||
@@ -135,7 +133,7 @@ describe("<SpacePanel />", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
SpaceStore.instance.enabledMetaSpaces.push(MetaSpace.Home, MetaSpace.Orphans, MetaSpace.VideoRooms);
|
||||
sdkContext.spaceStore.enabledMetaSpaces.push(MetaSpace.Home, MetaSpace.Orphans, MetaSpace.VideoRooms);
|
||||
mocked(shouldShowComponent).mockClear().mockReturnValue(true);
|
||||
});
|
||||
afterEach(() => {
|
||||
@@ -186,7 +184,7 @@ describe("<SpacePanel />", () => {
|
||||
});
|
||||
|
||||
it("should allow rearranging via drag and drop", async () => {
|
||||
(SpaceStore.instance.spacePanelSpaces as any) = [
|
||||
(sdkContext.spaceStore.spacePanelSpaces as any) = [
|
||||
mkStubRoom("!room1:server", "Room 1", mockClient),
|
||||
mkStubRoom("!room2:server", "Room 2", mockClient),
|
||||
mkStubRoom("!room3:server", "Room 3", mockClient),
|
||||
@@ -201,7 +199,7 @@ describe("<SpacePanel />", () => {
|
||||
await move(room1, DragDirection.DOWN);
|
||||
await drop(room1);
|
||||
|
||||
expect(SpaceStore.instance.moveRootSpace).toHaveBeenCalledWith(0, 1);
|
||||
expect(sdkContext.spaceStore.moveRootSpace).toHaveBeenCalledWith(0, 1);
|
||||
});
|
||||
|
||||
it("should be able to open the user menu via dispatcher", async () => {
|
||||
|
||||
@@ -10,16 +10,15 @@ import React from "react";
|
||||
import { fireEvent, getByTestId, render } from "jest-matrix-react";
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import { mkRoom, stubClient } from "../../../../test-utils";
|
||||
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
|
||||
import { clientAndSDKContextRenderOptions, mkRoom, stubClient } from "../../../../test-utils";
|
||||
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||
import defaultDispatcher from "../../../../../src/dispatcher/dispatcher";
|
||||
import { Action } from "../../../../../src/dispatcher/actions";
|
||||
import { SpaceItem, SpaceButton } from "../../../../../src/components/views/spaces/SpaceTreeLevel";
|
||||
import { MetaSpace, type SpaceKey } from "../../../../../src/stores/spaces";
|
||||
import SpaceStore from "../../../../../src/stores/spaces/SpaceStore";
|
||||
import { StaticNotificationState } from "../../../../../src/stores/notifications/StaticNotificationState";
|
||||
import { NotificationLevel } from "../../../../../src/stores/notifications/NotificationLevel";
|
||||
import { SDKContextClass } from "../../../../../src/contexts/SDKContextClass";
|
||||
|
||||
jest.mock("../../../../../src/stores/spaces/SpaceStore", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
@@ -29,15 +28,16 @@ jest.mock("../../../../../src/stores/spaces/SpaceStore", () => {
|
||||
setActiveSpace = jest.fn();
|
||||
getChildSpaces = jest.fn();
|
||||
getNotificationState = jest.fn();
|
||||
start = jest.fn();
|
||||
}
|
||||
|
||||
return { instance: new MockSpaceStore() };
|
||||
return MockSpaceStore;
|
||||
});
|
||||
|
||||
describe("SpaceButton", () => {
|
||||
stubClient();
|
||||
const space = mkRoom(MatrixClientPeg.safeGet(), "!1:example.org");
|
||||
DMRoomMap.makeShared(MatrixClientPeg.safeGet());
|
||||
const cli = stubClient();
|
||||
const space = mkRoom(cli, "!1:example.org");
|
||||
DMRoomMap.makeShared(cli);
|
||||
|
||||
const dispatchSpy = jest.spyOn(defaultDispatcher, "dispatch");
|
||||
|
||||
@@ -53,11 +53,12 @@ describe("SpaceButton", () => {
|
||||
data-testid="create-space-button"
|
||||
size="32px"
|
||||
/>,
|
||||
clientAndSDKContextRenderOptions(cli, SDKContextClass.instance),
|
||||
);
|
||||
|
||||
expect(SpaceStore.instance.setActiveSpace).not.toHaveBeenCalled();
|
||||
expect(SDKContextClass.instance.spaceStore.setActiveSpace).not.toHaveBeenCalled();
|
||||
fireEvent.click(getByTestId(container, "create-space-button"));
|
||||
expect(SpaceStore.instance.setActiveSpace).toHaveBeenCalledWith("!1:example.org");
|
||||
expect(SDKContextClass.instance.spaceStore.setActiveSpace).toHaveBeenCalledWith("!1:example.org");
|
||||
});
|
||||
|
||||
it("navigates to the space home on click if already active", () => {
|
||||
@@ -87,11 +88,12 @@ describe("SpaceButton", () => {
|
||||
data-testid="create-space-button"
|
||||
size="32px"
|
||||
/>,
|
||||
clientAndSDKContextRenderOptions(cli, SDKContextClass.instance),
|
||||
);
|
||||
|
||||
expect(SpaceStore.instance.setActiveSpace).not.toHaveBeenCalled();
|
||||
expect(SDKContextClass.instance.spaceStore.setActiveSpace).not.toHaveBeenCalled();
|
||||
fireEvent.click(getByTestId(container, "create-space-button"));
|
||||
expect(SpaceStore.instance.setActiveSpace).toHaveBeenCalledWith(MetaSpace.Home);
|
||||
expect(SDKContextClass.instance.spaceStore.setActiveSpace).toHaveBeenCalledWith(MetaSpace.Home);
|
||||
});
|
||||
|
||||
it("does nothing on click if already active", () => {
|
||||
@@ -103,12 +105,13 @@ describe("SpaceButton", () => {
|
||||
data-testid="create-space-button"
|
||||
size="32px"
|
||||
/>,
|
||||
clientAndSDKContextRenderOptions(cli, SDKContextClass.instance),
|
||||
);
|
||||
|
||||
fireEvent.click(getByTestId(container, "create-space-button"));
|
||||
expect(dispatchSpy).not.toHaveBeenCalled();
|
||||
// Re-activating the metaspace is a no-op
|
||||
expect(SpaceStore.instance.setActiveSpace).toHaveBeenCalledWith(MetaSpace.Home);
|
||||
expect(SDKContextClass.instance.spaceStore.setActiveSpace).toHaveBeenCalledWith(MetaSpace.Home);
|
||||
});
|
||||
|
||||
it("should render notificationState if one is provided", () => {
|
||||
@@ -139,11 +142,14 @@ describe("SpaceItem", () => {
|
||||
subspace.name = "Subspace";
|
||||
|
||||
it("should render a space with subspaces", () => {
|
||||
mocked(SpaceStore.instance.getChildSpaces).mockImplementation((spaceId) =>
|
||||
mocked(SDKContextClass.instance.spaceStore.getChildSpaces).mockImplementation((spaceId) =>
|
||||
spaceId === space.roomId ? [subspace] : [],
|
||||
);
|
||||
|
||||
const { asFragment, queryByText, getByLabelText } = render(<SpaceItem space={space} activeSpaces={[]} />);
|
||||
const { asFragment, queryByText, getByLabelText } = render(
|
||||
<SpaceItem space={space} activeSpaces={[]} />,
|
||||
clientAndSDKContextRenderOptions(cli, SDKContextClass.instance),
|
||||
);
|
||||
|
||||
expect(queryByText("Root Space")).toBeVisible();
|
||||
expect(queryByText("Subspace")).toBeNull();
|
||||
|
||||
Reference in New Issue
Block a user