@@ -78,6 +78,43 @@ describe('filters store - filter business rules', () => {
7878 useFiltersStore = module . useFiltersStore
7979 } )
8080
81+ describe ( 'business rule: state should be initialised from PHP initial state using files_list_filter_* keys' , ( ) => {
82+ beforeEach ( ( ) => {
83+ vi . resetModules ( )
84+ } )
85+
86+ it ( 'reads filter_status from files_list_filter_status key' , async ( ) => {
87+ const loadStateMock = loadState as MockedFunction < typeof loadState >
88+ loadStateMock . mockReturnValue ( { files_list_filter_status : '["signed"]' , files_list_filter_modified : '' } )
89+
90+ const { useFiltersStore : freshStore } = await import ( '../../store/filters.js' )
91+ const store = freshStore ( )
92+
93+ expect ( store . filter_status ) . toBe ( '["signed"]' )
94+ } )
95+
96+ it ( 'reads filter_modified from files_list_filter_modified key' , async ( ) => {
97+ const loadStateMock = loadState as MockedFunction < typeof loadState >
98+ loadStateMock . mockReturnValue ( { files_list_filter_status : '' , files_list_filter_modified : 'last-7' } )
99+
100+ const { useFiltersStore : freshStore } = await import ( '../../store/filters.js' )
101+ const store = freshStore ( )
102+
103+ expect ( store . filter_modified ) . toBe ( 'last-7' )
104+ } )
105+
106+ it ( 'defaults to empty string when keys are absent' , async ( ) => {
107+ const loadStateMock = loadState as MockedFunction < typeof loadState >
108+ loadStateMock . mockReturnValue ( { } )
109+
110+ const { useFiltersStore : freshStore } = await import ( '../../store/filters.js' )
111+ const store = freshStore ( )
112+
113+ expect ( store . filter_status ) . toBe ( '' )
114+ expect ( store . filter_modified ) . toBe ( '' )
115+ } )
116+ } )
117+
81118 describe ( 'business rule: activeChips should return all active chips from all filters' , ( ) => {
82119 it ( 'returns empty array when there are no chips' , ( ) => {
83120 const store = useFiltersStore ( )
0 commit comments