Files
memind/mindspace-page-tag.test.mjs
john 927e16d861 fix(brand): force visible platform-brand footer on published pages
Inject serve-time CSS so author styles cannot hide TKMind · 智趣 with
low opacity, which made pages like weather.html look brandless.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 14:32:36 +08:00

50 lines
2.1 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
MINDSPACE_PAGE_TAG_ATTR,
MINDSPACE_PAGE_TAG_PLATFORM_BRAND,
ensurePlatformBrandFooter,
ensurePlatformBrandPageTags,
injectPlatformBrandVisibilityStyle,
normalizePlatformBrandHtml,
PLATFORM_BRAND_STYLE_ID,
prepareHtmlPageBrandMarkers,
} from './mindspace-page-tag.mjs';
test('normalizePlatformBrandHtml rewrites tkmind.ai to tkmind.cn', () => {
const html = '<a href="mailto:contact@tkmind.ai">📧 contact@tkmind.ai</a>';
const result = normalizePlatformBrandHtml(html);
assert.match(result, /TKMind · 智趣/);
assert.doesNotMatch(result, /tkmind\.ai/i);
assert.doesNotMatch(result, /contact@tkmind\.cn/i);
});
test('ensurePlatformBrandPageTags adds platform-brand marker to contact line', () => {
const html = '<footer><p>📧 contact@tkmind.ai</p></footer>';
const result = ensurePlatformBrandPageTags(html);
assert.match(result, new RegExp(`${MINDSPACE_PAGE_TAG_ATTR}="${MINDSPACE_PAGE_TAG_PLATFORM_BRAND}"`));
assert.match(result, /TKMind · 智趣/);
});
test('prepareHtmlPageBrandMarkers keeps existing marker', () => {
const html = `<p ${MINDSPACE_PAGE_TAG_ATTR}="${MINDSPACE_PAGE_TAG_PLATFORM_BRAND}">TKMind · 智趣</p>`;
const result = prepareHtmlPageBrandMarkers(html);
assert.equal(result.match(new RegExp(MINDSPACE_PAGE_TAG_ATTR, 'g'))?.length, 1);
});
test('injectPlatformBrandVisibilityStyle adds readable brand css', () => {
const html =
'<html><head><style>.footer p{color:rgba(255,255,255,0.25)}</style></head><body>' +
`<p data-mindspace-page-tag="platform-brand">TKMind · 智趣</p></body></html>`;
const result = injectPlatformBrandVisibilityStyle(html);
assert.match(result, new RegExp(`id="${PLATFORM_BRAND_STYLE_ID}"`));
assert.match(result, /opacity:\s*1 !important/);
});
test('ensurePlatformBrandFooter appends brand line when marker is missing', () => {
const html = '<html><body><main>content</main></body></html>';
const result = ensurePlatformBrandFooter(html);
assert.match(result, /data-mindspace-page-tag="platform-brand"/);
assert.match(result, /TKMind · 智趣/);
});