feat: image variants cache panel
This commit is contained in:
1 parent
951fef18ba
commit
d768668014
53 files changed
+5809
-46
No files matched your search
@@ -0,0 +1,111 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { initializeLocale } from '@/i18n'
|
||||
import type { ActivityItem } from '@/lib/activity'
|
||||
import { detailLine, sentenceText } from '../activitySentence'
|
||||
|
||||
function purgeItem(overrides: Partial<ActivityItem>): ActivityItem {
|
||||
return {
|
||||
id: 1,
|
||||
created_at: '2026-10-03T12:00:00Z',
|
||||
action: 'media.variant_purge_all',
|
||||
category: 'media',
|
||||
actor: { type: 'user', id: 3, name: 'Marta Alves' },
|
||||
target: null,
|
||||
outcome: 'success',
|
||||
failure_reason: null,
|
||||
security: false,
|
||||
source: 'web',
|
||||
ip: null,
|
||||
user_agent: null,
|
||||
params: {},
|
||||
changes: [],
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
const hero = { type: 'image_variant', id: 'hero', name: 'hero', exists: true }
|
||||
const wall = { type: 'image', id: '1', name: 'north-wall.jpg', exists: true }
|
||||
|
||||
const rows: [string, Partial<ActivityItem>, string, string | null][] = [
|
||||
[
|
||||
'media.variant_purge_all success',
|
||||
{ params: { purged_files: 1284, purged_bytes: 222298112 } },
|
||||
'Purged all variants',
|
||||
'Removed 1,284 files (212 MB)',
|
||||
],
|
||||
['media.variant_purge_all failed', { outcome: 'failed' }, 'Failed to purge all variants', null],
|
||||
[
|
||||
'media.variant_purge_unused success',
|
||||
{
|
||||
action: 'media.variant_purge_unused',
|
||||
params: { purged_files: 312, purged_bytes: 42991616, older_than_days: 30 },
|
||||
},
|
||||
'Purged unused variants',
|
||||
'Removed 312 files (41 MB) not requested for 30 days',
|
||||
],
|
||||
[
|
||||
'media.variant_purge_unused failed',
|
||||
{ action: 'media.variant_purge_unused', outcome: 'failed' },
|
||||
'Failed to purge unused variants',
|
||||
null,
|
||||
],
|
||||
[
|
||||
'media.variant_purge success',
|
||||
{
|
||||
action: 'media.variant_purge',
|
||||
target: hero,
|
||||
params: { purged_files: 244, purged_bytes: 88080384 },
|
||||
},
|
||||
'Purged the cache of variant “hero”',
|
||||
'Removed 244 files (84 MB)',
|
||||
],
|
||||
[
|
||||
'media.variant_purge failed',
|
||||
{ action: 'media.variant_purge', target: hero, outcome: 'failed' },
|
||||
'Failed to purge the cache of variant “hero”',
|
||||
null,
|
||||
],
|
||||
[
|
||||
'media.variant_purge_image success',
|
||||
{
|
||||
action: 'media.variant_purge_image',
|
||||
target: wall,
|
||||
params: { purged_files: 6, purged_bytes: 6082765 },
|
||||
},
|
||||
'Purged the variants of north-wall.jpg',
|
||||
'Removed 6 files (5.8 MB)',
|
||||
],
|
||||
]
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
initializeLocale()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
localStorage.clear()
|
||||
initializeLocale()
|
||||
})
|
||||
|
||||
describe('The Activity screen words each cache purge scope', () => {
|
||||
it.each(rows)('%s', (_, overrides, sentence, detail) => {
|
||||
const subject = purgeItem(overrides)
|
||||
|
||||
expect(sentenceText(subject)).toBe(sentence)
|
||||
expect(detailLine(subject)).toBe(detail)
|
||||
})
|
||||
|
||||
it('A partial purge adds the failed count to the detail line', () => {
|
||||
const subject = purgeItem({
|
||||
params: { purged_files: 640, purged_bytes: 111149056, failed_files: 644 },
|
||||
})
|
||||
|
||||
expect(detailLine(subject)).toBe('Removed 640 files (106 MB) · 644 failed')
|
||||
})
|
||||
|
||||
it('The singular reads 1 file', () => {
|
||||
const subject = purgeItem({ params: { purged_files: 1, purged_bytes: 2048 } })
|
||||
|
||||
expect(detailLine(subject)).toBe('Removed 1 file (2 KB)')
|
||||
})
|
||||
})
|
||||
@@ -231,6 +231,9 @@ describe('The catalogue is complete in both languages', () => {
|
||||
'media.merge',
|
||||
'media.purge',
|
||||
'media.variant_generate_all',
|
||||
'media.variant_purge',
|
||||
'media.variant_purge_all',
|
||||
'media.variant_purge_unused',
|
||||
'media.variant_purge_image',
|
||||
'system.media_purge',
|
||||
'user.register',
|
||||
|
||||
Reference in new issue
Block a user