Skip to content

Commit 7ab6e43

Browse files
test(store/filters): add filterModifiedRange getter and filter_modified persistence tests
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 911b372 commit 7ab6e43

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

src/tests/store/filters.spec.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,47 @@ describe('filters store - filter business rules', () => {
157157
})
158158
})
159159

160+
describe('business rule: filterModifiedRange should compute date range from preset id', () => {
161+
it('returns null when filter_modified is empty', () => {
162+
const store = useFiltersStore()
163+
store.filter_modified = ''
164+
165+
expect(store.filterModifiedRange).toBeNull()
166+
})
167+
168+
it('returns null for unknown preset id', () => {
169+
const store = useFiltersStore()
170+
store.filter_modified = 'unknown-preset'
171+
172+
expect(store.filterModifiedRange).toBeNull()
173+
})
174+
175+
it.each(['today', 'last-7', 'last-30', 'this-year', 'last-year'])('returns { start, end } for preset "%s"', (presetId) => {
176+
const store = useFiltersStore()
177+
store.filter_modified = presetId
178+
179+
const range = store.filterModifiedRange
180+
expect(range).not.toBeNull()
181+
expect(range?.start).toBeTypeOf('number')
182+
expect(range?.end).toBeTypeOf('number')
183+
expect(range!.start).toBeLessThan(range!.end)
184+
})
185+
186+
it('today preset: start is midnight and end is end of day', () => {
187+
const store = useFiltersStore()
188+
store.filter_modified = 'today'
189+
190+
const range = store.filterModifiedRange!
191+
const startDate = new Date(range.start)
192+
const endDate = new Date(range.end)
193+
194+
expect(startDate.getHours()).toBe(0)
195+
expect(startDate.getMinutes()).toBe(0)
196+
expect(endDate.getHours()).toBe(23)
197+
expect(endDate.getMinutes()).toBe(59)
198+
})
199+
})
200+
160201
describe('business rule: chips update should emit filter event', () => {
161202
it('onFilterUpdateChips should emit libresign:filters:update event', async () => {
162203
const store = useFiltersStore()
@@ -254,6 +295,35 @@ describe('filters store - filter business rules', () => {
254295
{ value: '' }
255296
)
256297
})
298+
299+
it('modified filter should update local state after saving', async () => {
300+
axiosMock.put.mockResolvedValue({ data: { success: true } })
301+
302+
const store = useFiltersStore()
303+
const event = {
304+
id: 'modified',
305+
detail: [{ id: 'today', label: 'Today' }],
306+
}
307+
308+
await store.onFilterUpdateChipsAndSave(event)
309+
310+
expect(store.filter_modified).toBe('today')
311+
})
312+
313+
it('empty modified filter should clear local state', async () => {
314+
axiosMock.put.mockResolvedValue({ data: { success: true } })
315+
316+
const store = useFiltersStore()
317+
store.filter_modified = 'last-7'
318+
const event = {
319+
id: 'modified',
320+
detail: [],
321+
}
322+
323+
await store.onFilterUpdateChipsAndSave(event)
324+
325+
expect(store.filter_modified).toBe('')
326+
})
257327
})
258328

259329
describe('business rule: status filter should save JSON array to server', () => {

0 commit comments

Comments
 (0)