Files
Modern-Promoted-Link-List/tests/PromotedLinkCore.test.ts
T
2026-08-24 12:51:11 +02:00

33 lines
1.8 KiB
TypeScript

import {
isDialogLaunch,
isNewTabLaunch,
normalizeColumns,
normalizeImageUrl,
normalizeNavigationUrl,
normalizeTileHeight
} from '../src/webparts/modernPromotedLinks/PromotedLinkCore';
declare const console: { log(message: string): void };
let passed: number = 0;
function assert(condition: boolean, message: string): void {
if (!condition) { throw new Error(message); }
passed++;
}
const webUrl: string = 'http://portal.contoso.local/sites/demo';
assert(normalizeNavigationUrl('Pages/Start.aspx', webUrl) === webUrl + '/Pages/Start.aspx', 'Relative links must be resolved.');
assert(normalizeNavigationUrl('/sites/demo', webUrl) === '/sites/demo', 'Server-relative links must be retained.');
assert(normalizeNavigationUrl('mailto:test@example.com', webUrl) === 'mailto:test@example.com', 'Mail links must be supported.');
assert(normalizeNavigationUrl('javascript:alert(1)', webUrl) === '', 'JavaScript URLs must be rejected.');
assert(normalizeNavigationUrl('data:text/html,test', webUrl) === '', 'Data URLs must be rejected.');
assert(normalizeImageUrl('mailto:test@example.com', webUrl) === '', 'Special navigation URLs must not be accepted as images.');
assert(normalizeImageUrl('/SiteAssets/tile.jpg', webUrl) === '/SiteAssets/tile.jpg', 'Server-relative image URLs must be retained.');
assert(isNewTabLaunch('New tab'), 'New tab launch behavior must be recognized.');
assert(isNewTabLaunch('New window'), 'New window launch behavior must be recognized.');
assert(isDialogLaunch('Dialog'), 'Dialog launch behavior must be recognized.');
assert(normalizeColumns(9) === 6 && normalizeColumns(0) === 4, 'Column values must be normalized.');
assert(normalizeTileHeight(80) === 120 && normalizeTileHeight(400) === 320, 'Tile height must be normalized.');
console.log('Promoted link core tests passed: ' + passed);