ee8677cc6d
Wire delivery path detection through portal static routes and strip baked share chrome from learn parent/child HTML. Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
3.6 KiB
JavaScript
77 lines
3.6 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
injectPublicFileShareButton,
|
|
stripPublicFileShareWidget,
|
|
} from './mindspace-public-share-widget.mjs';
|
|
|
|
test('injectPublicFileShareButton adds plaza entry and confirm dialog', () => {
|
|
const result = injectPublicFileShareButton('<!doctype html><html><body><h1>Hi</h1></body></html>');
|
|
assert.match(result.html, /data-action="plaza"/);
|
|
assert.match(result.html, /发布到 Plaza/);
|
|
assert.match(result.html, /data-action="plaza-confirm"/);
|
|
assert.match(result.html, /data-action="wechat-draft"/);
|
|
assert.match(result.html, /公众号/);
|
|
assert.match(result.html, /quick-plaza-from-public-html/);
|
|
assert.match(result.html, /quick-wechat-draft-from-public-html/);
|
|
assert.match(result.html, /quick-plaza-from-public-html\/status/);
|
|
assert.match(result.html, /data-plaza-view="already"/);
|
|
assert.match(result.html, /已在广场发布/);
|
|
assert.match(result.html, /data-mindspace-public-share-dialog-panel role="dialog"/);
|
|
assert.doesNotMatch(result.html, /data-mindspace-public-share-dialog-panel"/);
|
|
assert.match(result.html, /color:#fff !important/);
|
|
assert.match(result.html, /apiErrorBody/);
|
|
assert.match(result.html, /ALREADY_PUBLISHED/);
|
|
assert.equal(result.scriptHashes.length, 1);
|
|
});
|
|
|
|
test('injectPublicFileShareButton hides Plaza entry but keeps WeChat entry for non-owner viewers', () => {
|
|
const result = injectPublicFileShareButton(
|
|
'<!doctype html><html><body><h1>Hi</h1></body></html>',
|
|
{ isOwner: false },
|
|
);
|
|
assert.doesNotMatch(result.html, /<button type="button" data-action="plaza">/);
|
|
assert.match(result.html, /<button type="button" data-action="wechat-draft">/);
|
|
assert.match(result.html, /data-is-owner="false"/);
|
|
assert.match(result.html, /暂时无权限/);
|
|
assert.match(result.html, /data-wechat-view="forbidden"/);
|
|
assert.match(result.html, /isPageOwner/);
|
|
assert.doesNotMatch(result.html, /发布到 Plaza/);
|
|
assert.doesNotMatch(result.html, /<button type="button" data-action="plaza-confirm">/);
|
|
assert.doesNotMatch(result.html, /<div data-mindspace-public-share-dialog hidden>/);
|
|
// Non-Plaza actions must remain available to visitors.
|
|
assert.match(result.html, /data-action="capture"/);
|
|
assert.match(result.html, /data-action="share"/);
|
|
assert.match(result.html, /公开分享/);
|
|
assert.equal(result.scriptHashes.length, 1);
|
|
});
|
|
|
|
test('injectPublicFileShareButton upgrades stale baked widget markup', () => {
|
|
const stale = injectPublicFileShareButton('<!doctype html><html><body><h1>Hi</h1></body></html>', {
|
|
isOwner: false,
|
|
}).html;
|
|
const upgraded = injectPublicFileShareButton(stale, { isOwner: true });
|
|
assert.match(upgraded.html, /data-action="wechat-draft"/);
|
|
assert.match(upgraded.html, /data-is-owner="true"/);
|
|
assert.match(upgraded.html, /data-action="plaza"/);
|
|
assert.doesNotMatch(upgraded.html, /data-is-owner="false"/);
|
|
assert.equal(upgraded.scriptHashes.length, 1);
|
|
});
|
|
|
|
test('injectPublicFileShareButton keeps Plaza entry when isOwner explicitly true', () => {
|
|
const result = injectPublicFileShareButton(
|
|
'<!doctype html><html><body><h1>Hi</h1></body></html>',
|
|
{ isOwner: true },
|
|
);
|
|
assert.match(result.html, /data-action="plaza"/);
|
|
assert.match(result.html, /data-mindspace-public-share-dialog/);
|
|
});
|
|
|
|
test('stripPublicFileShareWidget removes injected share chrome', () => {
|
|
const injected = injectPublicFileShareButton('<!doctype html><html><body><h1>Hi</h1></body></html>');
|
|
const stripped = stripPublicFileShareWidget(injected.html);
|
|
assert.doesNotMatch(stripped, /data-mindspace-public-share/);
|
|
assert.doesNotMatch(stripped, /公众号/);
|
|
assert.doesNotMatch(stripped, /保存长图/);
|
|
});
|