Add cache pinning and health controls
This commit is contained in:
24
tests/admin-cache.spec.js
Normal file
24
tests/admin-cache.spec.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
test('cache actions pin, unpin, confirm eviction and request a source re-download', async ({ page }) => {
|
||||
const state = { pinned: false, evicted: false, redownloaded: false };
|
||||
await page.route('**/api/**', async route => {
|
||||
const req = route.request(), url = new URL(req.url()); let body = { ok: true };
|
||||
if (url.pathname === '/api/admin/me') body = { enabled: true, admin: true };
|
||||
else if (url.pathname === '/api/admin/cache/health') body = { ok: true, total: 1, offset: 0, budget: 1000, pinnedBudget: 900, bytes: 700, pinnedBytes: state.pinned ? 700 : 0, utilization: .7, statuses: [{ status: 'ready', count: 1, bytes: 700 }], media: [{ id: 'CacheItem001', status: 'ready', bytes: 700, lastAccess: 1791900000000, gen: 4, pinned: state.pinned }] };
|
||||
else if (url.pathname === '/api/admin/cache/CacheItem001/pin' && req.method() === 'POST') { state.pinned = req.postDataJSON().pinned; body.pinned = state.pinned; }
|
||||
else if (url.pathname === '/api/admin/cache/CacheItem001/evict' && req.method() === 'POST') state.evicted = true;
|
||||
else if (url.pathname === '/api/admin/media/CacheItem001/redownload' && req.method() === 'POST') state.redownloaded = true;
|
||||
else if (url.pathname === '/api/admin/media') body.media = [];
|
||||
else if (url.pathname === '/api/uploads') body.uploads = [];
|
||||
else if (url.pathname === '/api/admin/flags') body.flags = [];
|
||||
await route.fulfill({ contentType: 'application/json', body: JSON.stringify(body) });
|
||||
});
|
||||
await page.goto('/admin.html#cache');
|
||||
await expect(page.locator('#cacheTable')).toContainText('CacheItem001');
|
||||
await page.locator('[data-cache-pin]').click(); await expect(page.locator('[data-cache-pin]')).toHaveText('Unpin');
|
||||
await page.locator('[data-cache-pin]').click(); await expect(page.locator('[data-cache-pin]')).toHaveText('Pin');
|
||||
page.once('dialog', dialog => dialog.accept()); await page.locator('[data-cache-evict]').click();
|
||||
page.once('dialog', dialog => dialog.accept()); await page.locator('[data-cache-redownload]').click();
|
||||
expect(state).toEqual({ pinned: false, evicted: true, redownloaded: true });
|
||||
});
|
||||
Reference in New Issue
Block a user