Files
memind/mindspace-public-share-widget.test.mjs
T
John 014c3b7981
Memind CI / Test, build, and release guards (push) Has been cancelled
fix(wechat): 长文推送先留页脚,失败弹窗展示真实原因
超过 2 万字时不再把阅读原文和关注区裁掉;公开页错误态不再误报需要登录 MindSpace。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-12 12:51:06 +08:00

75 lines
3.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { injectPublicFileShareButton } 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, /redirectToMindSpaceLogin/);
assert.match(result.html, /auth\/wechat\/authorize\?intent=login/);
assert.match(result.html, /setWechatErrorHint/);
assert.match(result.html, /\[data-wechat-view="error"\] \[data-wechat-hint\]/);
assert.match(result.html, /推送失败,请稍后重试。/);
assert.doesNotMatch(
result.html,
/data-wechat-view="error"[\s\S]*请稍后重试,或先登录 MindSpace/,
);
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/);
});