优化了一些问题
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const test = require('node:test');
|
||||
|
||||
const root = path.resolve(__dirname, '..', '..');
|
||||
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
|
||||
|
||||
// .but.cir icon buttons center via inline-flex; the 0.25em icon margin rule
|
||||
// (.but > i[class*="fa-"]:not(.fa-angle-right), specificity 0,3,1) must be
|
||||
// outranked by the reset, or glyphs like fa-ellipsis-h sit left of center.
|
||||
const resetSelectors = [
|
||||
'.but.cir svg.icon',
|
||||
'.but.cir > .fa,',
|
||||
'.but.cir > .fa:not(.fa-angle-right),',
|
||||
'.but.cir > i[class*="fa-"]:not(.fa-angle-right)',
|
||||
];
|
||||
|
||||
test('buttons.css resets direct-child icon margins on circular buttons', () => {
|
||||
const buttons = read('assets/css/core/buttons.css');
|
||||
const resetStart = buttons.indexOf('.but.cir svg.icon,');
|
||||
assert.notEqual(resetStart, -1, 'missing .but.cir icon margin reset');
|
||||
const resetBlock = buttons.slice(resetStart, buttons.indexOf('}', resetStart));
|
||||
for (const selector of resetSelectors) {
|
||||
assert.ok(resetBlock.includes(selector), `reset is missing selector: ${selector}`);
|
||||
}
|
||||
assert.match(resetBlock, /margin:\s*0\s*;/);
|
||||
|
||||
const marginStart = buttons.indexOf('.but .icon,');
|
||||
assert.notEqual(marginStart, -1);
|
||||
assert.ok(marginStart < resetStart, 'margin rule must precede the reset');
|
||||
});
|
||||
|
||||
test('the built public bundle carries the reset after the margin rule', () => {
|
||||
const bundle = read('assets/css/build/public.min.css');
|
||||
const minifiedReset = bundle.indexOf('.but.cir>i[class*=fa-]:not(.fa-angle-right){margin:0}');
|
||||
assert.notEqual(minifiedReset, -1, 'missing minified .but.cir icon margin reset');
|
||||
|
||||
const marginRule = /\.but>i\[class\*=fa-\]:not\(\.fa-angle-right\)\{margin-right:\.25em\}/g;
|
||||
let lastMargin = -1;
|
||||
for (const match of bundle.matchAll(marginRule)) {
|
||||
lastMargin = match.index;
|
||||
}
|
||||
assert.notEqual(lastMargin, -1, 'expected the icon margin rule to still exist');
|
||||
assert.ok(minifiedReset > lastMargin, 'reset must appear after the last margin rule copy');
|
||||
});
|
||||
Reference in New Issue
Block a user