@@ -2,7 +2,6 @@ import { EnvironmentId, ProjectId } from "@t3tools/contracts";
22import { describe , expect , it } from "vite-plus/test" ;
33
44import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell" ;
5- import type { HomeProjectScope } from "../home/homeThreadList" ;
65import {
76 newTaskDestination ,
87 resolveDraftProjectSelection ,
@@ -40,19 +39,6 @@ function makeProject(
4039 } ;
4140}
4241
43- function makeScope ( projects : ReadonlyArray < EnvironmentProject > ) : HomeProjectScope {
44- return {
45- key : "github.com/t3tools/t3code" ,
46- title : "T3 Code" ,
47- representative : projects [ 0 ] ! ,
48- projects,
49- projectRefs : projects . map ( ( project ) => ( {
50- environmentId : project . environmentId ,
51- projectId : project . id ,
52- } ) ) ,
53- } ;
54- }
55-
5642describe ( "resolveEnvironmentProjectMatch" , ( ) => {
5743 it ( "follows the same repository onto the target machine" , ( ) => {
5844 const selected = makeProject ( "t3code" , "mac" , { repositoryKey : "github.com/t3tools/t3code" } ) ;
@@ -95,60 +81,89 @@ describe("resolveEnvironmentProjectMatch", () => {
9581} ) ;
9682
9783describe ( "resolveDraftProjectSelection" , ( ) => {
98- it ( "selects one logical project even when it has multiple physical workspaces" , ( ) => {
99- const projects = [ makeProject ( "t3code" ) , makeProject ( "t3code-2" ) , makeProject ( "t3code-3" ) ] ;
100- expect ( resolveDraftProjectSelection ( null , projects , [ makeScope ( projects ) ] ) ) . toEqual ( {
101- kind : "select" ,
102- project : projects [ 0 ] ,
84+ it ( "keeps the picker even when only one project is available" , ( ) => {
85+ expect ( resolveDraftProjectSelection ( null , [ makeProject ( "only" ) ] ) ) . toEqual ( { kind : "pick" } ) ;
86+ } ) ;
87+
88+ it ( "preserves an explicit project selection" , ( ) => {
89+ expect ( resolveDraftProjectSelection ( "environment:chosen" , [ makeProject ( "chosen" ) ] ) ) . toEqual ( {
90+ kind : "preserve" ,
10391 } ) ;
10492 } ) ;
10593
106- it ( "does not preserve a project key that is missing from the catalog" , ( ) => {
107- const project = makeProject ( "t3code" ) ;
108- expect (
109- resolveDraftProjectSelection ( "environment:removed" , [ project ] , [ makeScope ( [ project ] ) ] ) ,
110- ) . toEqual ( {
111- kind : "select" ,
112- project,
94+ it ( "returns to the picker when the selected project is missing" , ( ) => {
95+ expect ( resolveDraftProjectSelection ( "environment:removed" , [ makeProject ( "only" ) ] ) ) . toEqual ( {
96+ kind : "pick" ,
11397 } ) ;
11498 } ) ;
11599} ) ;
116100
117101describe ( "newTaskDestination" , ( ) => {
118- it ( "opens the current thread's project directly in split view" , ( ) => {
102+ const request = { draft : { requestId : "request" } } ;
103+
104+ it . each ( [ undefined , false ] ) ( "opens the picker when the preference is %s" , ( useLastProject ) => {
119105 const projects = [ makeProject ( "first" ) , makeProject ( "current" , "other-environment" ) ] ;
120- expect ( newTaskDestination ( true , projects , projects [ 1 ] , "request" ) ) . toEqual ( {
106+ expect (
107+ newTaskDestination ( useLastProject , projects , projects [ 1 ] , "request" , {
108+ environmentId : "environment" ,
109+ projectId : "first" ,
110+ } ) ,
111+ ) . toEqual ( request ) ;
112+ } ) ;
113+
114+ it ( "uses the current thread or draft project when enabled" , ( ) => {
115+ const projects = [ makeProject ( "first" ) , makeProject ( "current" , "other-environment" ) ] ;
116+ expect (
117+ newTaskDestination ( true , projects , projects [ 1 ] , "request" , {
118+ environmentId : "environment" ,
119+ projectId : "first" ,
120+ } ) ,
121+ ) . toEqual ( {
121122 draft : { requestId : "request" , environmentId : "other-environment" , projectId : "current" } ,
122123 } ) ;
123124 } ) ;
124- it . each ( [ true , false ] ) (
125- "leaves the draft unassigned when there is no current project (split view: %s)" ,
126- ( usesSplitView ) => {
127- const projects = [ makeProject ( "first" ) , makeProject ( "second" ) ] ;
128- expect ( newTaskDestination ( usesSplitView , projects , undefined , "request" ) ) . toEqual ( {
129- draft : { requestId : "request" } ,
130- } ) ;
131- } ,
132- ) ;
133- it . each ( [ true , false ] ) (
134- "leaves the draft unassigned when the current project is stale (split view: %s)" ,
135- ( usesSplitView ) => {
136- const projects = [ makeProject ( "first" ) , makeProject ( "second" ) ] ;
137- const currentProject = makeProject ( "first" , "removed-environment" ) ;
138- expect ( newTaskDestination ( usesSplitView , projects , currentProject , "request" ) ) . toEqual ( {
139- draft : { requestId : "request" } ,
140- } ) ;
141- } ,
142- ) ;
143- it ( "keeps the picker when there are no projects" , ( ) => {
144- expect ( newTaskDestination ( true , [ ] , undefined , "request" ) ) . toEqual ( {
145- draft : { requestId : "request" } ,
125+
126+ it ( "remembers the last project from Home without relying on project order" , ( ) => {
127+ const projects = [ makeProject ( "same-id" ) , makeProject ( "same-id" , "other-environment" ) ] ;
128+ expect (
129+ newTaskDestination ( true , projects , undefined , "request" , {
130+ environmentId : "other-environment" ,
131+ projectId : "same-id" ,
132+ } ) ,
133+ ) . toEqual ( {
134+ draft : { requestId : "request" , environmentId : "other-environment" , projectId : "same-id" } ,
146135 } ) ;
147136 } ) ;
148- it ( "opens the same draft route in compact view" , ( ) => {
149- const project = makeProject ( "current" ) ;
150- expect ( newTaskDestination ( false , [ project ] , project , "request" ) ) . toEqual ( {
151- draft : { requestId : "request" , environmentId : "environment" , projectId : "current" } ,
137+
138+ it ( "uses the remembered project when the current project is stale" , ( ) => {
139+ const project = makeProject ( "remembered" ) ;
140+ expect (
141+ newTaskDestination ( true , [ project ] , makeProject ( "removed" ) , "request" , {
142+ environmentId : "environment" ,
143+ projectId : "remembered" ,
144+ } ) ,
145+ ) . toEqual ( {
146+ draft : { requestId : "request" , environmentId : "environment" , projectId : "remembered" } ,
152147 } ) ;
153148 } ) ;
149+
150+ it . each ( [
151+ undefined ,
152+ { environmentId : "removed-environment" , projectId : "first" } ,
153+ { environmentId : "environment" , projectId : "removed" } ,
154+ ] ) ( "keeps the picker when the last project is missing or stale: %s" , ( lastProject ) => {
155+ const projects = [ makeProject ( "first" ) , makeProject ( "second" ) ] ;
156+ expect (
157+ newTaskDestination ( true , projects , makeProject ( "removed" ) , "request" , lastProject ) ,
158+ ) . toEqual ( request ) ;
159+ } ) ;
160+
161+ it ( "keeps the picker when no projects are available" , ( ) => {
162+ expect (
163+ newTaskDestination ( true , [ ] , undefined , "request" , {
164+ environmentId : "environment" ,
165+ projectId : "removed" ,
166+ } ) ,
167+ ) . toEqual ( request ) ;
168+ } ) ;
154169} ) ;
0 commit comments