Files
ytplayer/tests/admin-audit.spec.js
2026-10-14 01:54:08 +08:00

28 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { test, expect } = require('@playwright/test');
test('audit tab filters, pages and links filtered exports', async ({ page }) => {
const requests = [];
await page.route('**/api/**', async route => {
const url = new URL(route.request().url()); requests.push(url.pathname + url.search);
let body = { ok: true };
if (url.pathname === '/api/admin/me') body = { ok: true, enabled: true, admin: true };
if (url.pathname === '/api/admin/audit') body = {
ok: true, total: 62, offset: Number(url.searchParams.get('offset')) || 0,
events: [{ id: 9, ts: 1791900000, actor: 'admin', action: 'notes.save.lyrics', target: 'dQw4w9WgXcQ', detail: { rev: 4 } }],
};
if (url.pathname === '/api/admin/flags') body = { ok: true, open: 0, flags: [] };
if (url.pathname === '/api/admin/media') body = { ok: true, media: [] };
if (url.pathname === '/api/uploads') body = { ok: true, uploads: [] };
await route.fulfill({ contentType: 'application/json', body: JSON.stringify(body) });
});
await page.goto('/admin.html#audit');
await expect(page.locator('#p-audit')).toBeVisible();
await expect(page.locator('#auditTable')).toContainText('notes.save.lyrics');
await page.locator('#auditActor').fill('admin'); await page.locator('#auditAction').fill('lyrics');
await page.locator('#auditFilterForm button[type=submit]').click();
await expect.poll(() => requests.filter(x => x.startsWith('/api/admin/audit?')).length).toBeGreaterThan(1);
await expect(page.locator('#auditJson')).toHaveAttribute('href', /actor=admin.*action=lyrics.*format=json/);
await page.locator('#auditNext').click();
await expect(page.locator('#auditCount')).toContainText('51–');
});