Improve workspace navigation and render isolation

This commit is contained in:
Mohamed Boudra
2026-04-20 16:14:22 +07:00
parent 403fb03c97
commit a6423f7f0a
46 changed files with 2801 additions and 862 deletions
@@ -1,9 +1,26 @@
import { describe, expect, it } from "vitest";
import type { DaemonClient } from "@server/client/daemon-client";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
buildWorkspaceArchiveRedirectRoute,
resolveWorkspaceArchiveRedirectWorkspaceId,
} from "@/utils/workspace-archive-navigation";
import type { WorkspaceDescriptor } from "@/stores/session-store";
import { useSessionStore } from "@/stores/session-store";
import {
activateNavigationWorkspaceSelection,
syncNavigationActiveWorkspace,
} from "@/stores/navigation-active-workspace-store";
import { redirectIfArchivingActiveWorkspace } from "@/utils/sidebar-workspace-archive-redirect";
const { replaceMock } = vi.hoisted(() => ({
replaceMock: vi.fn(),
}));
vi.mock("expo-router", () => ({
router: {
replace: replaceMock,
},
}));
function workspace(
input: Partial<WorkspaceDescriptor> & Pick<WorkspaceDescriptor, "id">,
@@ -76,3 +93,53 @@ describe("resolveWorkspaceArchiveRedirectWorkspaceId", () => {
).toBe("/h/server-1");
});
});
describe("redirectIfArchivingActiveWorkspace", () => {
afterEach(() => {
replaceMock.mockClear();
syncNavigationActiveWorkspace({ current: null });
useSessionStore.getState().clearSession("server-1");
});
it("does not replace the route when archiving an inactive workspace", () => {
useSessionStore.getState().initializeSession("server-1", null as unknown as DaemonClient);
useSessionStore.getState().setWorkspaces(
"server-1",
new Map([
["main", workspace({ id: "main", workspaceKind: "local_checkout" })],
["feature", workspace({ id: "feature", name: "feature" })],
]),
);
activateNavigationWorkspaceSelection({ serverId: "server-1", workspaceId: "main" });
expect(
redirectIfArchivingActiveWorkspace({
serverId: "server-1",
workspaceId: "feature",
}),
).toBe(false);
expect(replaceMock).not.toHaveBeenCalled();
});
it("replaces the route at action time when archiving the active workspace", () => {
useSessionStore.getState().initializeSession("server-1", null as unknown as DaemonClient);
useSessionStore.getState().setWorkspaces(
"server-1",
new Map([
["main", workspace({ id: "main", workspaceKind: "local_checkout" })],
["feature", workspace({ id: "feature", name: "feature" })],
]),
);
activateNavigationWorkspaceSelection({ serverId: "server-1", workspaceId: "feature" });
expect(
redirectIfArchivingActiveWorkspace({
serverId: "server-1",
workspaceId: "feature",
}),
).toBe(true);
expect(replaceMock).toHaveBeenCalledWith("/h/server-1/workspace/main");
});
});