60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
var fs = require('fs');
|
|
|
|
function assert(name, condition) {
|
|
if (!condition) {
|
|
throw new Error('FAILED: ' + name);
|
|
}
|
|
console.log('OK:', name);
|
|
}
|
|
|
|
function read(path) {
|
|
return fs.readFileSync(path, 'utf8');
|
|
}
|
|
|
|
function validatePreview(path) {
|
|
var html = read(path);
|
|
var start = html.indexOf('<script>');
|
|
var end = html.indexOf('</script>', start);
|
|
assert(path + ' contains script', start >= 0 && end > start);
|
|
new Function(html.substring(start + 8, end));
|
|
assert(path + ' script syntax', true);
|
|
assert(path + ' uses production CSS', html.indexOf('../classic/megamenu-classic.css') >= 0);
|
|
assert(path + ' has mobile toggle', html.indexOf('mega-menu-mobile-toggle') >= 0);
|
|
assert(path + ' has accessible submenu toggle', html.indexOf('menu-item-toggle') >= 0 && html.indexOf('aria-controls') >= 0);
|
|
}
|
|
|
|
function validateStyle(path) {
|
|
var css = read(path);
|
|
var opening = (css.match(/\{/g) || []).length;
|
|
var closing = (css.match(/\}/g) || []).length;
|
|
assert(path + ' balanced blocks', opening === closing);
|
|
['mega-menu-mobile-toggle', 'menu-item-toggle', 'flyout-toggle', 'mega-menu-description'].forEach(function (className) {
|
|
assert(path + ' contains ' + className, css.indexOf(className) >= 0);
|
|
});
|
|
}
|
|
|
|
validatePreview('preview/mega-menu-preview.html');
|
|
validatePreview('preview/flyout-menu-preview.html');
|
|
validateStyle('classic/megamenu-classic.css');
|
|
validateStyle('src/extensions/megaMenu/MegaMenu.module.scss');
|
|
|
|
var modernStyles = read('src/extensions/megaMenu/MegaMenu.module.scss');
|
|
[
|
|
'white',
|
|
'neutralLighter',
|
|
'neutralLight',
|
|
'neutralTertiary',
|
|
'neutralSecondary',
|
|
'neutralPrimary',
|
|
'themePrimary',
|
|
'themeDark',
|
|
'themeLighterAlt'
|
|
].forEach(function (themeSlot) {
|
|
assert('modern styles use SharePoint theme slot ' + themeSlot,
|
|
modernStyles.indexOf('[theme: ' + themeSlot + ', default:') >= 0);
|
|
});
|
|
|
|
console.log('Static MegaMenu asset tests passed.');
|