Restore the previous workspace on app start (#1101)

* Restore previous workspace on app start

* Guard workspace startup hydration

* Extract last workspace selection store
This commit is contained in:
Mohamed Boudra
2026-05-19 23:53:57 +08:00
committed by GitHub
parent 306601a0c3
commit b7a8567092
8 changed files with 280 additions and 25 deletions
@@ -13,6 +13,10 @@ const pathnameState = vi.hoisted(() => ({
const localParamsState = vi.hoisted(() => ({
value: {} as { serverId?: string | string[]; workspaceId?: string | string[] },
}));
const asyncStorageMock = vi.hoisted(() => ({
getItem: vi.fn(async () => null as string | null),
setItem: vi.fn(async () => undefined),
}));
vi.mock("expo-router", () => ({
router: routerMock,
@@ -20,6 +24,10 @@ vi.mock("expo-router", () => ({
usePathname: () => pathnameState.value,
}));
vi.mock("@react-native-async-storage/async-storage", () => ({
default: asyncStorageMock,
}));
import {
navigateToLastWorkspace,
navigateToWorkspace,
@@ -29,6 +37,7 @@ import {
describe("workspace navigation", () => {
beforeEach(() => {
routerMock.dismissTo.mockReset();
asyncStorageMock.setItem.mockClear();
pathnameState.value = "/";
localParamsState.value = {};
});
@@ -41,6 +50,10 @@ describe("workspace navigation", () => {
navigateToWorkspace("server-1", "workspace-a");
expect(routerMock.dismissTo).toHaveBeenCalledWith("/h/server-1/workspace/workspace-a");
expect(asyncStorageMock.setItem).toHaveBeenCalledWith(
"paseo:last-workspace-route-selection",
JSON.stringify({ serverId: "server-1", workspaceId: "workspace-a" }),
);
});
it("reads the active workspace from the current route", () => {