80 lines
2.5 KiB
JavaScript
80 lines
2.5 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
require('../src/common');
|
|
|
|
const {
|
|
renderBackgroundTasksPage,
|
|
renderBackgroundTasksScheduledPage
|
|
} = require('../src/web/routes/settings/background-tasks-page');
|
|
|
|
test('background task pages opt into 24-hour timestamps, confirm clearing tasks, and search by dates', () => {
|
|
const baseQueueData = {
|
|
tasks: [
|
|
{
|
|
title: 'Example task',
|
|
key: 'secret-key',
|
|
category: 'Refresh',
|
|
status: 'completed',
|
|
createdAt: '2026-08-04T10:15:00.000Z',
|
|
startedAt: '2026-08-04T10:16:00.000Z',
|
|
finishedAt: '2026-08-04T10:17:00.000Z',
|
|
metadata: {
|
|
playerLabel: 'Player Alpha'
|
|
}
|
|
},
|
|
{
|
|
title: 'Older task',
|
|
key: 'older-key',
|
|
category: 'Refresh',
|
|
status: 'completed',
|
|
createdAt: '2026-08-01T10:15:00.000Z',
|
|
startedAt: '2026-08-01T10:16:00.000Z',
|
|
finishedAt: '2026-08-01T10:17:00.000Z'
|
|
}
|
|
],
|
|
summary: { counts: {}, total: 1, activeCount: 0 }
|
|
};
|
|
|
|
const queueHtml = renderBackgroundTasksPage(baseQueueData, '', {
|
|
permissions: ['background-tasks.allow']
|
|
});
|
|
|
|
const queueKeySearchHtml = renderBackgroundTasksPage(Object.assign({}, baseQueueData, { search: 'secret-key' }), '', {
|
|
permissions: ['background-tasks.allow']
|
|
});
|
|
|
|
const queueDateSearchHtml = renderBackgroundTasksPage(Object.assign({}, baseQueueData, { search: '2026-08-04' }), '', {
|
|
permissions: ['background-tasks.allow']
|
|
});
|
|
|
|
const scheduledHtml = renderBackgroundTasksScheduledPage(
|
|
{
|
|
recurringTasks: [
|
|
{
|
|
title: 'Recurring refresh',
|
|
key: 'refresh',
|
|
intervalMs: 60000,
|
|
nextRunAt: '2026-08-04T10:15:00.000Z',
|
|
lastRunAt: '2026-08-04T09:15:00.000Z',
|
|
metadata: {
|
|
playerIdentifier: 'Player Beta'
|
|
}
|
|
}
|
|
],
|
|
summary: { counts: {}, total: 1, activeCount: 0, scheduledCount: 1 }
|
|
},
|
|
'',
|
|
{
|
|
permissions: ['scheduled-tasks.allow']
|
|
}
|
|
);
|
|
|
|
assert.match(queueHtml, /data-confirm-message="Clear finished background tasks\?"/);
|
|
assert.match(queueHtml, /data-local-datetime-format="24h"/);
|
|
assert.match(queueHtml, /Player Alpha:secret-key/);
|
|
assert.doesNotMatch(queueKeySearchHtml, /Example task/);
|
|
assert.match(queueDateSearchHtml, /Example task/);
|
|
assert.match(scheduledHtml, /data-local-datetime-format="24h"/);
|
|
assert.match(scheduledHtml, /Player:\s+Player Beta/);
|
|
}); |