initial Commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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);
|
||||
Reference in New Issue
Block a user