@@ -189,4 +189,174 @@ public void SaveFileDialog_PopTree_AndNavigate (V2TestDriver d)
189
189
. WriteOutLogs ( _out )
190
190
. Stop ( ) ;
191
191
}
192
+
193
+ [ Theory ]
194
+ [ ClassData ( typeof ( V2TestDrivers ) ) ]
195
+ public void SaveFileDialog_PopTree_AndNavigate_PreserveFilenameOnDirectoryChanges_True ( V2TestDriver d )
196
+ {
197
+ var sd = new SaveDialog ( CreateExampleFileSystem ( ) ) { Modal = false } ;
198
+ sd . Style . PreserveFilenameOnDirectoryChanges = true ;
199
+
200
+ using var c = With . A ( sd , 100 , 20 , d )
201
+ . ScreenShot ( "Save dialog" , _out )
202
+ . Then ( ( ) => Assert . True ( sd . Canceled ) )
203
+ . Focus < TextField > ( _=> true )
204
+ // Clear selection by pressing right in 'file path' text box
205
+ . RaiseKeyDownEvent ( Key . CursorRight )
206
+ . AssertIsType < TextField > ( sd . Focused )
207
+ // Type a filename into the dialog
208
+ . RaiseKeyDownEvent ( Key . H )
209
+ . RaiseKeyDownEvent ( Key . E )
210
+ . RaiseKeyDownEvent ( Key . L )
211
+ . RaiseKeyDownEvent ( Key . L )
212
+ . RaiseKeyDownEvent ( Key . O )
213
+ . WaitIteration ( )
214
+ . ScreenShot ( "After typing filename 'hello'" , _out )
215
+ . AssertEndsWith ( "hello" , sd . Path )
216
+ . LeftClick < Button > ( b => b . Text == "►►" )
217
+ . ScreenShot ( "After pop tree" , _out )
218
+ . Focus < TreeView < IFileSystemInfo > > ( _ => true )
219
+ . Right ( )
220
+ . ScreenShot ( "After expand tree" , _out )
221
+ // Because of PreserveFilenameOnDirectoryChanges we should select the new dir but keep the filename
222
+ . AssertEndsWith ( "hello" , sd . Path )
223
+ . Down ( )
224
+ . ScreenShot ( "After navigate down in tree" , _out )
225
+ // Because of PreserveFilenameOnDirectoryChanges we should select the new dir but keep the filename
226
+ . AssertContains ( "empty-dir" , sd . Path )
227
+ . AssertEndsWith ( "hello" , sd . Path )
228
+ . Enter ( )
229
+ . WaitIteration ( )
230
+ . Then ( ( ) => Assert . False ( sd . Canceled ) )
231
+ . AssertContains ( "empty-dir" , sd . FileName )
232
+ . WriteOutLogs ( _out )
233
+ . Stop ( ) ;
234
+ }
235
+
236
+ [ Theory ]
237
+ [ ClassData ( typeof ( V2TestDrivers ) ) ]
238
+ public void SaveFileDialog_PopTree_AndNavigate_PreserveFilenameOnDirectoryChanges_False ( V2TestDriver d )
239
+ {
240
+ var sd = new SaveDialog ( CreateExampleFileSystem ( ) ) { Modal = false } ;
241
+ sd . Style . PreserveFilenameOnDirectoryChanges = false ;
242
+
243
+ using var c = With . A ( sd , 100 , 20 , d )
244
+ . ScreenShot ( "Save dialog" , _out )
245
+ . Then ( ( ) => Assert . True ( sd . Canceled ) )
246
+ . Focus < TextField > ( _ => true )
247
+ // Clear selection by pressing right in 'file path' text box
248
+ . RaiseKeyDownEvent ( Key . CursorRight )
249
+ . AssertIsType < TextField > ( sd . Focused )
250
+ // Type a filename into the dialog
251
+ . RaiseKeyDownEvent ( Key . H )
252
+ . RaiseKeyDownEvent ( Key . E )
253
+ . RaiseKeyDownEvent ( Key . L )
254
+ . RaiseKeyDownEvent ( Key . L )
255
+ . RaiseKeyDownEvent ( Key . O )
256
+ . WaitIteration ( )
257
+ . ScreenShot ( "After typing filename 'hello'" , _out )
258
+ . AssertEndsWith ( "hello" , sd . Path )
259
+ . LeftClick < Button > ( b => b . Text == "►►" )
260
+ . ScreenShot ( "After pop tree" , _out )
261
+ . Focus < TreeView < IFileSystemInfo > > ( _ => true )
262
+ . Right ( )
263
+ . ScreenShot ( "After expand tree" , _out )
264
+ . Down ( )
265
+ . ScreenShot ( "After navigate down in tree" , _out )
266
+ // PreserveFilenameOnDirectoryChanges is false so just select new path
267
+ . AssertEndsWith ( "empty-dir" , sd . Path )
268
+ . AssertDoesNotContain ( "hello" , sd . Path )
269
+ . Enter ( )
270
+ . WaitIteration ( )
271
+ . Then ( ( ) => Assert . False ( sd . Canceled ) )
272
+ . AssertContains ( "empty-dir" , sd . FileName )
273
+ . WriteOutLogs ( _out )
274
+ . Stop ( ) ;
275
+ }
276
+
277
+ [ Theory ]
278
+ [ ClassData ( typeof ( V2TestDrivers_WithTrueFalseParameter ) ) ]
279
+ public void SaveFileDialog_TableView_UpDown_PreserveFilenameOnDirectoryChanges_True ( V2TestDriver d , bool preserve )
280
+ {
281
+ var sd = new SaveDialog ( CreateExampleFileSystem ( ) ) { Modal = false } ;
282
+ sd . Style . PreserveFilenameOnDirectoryChanges = preserve ;
283
+
284
+ using var c = With . A ( sd , 100 , 20 , d )
285
+ . ScreenShot ( "Save dialog" , _out )
286
+ . Then ( ( ) => Assert . True ( sd . Canceled ) )
287
+ . Focus < TextField > ( _ => true )
288
+ // Clear selection by pressing right in 'file path' text box
289
+ . RaiseKeyDownEvent ( Key . CursorRight )
290
+ . AssertIsType < TextField > ( sd . Focused )
291
+ // Type a filename into the dialog
292
+ . RaiseKeyDownEvent ( Key . H )
293
+ . RaiseKeyDownEvent ( Key . E )
294
+ . RaiseKeyDownEvent ( Key . L )
295
+ . RaiseKeyDownEvent ( Key . L )
296
+ . RaiseKeyDownEvent ( Key . O )
297
+ . WaitIteration ( )
298
+ . ScreenShot ( "After typing filename 'hello'" , _out )
299
+ . AssertEndsWith ( "hello" , sd . Path )
300
+ . Focus < TableView > ( _ => true )
301
+ . ScreenShot ( "After focus table" , _out )
302
+ . Down ( )
303
+ . ScreenShot ( "After down in table" , _out ) ;
304
+
305
+ if ( preserve )
306
+ {
307
+ c . AssertContains ( "logs" , sd . Path )
308
+ . AssertEndsWith ( "hello" , sd . Path ) ;
309
+ }
310
+ else
311
+ {
312
+ c . AssertContains ( "logs" , sd . Path )
313
+ . AssertDoesNotContain ( "hello" , sd . Path ) ;
314
+ }
315
+
316
+ c . Up ( )
317
+ . ScreenShot ( "After up in table" , _out ) ;
318
+
319
+ if ( preserve )
320
+ {
321
+ c . AssertContains ( "empty-dir" , sd . Path )
322
+ . AssertEndsWith ( "hello" , sd . Path ) ;
323
+ }
324
+ else
325
+ {
326
+ c . AssertContains ( "empty-dir" , sd . Path )
327
+ . AssertDoesNotContain ( "hello" , sd . Path ) ;
328
+ }
329
+
330
+ c . Enter ( )
331
+ . ScreenShot ( "After enter in table" , _out ) ; ;
332
+
333
+
334
+ if ( preserve )
335
+ {
336
+ c . AssertContains ( "empty-dir" , sd . Path )
337
+ . AssertEndsWith ( "hello" , sd . Path ) ;
338
+ }
339
+ else
340
+ {
341
+ c . AssertContains ( "empty-dir" , sd . Path )
342
+ . AssertDoesNotContain ( "hello" , sd . Path ) ;
343
+ }
344
+
345
+ c . LeftClick < Button > ( b => b . Text == "_Save" ) ;
346
+ c . AssertFalse ( sd . Canceled ) ;
347
+
348
+ if ( preserve )
349
+ {
350
+ c . AssertContains ( "empty-dir" , sd . Path )
351
+ . AssertEndsWith ( "hello" , sd . Path ) ;
352
+ }
353
+ else
354
+ {
355
+ c . AssertContains ( "empty-dir" , sd . Path )
356
+ . AssertDoesNotContain ( "hello" , sd . Path ) ;
357
+ }
358
+
359
+ c . WriteOutLogs ( _out )
360
+ . Stop ( ) ;
361
+ }
192
362
}
0 commit comments