Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(dashboard): reject the font shorthand on body and #root

Yudhi Armyndharis32f5768275cf
diff --git a/dashboard/src/fonts-rtl.test.ts b/dashboard/src/fonts-rtl.test.ts
index 373d69d26..a6e152141 100644
--- a/dashboard/src/fonts-rtl.test.ts
+++ b/dashboard/src/fonts-rtl.test.ts
@@ -11,13 +11,29 @@ import { dirname, join } from 'node:path';
const SRC = dirname(fileURLToPath(import.meta.url));
const cssFiles = (readdirSync(SRC, { recursive: true }) as string[]).filter(f => f.endsWith('.css'));
-test('no stylesheet sets a font-family on body or #root', () => {
+// The `font` shorthand resets font-family too; the colon keeps font-weight and font-size out.
+const SETS_FONT_FAMILY = /(^|;|\s)font(-family)?\s*:/;
+
+test('the font-family pattern catches the font shorthand but not other font properties', () => {
+ for (const body of [' font-family: X;', " font: 16px/1.6 'X', sans-serif;", 'font:inherit']) {
+ assert.match(body, SETS_FONT_FAMILY);
+ }
+ for (const body of [' font-weight: 500;', ' font-size: 1rem;', ' -webkit-font-smoothing: antialiased;']) {
+ assert.doesNotMatch(body, SETS_FONT_FAMILY);
+ }
+});
+
+test('no stylesheet sets a font-family or font shorthand on body or #root', () => {
for (const file of cssFiles) {
const css = readFileSync(join(SRC, file), 'utf8').replace(/\/\*[\s\S]*?\*\//g, '');
for (const [, selectorList, body] of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
const selectors = selectorList.split(',').map(s => s.trim());
if (!selectors.some(s => s === 'body' || s === '#root')) continue;
- assert.doesNotMatch(body, /(^|;|\s)font-family\s*:/, `${file}: ${selectorList.trim()} sets a font-family`);
+ assert.doesNotMatch(
+ body,
+ SETS_FONT_FAMILY,
+ `${file}: ${selectorList.trim()} sets a font-family or font shorthand`,
+ );
}
}
});