feat: recent activity card on Home and Retention card on Settings
This commit is contained in:
1 parent
35db442cd3
commit
43469ef08d
33 files changed
+2748
-204
No files matched your search
@@ -0,0 +1,88 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { initializeLocale, setLocale } from '@/i18n'
|
||||
import type { WorkspaceSettings } from '@/composables/useSettings'
|
||||
import { recentWhenLabel } from '../activityTime'
|
||||
import {
|
||||
helperCopy,
|
||||
isShorter,
|
||||
lastCleanupLine,
|
||||
nextCleanupLine,
|
||||
shorteningDescription,
|
||||
} from '../activityRetention'
|
||||
|
||||
const NOW = new Date(2026, 9, 6, 15, 0)
|
||||
|
||||
function at(day: number, hour: number, minute: number) {
|
||||
return new Date(2026, 9, day, hour, minute).toISOString()
|
||||
}
|
||||
|
||||
function settings(overrides: Partial<WorkspaceSettings> = {}): WorkspaceSettings {
|
||||
return {
|
||||
version: 'v2.2.0-beta',
|
||||
activity_retention_days: 90,
|
||||
activity_last_cleanup_at: at(6, 3, 0),
|
||||
activity_last_cleanup_removed: 142,
|
||||
activity_next_cleanup_at: at(7, 3, 0),
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
initializeLocale()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
localStorage.clear()
|
||||
initializeLocale()
|
||||
})
|
||||
|
||||
describe('recentWhenLabel follows the day', () => {
|
||||
it.each([
|
||||
[at(6, 14, 58), '2 min ago'],
|
||||
[at(6, 12, 0), '3 h ago'],
|
||||
[at(5, 14, 20), 'Yesterday, 14:20'],
|
||||
[at(3, 14, 20), '3 Oct 2026, 14:20'],
|
||||
])('%s reads %s', (iso, label) => {
|
||||
expect(recentWhenLabel(iso, NOW)).toBe(label)
|
||||
})
|
||||
|
||||
it('reads French labels in French', () => {
|
||||
setLocale('fr')
|
||||
|
||||
expect(recentWhenLabel(at(5, 14, 20), NOW)).toBe('Hier, 14:20')
|
||||
expect(recentWhenLabel(at(3, 14, 20), NOW)).toBe('3 oct. 2026, 14:20')
|
||||
})
|
||||
})
|
||||
|
||||
describe('retention periods', () => {
|
||||
it('ranks 30 < 90 < 365 < Forever', () => {
|
||||
expect(isShorter(30, 90)).toBe(true)
|
||||
expect(isShorter(365, 0)).toBe(true)
|
||||
expect(isShorter(0, 365)).toBe(false)
|
||||
expect(isShorter(90, 90)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('retention lines', () => {
|
||||
it('reads the last cleanup with its count', () => {
|
||||
expect(lastCleanupLine(settings())).toBe('6 Oct 2026, 03:00 · 142 events removed')
|
||||
expect(lastCleanupLine(settings({ activity_last_cleanup_removed: 1 }))).toBe(
|
||||
'6 Oct 2026, 03:00 · 1 event removed',
|
||||
)
|
||||
})
|
||||
|
||||
it('reads Never before the first cleanup and Not scheduled for Forever', () => {
|
||||
expect(lastCleanupLine(settings({ activity_last_cleanup_at: null }))).toBe('Never')
|
||||
expect(nextCleanupLine(settings({ activity_next_cleanup_at: null }))).toBe('Not scheduled')
|
||||
expect(nextCleanupLine(settings())).toBe('7 Oct 2026, 03:00')
|
||||
})
|
||||
|
||||
it('words the helper and the warning', () => {
|
||||
expect(helperCopy(90)).toBe('Older events are removed automatically.')
|
||||
expect(helperCopy(0)).toBe('Nothing is removed automatically. The log grows over time.')
|
||||
expect(shorteningDescription(settings())).toBe(
|
||||
"This happens at the next cleanup on 7 Oct 2026, 03:00. It can't be undone.",
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user