111 lines
4.4 KiB
JavaScript
111 lines
4.4 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const Module = require('module');
|
|
const path = require('path');
|
|
|
|
const originalResolveFilename = Module._resolveFilename;
|
|
Module._resolveFilename = function (request, parent, isMain, options) {
|
|
if (request === '#src/data/announcement-icons') {
|
|
return path.join(__dirname, '..', 'src', 'data', 'announcement-icons.js');
|
|
}
|
|
if (request === '#root/package.json') {
|
|
return path.join(__dirname, '..', 'package.json');
|
|
}
|
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
};
|
|
|
|
const { buildAnnouncementFormViewModel } = require('../src/web/routes/signage/announcements/form-view-model');
|
|
const renderAnnouncementsPage = require('../src/web/routes/signage/announcements/list');
|
|
const renderAnnouncementEditPage = require('../src/web/routes/signage/announcements/edit');
|
|
|
|
test('announcement add page shows a disabled delete button placeholder', () => {
|
|
const model = buildAnnouncementFormViewModel({ id: null, canDelete: false }, '', { permissionKeys: ['announcements.delete'] }, { announcementTypes: [], announcementColors: [], announcementIcons: [], announcementScreens: [] }, false);
|
|
|
|
assert.equal(model.showSaveSecondaryActions, true);
|
|
assert.equal(model.showDeleteAction, true);
|
|
assert.equal(model.deleteDisabled, true);
|
|
assert.match(model.deleteTitle, /available after the announcement has been created/i);
|
|
});
|
|
|
|
test('announcement edit page enables delete when the announcement is inactive', () => {
|
|
const model = buildAnnouncementFormViewModel({ id: 12, canDelete: true, expires_at: '2026-08-04T00:00:00.000Z' }, '', { permissionKeys: ['announcements.delete'] }, { announcementTypes: [], announcementColors: [], announcementIcons: [], announcementScreens: [] }, true);
|
|
|
|
assert.equal(model.showDeleteAction, true);
|
|
assert.equal(model.deleteDisabled, false);
|
|
assert.equal(model.deleteConfirmMessage, 'Delete this announcement?');
|
|
assert.equal(model.deleteTitle, '');
|
|
});
|
|
|
|
test('announcement edit page renders delete confirmation on the delete button', () => {
|
|
const html = renderAnnouncementEditPage({
|
|
id: 12,
|
|
message: 'Test message',
|
|
short_label: 'Test announcement',
|
|
announcement_type: 'top-banner',
|
|
color_key: 'primary',
|
|
icon_key: 'info-circle',
|
|
duration_seconds: null,
|
|
expires_at: '2026-08-03T00:00:00.000Z',
|
|
canDelete: true,
|
|
screen_ids: [1]
|
|
}, {
|
|
announcementTypes: [],
|
|
announcementColors: [],
|
|
announcementIcons: [],
|
|
announcementScreens: []
|
|
}, '', { permissionKeys: ['announcements.delete'] }, {
|
|
announcementTypes: [],
|
|
announcementColors: [],
|
|
announcementIcons: [],
|
|
announcementScreens: []
|
|
});
|
|
|
|
assert.match(html, /data-delete-action-url="\/announcements\/12\/delete"/);
|
|
assert.match(html, /data-confirm-message="Delete this announcement\?"/);
|
|
});
|
|
|
|
test('announcement list disables delete for active announcements', () => {
|
|
const html = renderAnnouncementsPage({
|
|
announcements: [
|
|
{
|
|
id: 1,
|
|
short_label: 'Active announcement',
|
|
message: 'Now live',
|
|
icon_key: 'info-circle',
|
|
color_key: 'primary',
|
|
announcement_type: 'top-banner',
|
|
duration_seconds: null,
|
|
expires_at: null,
|
|
screen_target_count: 1,
|
|
total_screen_count: 1,
|
|
screen_targets_label: 'Main Screen'
|
|
}
|
|
],
|
|
pagination: { totalItems: 1, currentPage: 1 }
|
|
}, '', { permissionKeys: ['announcements.delete'] });
|
|
|
|
assert.match(html, /action="\/announcements\/1\/delete"[\s\S]*button class="btn btn-sm btn-outline-danger" type="submit" disabled title="This announcement is currently active and cannot be deleted\.">Delete<\/button>/);
|
|
});
|
|
|
|
test('announcement list enables delete for inactive announcements', () => {
|
|
const html = renderAnnouncementsPage({
|
|
announcements: [
|
|
{
|
|
id: 2,
|
|
short_label: 'Expired announcement',
|
|
message: 'Done',
|
|
icon_key: 'info-circle',
|
|
color_key: 'primary',
|
|
announcement_type: 'top-banner',
|
|
duration_seconds: null,
|
|
expires_at: '2026-08-03T00:00:00.000Z',
|
|
screen_target_count: 1,
|
|
total_screen_count: 1,
|
|
screen_targets_label: 'Main Screen'
|
|
}
|
|
],
|
|
pagination: { totalItems: 1, currentPage: 1 }
|
|
}, '', { permissionKeys: ['announcements.delete'] });
|
|
|
|
assert.match(html, /action="\/announcements\/2\/delete"[\s\S]*button class="btn btn-sm btn-danger" type="submit"\s*>Delete<\/button>/);
|
|
}); |