import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import test from 'node:test'; import React from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import { IMSettingsTab } from '../plugin-src/client/index.js'; const STYLES_URL = new URL('../plugin-src/client/styles.js', import.meta.url); const CLIENT_BUNDLE_URL = new URL('../lib/client.js', import.meta.url); const DINGTALK_CLIENT_SOURCE_URL = new URL( import.meta.resolve('@xmanrui/dsh-dingtalk/client-source'), ); test('IM settings renders three compact logo channel tabs without enable switches', () => { const markup = renderToStaticMarkup(React.createElement(IMSettingsTab, { feishuRpcCall: async () => ({ ok: true, value: {} }), weixinRpcCall: async () => ({ ok: true, value: {} }), dingtalkRpcCall: async () => ({ ok: true, value: {} }), })); assert.match(markup, /IM机器人/); assert.match(markup, /通过扫码把机器人接入 DeepSeek Harness/); assert.match(markup, />微信飞书钉钉|扫码接入<\/small>/); assert.doesNotMatch(markup, />INSTANT MESSAGING<|>Channel<|>微信设置 { const styles = await readFile(STYLES_URL, 'utf8'); assert.match(styles, /\.dim-panel \{ min-width: 0; container-type: inline-size; \}/); assert.match( styles, /@container \(max-width: 680px\)[\s\S]*\.dim-panel \.ddt-qrLayout \{ grid-template-columns: minmax\(0, 1fr\); justify-items: center;/, ); assert.match(styles, /\.dim-panel \.ddt-qrFrame, \.dim-panel \.ddt-countdown \{ width: min\(270px, 100%\); \}/); assert.match(styles, /\.dim-panel \.ddt-qrColumn \{ width: 100%; min-width: 0; \}/); assert.match(styles, /\.dim-panel \.ddt-qrCopy \{ width: 100%; min-width: 0; overflow-wrap: anywhere; \}/); }); test('the bundled DingTalk channel has no local sender approval workflow', async () => { const [{ DINGTALK_ENDPOINTS }, source, bundle] = await Promise.all([ import('@xmanrui/dsh-dingtalk/client-api'), readFile(DINGTALK_CLIENT_SOURCE_URL, 'utf8'), readFile(CLIENT_BUNDLE_URL, 'utf8'), ]); assert.equal('approveSender' in DINGTALK_ENDPOINTS, false); assert.equal('revokeSender' in DINGTALK_ENDPOINTS, false); assert.doesNotMatch(source, /SenderAccess|onApprove|onRevoke|approveSender|revokeSender/); assert.doesNotMatch( bundle, /bot\.sender\.approve|bot\.sender\.revoke|允许使用机器人的钉钉账号|批准使用/, ); });