Files
Modern-Promoted-Link-List/tests/validate-project.js
T
2026-08-24 12:51:11 +02:00

43 lines
2.8 KiB
JavaScript

'use strict';
var fs = require('fs');
var path = require('path');
var root = path.resolve(__dirname, '..');
var passed = 0;
function read(file) { return fs.readFileSync(path.join(root, file), 'utf8'); }
function json(file) { return JSON.parse(read(file)); }
function assert(condition, message) { if (!condition) { throw new Error(message); } passed++; }
var packageJson = json('package.json');
var packageSolution = json('config/package-solution.json');
var solution = packageSolution.solution;
var config = json('config/config.json');
var manifest = json('src/webparts/modernPromotedLinks/ModernPromotedLinksWebPart.manifest.json');
var webPart = read('src/webparts/modernPromotedLinks/ModernPromotedLinksWebPart.ts');
var service = read('src/webparts/modernPromotedLinks/PromotedLinksDataService.ts');
var component = read('src/webparts/modernPromotedLinks/components/ModernPromotedLinks.tsx');
var core = read('src/webparts/modernPromotedLinks/PromotedLinkCore.ts');
var styles = read('src/webparts/modernPromotedLinks/components/ModernPromotedLinks.module.scss');
assert(packageJson.name === 'modern-promoted-link-list-webpart', 'npm package name is inconsistent.');
assert(solution.name === packageJson.name && solution.title === packageJson.name, 'Solution naming is inconsistent.');
assert(packageSolution.paths.zippedPackage === 'solution/modern-promoted-link-list-webpart.sppkg', 'Package file name is inconsistent.');
assert(solution.includeClientSideAssets === true && solution.skipFeatureDeployment === true, 'Central asset deployment is not configured.');
assert(manifest.componentType === 'WebPart' && manifest.alias === 'ModernPromotedLinksWebPart', 'WebPart manifest is invalid.');
assert(!!config.bundles['modern-promoted-link-list-webpart'], 'Bundle name is inconsistent.');
assert(service.indexOf('BaseTemplate eq 170') >= 0, 'Promoted Links list filtering is missing.');
['BackgroundImageLocation', 'LinkLocation', 'LaunchBehavior', 'TileOrder'].forEach(function(field) {
assert(service.indexOf(field) >= 0, 'Classic Promoted Links field is missing: ' + field);
});
assert(webPart.indexOf("PropertyPaneDropdown('listId'") >= 0, 'List picker is missing.');
assert(webPart.indexOf("PropertyPaneSlider('columns'") >= 0 && webPart.indexOf("PropertyPaneSlider('tileHeight'") >= 0,
'Layout controls are missing.');
assert(component.indexOf("role='list'") >= 0 && component.indexOf('aria-label={label}') >= 0, 'Accessible list semantics are missing.');
assert(core.indexOf("/^[a-z][a-z0-9+.-]*:/i") >= 0, 'Unsafe URL schemes are not rejected.');
['bodyText', 'themePrimary', 'focusBorder', 'errorText'].forEach(function(slot) {
assert(styles.indexOf('[theme:' + slot + ', default:') >= 0, 'SharePoint theme slot is missing: ' + slot);
});
console.log('Modern Promoted Link List project validation passed: ' + passed);