1+ local function test_wrapper (test_fn )
2+ mock .patch (dfhack .filesystem , ' listdir_recursive' , mock .func ({}), test_fn )
3+ end
4+
15config = {
26 mode = ' fortress' ,
7+ wrapper = test_wrapper ,
38}
49
510local b = reqscript (' gui/blueprint' )
@@ -24,7 +29,9 @@ local function send_keys(...)
2429end
2530
2631local function load_ui ()
27- local view = b .BlueprintUI {}
32+ local options = {}
33+ blueprint .parse_gui_commandline (options , {})
34+ local view = b .BlueprintUI {presets = options }
2835 view :show ()
2936 return view
3037end
@@ -201,7 +208,8 @@ function test.preset_cursor()
201208 local view = b .active_screen
202209 expect .table_eq ({x = 11 , y = 12 , z = 13 }, guidm .getCursorPos ())
203210 expect .true_ (not not view .mark )
204- send_keys (' LEAVESCREEN' , ' LEAVESCREEN' ) -- cancel selection and ui
211+ -- cancel selection, ui, and look mode
212+ send_keys (' LEAVESCREEN' , ' LEAVESCREEN' , ' LEAVESCREEN' )
205213end
206214
207215-- auto enter and leave cursor-supporting mode
@@ -342,5 +350,99 @@ function test.render_status_line()
342350end
343351
344352-- edit widget for setting the blueprint name
353+ function test .preset_basename ()
354+ dfhack .run_script (' gui/blueprint' , ' imaname' )
355+ local view = b .active_screen
356+ expect .eq (' imaname' , view .subviews .name .text )
357+ send_keys (' LEAVESCREEN' ) -- leave UI
358+ end
359+
360+ function test .edit_basename ()
361+ local view = load_ui ()
362+ local name_widget = view .subviews .name
363+ expect .eq (' blueprint' , name_widget .text )
364+ send_keys (' CUSTOM_N' )
365+ expect .eq (' ' , name_widget .text )
366+ view :onInput ({_STRING = string.byte (' h' )})
367+ view :onInput ({_STRING = string.byte (' i' )})
368+ send_keys (' SELECT' )
369+ expect .eq (' hi' , name_widget .text )
370+ send_keys (' LEAVESCREEN' ) -- leave UI
371+ end
372+
373+ function test .cancel_name_edit ()
374+ local view = load_ui ()
375+ local name_widget = view .subviews .name
376+ expect .eq (' blueprint' , name_widget .text )
377+ send_keys (' CUSTOM_N' )
378+ expect .eq (' ' , name_widget .text )
379+ view :onInput ({_STRING = string.byte (' h' )})
380+ view :onInput ({_STRING = string.byte (' i' )})
381+ send_keys (' LEAVESCREEN' ) -- cancel edit
382+ expect .eq (' blueprint' , name_widget .text )
383+ send_keys (' LEAVESCREEN' ) -- leave UI
384+ end
385+
386+ function test .name_no_collision ()
387+ mock .patch (dfhack .filesystem , ' listdir_recursive' ,
388+ mock .func ({{path = ' blue-dig.csv' }}),
389+ function ()
390+ local view = load_ui ()
391+ view :updateLayout ()
392+ local name_help_label = view .subviews .name_help
393+ local name_help_text_pos = {x = name_help_label .frame_body .x1 ,
394+ y = name_help_label .frame_body .y1 }
395+ view :onRender ()
396+ expect .eq (' Set' , get_screen_word (name_help_text_pos ))
397+ send_keys (' LEAVESCREEN' ) -- cancel ui
398+ end )
399+
400+ mock .patch (dfhack .filesystem , ' listdir_recursive' ,
401+ mock .func ({{path = ' blueprint' }}),
402+ function ()
403+ local view = load_ui ()
404+ view .subviews .name .text = ' blueprint/'
405+ view .subviews .name .on_change ()
406+ view :updateLayout ()
407+ local name_help_label = view .subviews .name_help
408+ local name_help_text_pos = {x = name_help_label .frame_body .x1 ,
409+ y = name_help_label .frame_body .y1 }
410+ view :onRender ()
411+ expect .eq (' Set' , get_screen_word (name_help_text_pos ),
412+ ' dirname does not conflict with similar filename' )
413+ send_keys (' LEAVESCREEN' ) -- cancel ui
414+ end )
415+ end
416+
417+ function test .name_collision ()
418+ mock .patch (dfhack .filesystem , ' listdir_recursive' ,
419+ mock .func ({{path = ' blueprint-dig.csv' }}),
420+ function ()
421+ local view = load_ui ()
422+ view :updateLayout ()
423+ local name_help_label = view .subviews .name_help
424+ local name_help_text_pos = {x = name_help_label .frame_body .x1 ,
425+ y = name_help_label .frame_body .y1 }
426+ view :onRender ()
427+ expect .eq (' Warning:' , get_screen_word (name_help_text_pos ))
428+ send_keys (' LEAVESCREEN' ) -- cancel ui
429+ end )
430+
431+ mock .patch (dfhack .filesystem , ' listdir_recursive' ,
432+ mock .func ({{path = ' blueprint' , isdir = true }}),
433+ function ()
434+ local view = load_ui ()
435+ view .subviews .name .text = ' blueprint/'
436+ view .subviews .name .on_change ()
437+ view :updateLayout ()
438+ local name_help_label = view .subviews .name_help
439+ local name_help_text_pos = {x = name_help_label .frame_body .x1 ,
440+ y = name_help_label .frame_body .y1 }
441+ view :onRender ()
442+ expect .eq (' Warning:' , get_screen_word (name_help_text_pos ),
443+ ' dirname match generates warning' )
444+ send_keys (' LEAVESCREEN' ) -- cancel ui
445+ end )
446+ end
345447
346448-- widgets to configure which blueprint phases to output
0 commit comments