@@ -318,38 +318,67 @@ impl From<FileListKind> for ListKind {
318318#[ cfg( test) ]
319319mod tests {
320320 use super :: * ;
321- use crate :: TimestampStrategy ;
322321 use chrono:: NaiveDate ;
322+ use gui_core:: actions:: {
323+ Action , ActionDescriptor , FileListAction , FileListKind , IconSysAction , TimestampAction ,
324+ TimestampStrategyAction ,
325+ } ;
323326 use ps2_filetypes:: sjis;
324327 use std:: path:: PathBuf ;
325328
326- #[ test]
327- fn config_from_state_appends_psu_toml_once ( ) {
329+ fn dispatch_action ( app : & mut PackerApp , descriptor : & ActionDescriptor ) {
330+ let action = descriptor. action . clone ( ) ;
331+ assert ! ( app. supports_action( action. clone( ) ) ) ;
332+ assert ! ( app. is_action_enabled( action. clone( ) ) ) ;
333+ app. trigger_action ( action) ;
334+ }
335+
336+ fn set_manual_entry ( app : & mut PackerApp , kind : FileListKind , value : & str ) {
337+ let manual_entry = app. packer_state_mut ( ) . manual_entry_mut ( kind) ;
338+ manual_entry. clear ( ) ;
339+ manual_entry. push_str ( value) ;
340+ }
341+
342+ fn app_with_prefix ( prefix : SasPrefix ) -> PackerApp {
328343 let mut app = PackerApp :: default ( ) ;
329344 app. packer_state . set_folder_base_name ( "SAVE" . to_string ( ) ) ;
330345 app. packer_state . set_psu_file_base_name ( "SAVE" . to_string ( ) ) ;
331- app. packer_state . set_selected_prefix ( SasPrefix :: App ) ;
346+ app. packer_state . set_selected_prefix ( prefix) ;
347+ app
348+ }
332349
333- let config = app. config_from_state ( ) . expect ( "configuration should build" ) ;
350+ #[ test]
351+ fn config_from_state_appends_psu_toml_once ( ) {
352+ let base_app = app_with_prefix ( SasPrefix :: App ) ;
353+ let config = base_app
354+ . config_from_state ( )
355+ . expect ( "configuration should build" ) ;
334356 assert_eq ! ( config. exclude, Some ( vec![ "psu.toml" . to_string( ) ] ) ) ;
335357 assert ! (
336- app . packer_state. exclude_files. is_empty( ) ,
358+ base_app . packer_state. exclude_files. is_empty( ) ,
337359 "building the configuration should not modify the exclude list"
338360 ) ;
339361
340- app. packer_state
341- . set_file_list_entries ( FileListKind :: Exclude , vec ! [ "DATA.BIN" . to_string( ) ] ) ;
342- let config_with_manual_entry = app
362+ let manual_add_exclude = ActionDescriptor :: new (
363+ Action :: FileList ( FileListAction :: ManualAdd ( FileListKind :: Exclude ) ) ,
364+ "Add" ,
365+ ) ;
366+
367+ let mut manual_entry_app = app_with_prefix ( SasPrefix :: App ) ;
368+ set_manual_entry ( & mut manual_entry_app, FileListKind :: Exclude , "DATA.BIN" ) ;
369+ dispatch_action ( & mut manual_entry_app, & manual_add_exclude) ;
370+ let config_with_manual_entry = manual_entry_app
343371 . config_from_state ( )
344372 . expect ( "configuration should include manual exclude" ) ;
345373 assert_eq ! (
346374 config_with_manual_entry. exclude,
347375 Some ( vec![ "DATA.BIN" . to_string( ) , "psu.toml" . to_string( ) ] )
348376 ) ;
349377
350- app. packer_state
351- . set_file_list_entries ( FileListKind :: Exclude , vec ! [ "psu.toml" . to_string( ) ] ) ;
352- let config_with_duplicate = app
378+ let mut duplicate_app = app_with_prefix ( SasPrefix :: App ) ;
379+ set_manual_entry ( & mut duplicate_app, FileListKind :: Exclude , "psu.toml" ) ;
380+ dispatch_action ( & mut duplicate_app, & manual_add_exclude) ;
381+ let config_with_duplicate = duplicate_app
353382 . config_from_state ( )
354383 . expect ( "configuration should handle duplicate entries" ) ;
355384 assert_eq ! (
@@ -360,20 +389,34 @@ mod tests {
360389
361390 #[ test]
362391 fn build_config_uses_loaded_psu_edits ( ) {
363- let mut app = PackerApp :: default ( ) ;
392+ let mut app = app_with_prefix ( SasPrefix :: Emu ) ;
364393 app. packer_state . loaded_psu_path = Some ( PathBuf :: from ( "input.psu" ) ) ;
365- app. packer_state . set_selected_prefix ( SasPrefix :: Emu ) ;
366- app. packer_state . set_folder_base_name ( "SAVE" . to_string ( ) ) ;
367- app. packer_state . set_psu_file_base_name ( "SAVE" . to_string ( ) ) ;
368394 let timestamp = NaiveDate :: from_ymd_opt ( 2023 , 11 , 14 )
369395 . and_then ( |date| date. and_hms_opt ( 12 , 34 , 56 ) )
370396 . expect ( "valid timestamp" ) ;
371397 app. packer_state . set_manual_timestamp ( Some ( timestamp) ) ;
372- app. set_timestamp_strategy ( TimestampStrategy :: Manual ) ;
373- app. packer_state
374- . set_file_list_entries ( FileListKind :: Include , vec ! [ "FILE.BIN" . to_string( ) ] ) ;
375- app. packer_state
376- . set_file_list_entries ( FileListKind :: Exclude , vec ! [ "SKIP.DAT" . to_string( ) ] ) ;
398+
399+ let select_manual_strategy = ActionDescriptor :: new (
400+ Action :: Timestamp ( TimestampAction :: SelectStrategy (
401+ TimestampStrategyAction :: Manual ,
402+ ) ) ,
403+ "Manual" ,
404+ ) ;
405+ dispatch_action ( & mut app, & select_manual_strategy) ;
406+
407+ let include_manual_add = ActionDescriptor :: new (
408+ Action :: FileList ( FileListAction :: ManualAdd ( FileListKind :: Include ) ) ,
409+ "Add include" ,
410+ ) ;
411+ let exclude_manual_add = ActionDescriptor :: new (
412+ Action :: FileList ( FileListAction :: ManualAdd ( FileListKind :: Exclude ) ) ,
413+ "Add exclude" ,
414+ ) ;
415+
416+ set_manual_entry ( & mut app, FileListKind :: Include , "FILE.BIN" ) ;
417+ dispatch_action ( & mut app, & include_manual_add) ;
418+ set_manual_entry ( & mut app, FileListKind :: Exclude , "SKIP.DAT" ) ;
419+ dispatch_action ( & mut app, & exclude_manual_add) ;
377420
378421 let config = app. build_config ( ) . expect ( "config builds successfully" ) ;
379422 assert_eq ! ( config. name, "EMU_SAVE" ) ;
@@ -387,12 +430,20 @@ mod tests {
387430
388431 #[ test]
389432 fn manual_filter_entries_allowed_without_folder ( ) {
390- let mut app = PackerApp :: default ( ) ;
391- app. packer_state . set_selected_prefix ( SasPrefix :: App ) ;
392- app. packer_state . set_folder_base_name ( "SAVE" . to_string ( ) ) ;
433+ let mut app = app_with_prefix ( SasPrefix :: App ) ;
434+ let include_manual_add = ActionDescriptor :: new (
435+ Action :: FileList ( FileListAction :: ManualAdd ( FileListKind :: Include ) ) ,
436+ "Add include" ,
437+ ) ;
438+ let exclude_manual_add = ActionDescriptor :: new (
439+ Action :: FileList ( FileListAction :: ManualAdd ( FileListKind :: Exclude ) ) ,
440+ "Add exclude" ,
441+ ) ;
393442
394- assert ! ( app. handle_add_file_from_entry( ListKind :: Include , "BOOT.ELF" ) ) ;
395- assert ! ( app. handle_add_file_from_entry( ListKind :: Exclude , "THUMBS.DB" ) ) ;
443+ set_manual_entry ( & mut app, FileListKind :: Include , "BOOT.ELF" ) ;
444+ dispatch_action ( & mut app, & include_manual_add) ;
445+ set_manual_entry ( & mut app, FileListKind :: Exclude , "THUMBS.DB" ) ;
446+ dispatch_action ( & mut app, & exclude_manual_add) ;
396447
397448 let config = app. build_config ( ) . expect ( "config builds successfully" ) ;
398449 assert_eq ! ( config. include, Some ( vec![ "BOOT.ELF" . to_string( ) ] ) ) ;
@@ -404,24 +455,31 @@ mod tests {
404455
405456 #[ test]
406457 fn manual_filter_entries_trim_and_reject_duplicates ( ) {
407- let mut app = PackerApp :: default ( ) ;
458+ let mut app = app_with_prefix ( SasPrefix :: App ) ;
459+ let include_manual_add = ActionDescriptor :: new (
460+ Action :: FileList ( FileListAction :: ManualAdd ( FileListKind :: Include ) ) ,
461+ "Add include" ,
462+ ) ;
408463
409- assert ! ( app. handle_add_file_from_entry( ListKind :: Include , " DATA.BIN " ) ) ;
464+ set_manual_entry ( & mut app, FileListKind :: Include , " DATA.BIN " ) ;
465+ dispatch_action ( & mut app, & include_manual_add) ;
410466 assert_eq ! ( app. packer_state. include_files, vec![ "DATA.BIN" ] ) ;
411467
412- assert ! ( !app. handle_add_file_from_entry( ListKind :: Include , "DATA.BIN" ) ) ;
468+ let initial_len = app. packer_state . include_files . len ( ) ;
469+ set_manual_entry ( & mut app, FileListKind :: Include , "DATA.BIN" ) ;
470+ dispatch_action ( & mut app, & include_manual_add) ;
471+ assert_eq ! ( app. packer_state. include_files. len( ) , initial_len) ;
413472 assert_eq ! ( app. packer_state. include_files, vec![ "DATA.BIN" ] ) ;
414473 assert ! ( app. packer_state. error_message. is_some( ) ) ;
415474 }
416475
417476 #[ test]
418477 fn config_from_state_uses_shift_jis_byte_linebreaks ( ) {
419- let mut app = PackerApp :: default ( ) ;
420- app. packer_state . set_selected_prefix ( SasPrefix :: App ) ;
421- app. packer_state . set_folder_base_name ( "SAVE" . to_string ( ) ) ;
422- app. packer_state . set_psu_file_base_name ( "SAVE" . to_string ( ) ) ;
423- app. icon_sys_enabled = true ;
424- app. icon_sys_use_existing = false ;
478+ let mut app = app_with_prefix ( SasPrefix :: App ) ;
479+ let enable_descriptor =
480+ ActionDescriptor :: new ( Action :: IconSys ( IconSysAction :: Enable ) , "Enable" ) ;
481+ dispatch_action ( & mut app, & enable_descriptor) ;
482+
425483 app. icon_sys_title_line1 = "メモ" . to_string ( ) ;
426484 app. icon_sys_title_line2 = "リーカード" . to_string ( ) ;
427485
0 commit comments