@@ -57,18 +57,15 @@ describe("new thread project environment", () => {
5757 } ) ;
5858
5959 it . each ( [ { } , { defaultEnvironmentId : null } ] ) (
60- "preserves the context for Automatic %j whether connected or offline " ,
60+ "keeps a connected context for Automatic %j" ,
6161 ( override ) => {
62- for ( const connected of [ connectedEnvironmentIds , new Set ( [ mac . environmentId ] ) ] ) {
63- expect (
64- resolveNewThreadProjectRef ( {
65- ...input ,
66- settingsByEnvironment : settings ( override ) ,
67- contextProjectRef : padRef ,
68- connectedEnvironmentIds : connected ,
69- } ) ,
70- ) . toEqual ( { projectRef : padRef , environmentSelection : "auto" } ) ;
71- }
62+ expect (
63+ resolveNewThreadProjectRef ( {
64+ ...input ,
65+ settingsByEnvironment : settings ( override ) ,
66+ contextProjectRef : padRef ,
67+ } ) ,
68+ ) . toEqual ( { projectRef : padRef , environmentSelection : "auto" } ) ;
7269 } ,
7370 ) ;
7471
@@ -89,6 +86,61 @@ describe("new thread project environment", () => {
8986 } ,
9087 ) ;
9188
89+ it . each ( [ { } , { defaultEnvironmentId : null } ] ) (
90+ "prefers a connected copy over an offline context for Automatic %j" ,
91+ ( override ) => {
92+ expect (
93+ resolveNewThreadProjectRef ( {
94+ ...input ,
95+ settingsByEnvironment : settings ( override ) ,
96+ contextProjectRef : padRef ,
97+ connectedEnvironmentIds : new Set ( [ mac . environmentId ] ) ,
98+ } ) ,
99+ ) . toEqual ( { projectRef : macRef , environmentSelection : "auto" } ) ;
100+ } ,
101+ ) ;
102+
103+ it ( "keeps a manual offline pick ahead of connected copies" , ( ) => {
104+ expect (
105+ resolveNewThreadProjectRef ( {
106+ ...input ,
107+ manualProjectRef : padRef ,
108+ connectedEnvironmentIds : new Set ( [ mac . environmentId ] ) ,
109+ } ) ,
110+ ) . toEqual ( { projectRef : padRef , environmentSelection : "manual" } ) ;
111+ } ) ;
112+
113+ it ( "uses the first connected copy when context and primary are offline" , ( ) => {
114+ const server = { environmentId : EnvironmentId . make ( "server" ) , id : ProjectId . make ( "server" ) } ;
115+ expect (
116+ resolveNewThreadProjectRef ( {
117+ ...input ,
118+ settingsByEnvironment : settings ( ) ,
119+ members : [ mac , pad , server ] ,
120+ contextProjectRef : padRef ,
121+ connectedEnvironmentIds : new Set ( [ server . environmentId ] ) ,
122+ } ) . projectRef ,
123+ ) . toEqual ( { environmentId : server . environmentId , projectId : server . id } ) ;
124+ } ) ;
125+
126+ it . each ( [
127+ [ { contextProjectRef : padRef } , padRef ] ,
128+ [ { contextProjectRef : null , primaryEnvironmentId : pad . environmentId } , padRef ] ,
129+ [ { contextProjectRef : null , primaryEnvironmentId : null } , macRef ] ,
130+ ] as const ) (
131+ "keeps context, primary, then member order when nothing is connected (%#)" ,
132+ ( overrides , projectRef ) => {
133+ expect (
134+ resolveNewThreadProjectRef ( {
135+ ...input ,
136+ settingsByEnvironment : settings ( ) ,
137+ connectedEnvironmentIds : new Set < EnvironmentId > ( ) ,
138+ ...overrides ,
139+ } ) . projectRef ,
140+ ) . toEqual ( projectRef ) ;
141+ } ,
142+ ) ;
143+
92144 it . each ( [ mac . environmentId , null ] ) (
93145 "ignores a disconnected first copy's stale default %j when a connected copy has a value" ,
94146 ( staleDefault ) => {
0 commit comments