|
| 1 | +import * as NodeModule from "node:module"; |
1 | 2 | import type { ParamListBase, StackNavigationState } from "@react-navigation/native"; |
2 | 3 | import { describe, expect, it } from "vite-plus/test"; |
3 | 4 |
|
4 | 5 | import { |
| 6 | + nativeWorkspacePopAction, |
5 | 7 | nativeWorkspacePopCount, |
6 | 8 | projectWorkspaceStack, |
7 | 9 | partitionStackPresentations, |
8 | 10 | reconcileStackScreens, |
9 | 11 | } from "./workspace-stack-projection"; |
10 | 12 |
|
| 13 | +// Load the same router as native navigation without importing React Native into Node. |
| 14 | +const requireNavigation = NodeModule.createRequire( |
| 15 | + NodeModule.createRequire(import.meta.url).resolve("@react-navigation/native/package.json"), |
| 16 | +); |
| 17 | +const { StackRouter } = requireNavigation("@react-navigation/routers") as { |
| 18 | + StackRouter: typeof import("@react-navigation/native").StackRouter; |
| 19 | +}; |
| 20 | + |
11 | 21 | const home = { key: "home", name: "Home" }; |
12 | 22 | const thread = { key: "thread", name: "Thread", params: { threadId: "draft-thread" } }; |
13 | 23 | const files = { key: "files", name: "ThreadFiles", params: thread.params }; |
@@ -78,6 +88,24 @@ describe("workspace router projection", () => { |
78 | 88 | }); |
79 | 89 |
|
80 | 90 | describe("native workspace dismissal", () => { |
| 91 | + it("dismisses a sheet and its pushed pages without removing the underlying draft", () => { |
| 92 | + const state = history([home, thread, settings, legal]); |
| 93 | + const action = nativeWorkspacePopAction(state, settings.key)!; |
| 94 | + const next = StackRouter({}).getStateForAction(state, action, { |
| 95 | + routeNames: state.routeNames, |
| 96 | + routeParamList: {}, |
| 97 | + routeGetIdList: {}, |
| 98 | + }); |
| 99 | + expect(next?.routes).toEqual([home, thread]); |
| 100 | + expect(next?.routes[1]).toBe(thread); |
| 101 | + expect(next?.index).toBe(1); |
| 102 | + }); |
| 103 | + |
| 104 | + it("does not dismiss retained sheets beyond the active index", () => { |
| 105 | + const state = { ...history([home, thread, settings, legal]), index: 1 }; |
| 106 | + expect(nativeWorkspacePopAction(state, settings.key)).toBeNull(); |
| 107 | + expect(nativeWorkspacePopAction(state, legal.key)).toBeNull(); |
| 108 | + }); |
81 | 109 | it("pops a native dismissed file while keeping the conversation and its draft mounted", () => { |
82 | 110 | expect(nativeWorkspacePopCount(history([home, thread, files]), files.key)).toBe(1); |
83 | 111 | }); |
|
0 commit comments