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';
import { DINGTALK_ENDPOINTS } from '../plugin-src/client/channels/dingtalk/api.js';
import {
AccountCard as DingtalkAccountCard,
DingtalkSettingsTab,
} from '../plugin-src/client/channels/dingtalk/index.js';
import {
BotCard as FeishuBotCard,
FeishuSettingsTab,
} from '../plugin-src/client/channels/feishu/index.js';
import {
AccountCard as WeixinAccountCard,
WeixinSettingsTab,
} from '../plugin-src/client/channels/weixin/index.js';
const STYLES_URL = new URL('../plugin-src/client/styles.js', import.meta.url);
const FEISHU_STYLES_URL = new URL(
'../plugin-src/client/channels/feishu/styles.js',
import.meta.url,
);
const WEIXIN_STYLES_URL = new URL(
'../plugin-src/client/channels/weixin/styles.js',
import.meta.url,
);
const DINGTALK_STYLES_URL = new URL(
'../plugin-src/client/channels/dingtalk/styles.js',
import.meta.url,
);
const FEISHU_SOURCE_URL = new URL(
'../plugin-src/client/channels/feishu/index.js',
import.meta.url,
);
const WEIXIN_SOURCE_URL = new URL(
'../plugin-src/client/channels/weixin/index.js',
import.meta.url,
);
const CLIENT_BUNDLE_URL = new URL('../lib/client.js', import.meta.url);
const DINGTALK_CLIENT_SOURCE_URL = new URL(
'../plugin-src/client/channels/dingtalk/index.js',
import.meta.url,
);
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.doesNotMatch(markup, /\d+ 个渠道|dim-channelCount/);
assert.match(markup, />微信);
assert.match(markup, />飞书);
assert.match(markup, />钉钉);
assert.match(markup, /dim-logoWeixin/);
assert.match(markup, /dim-logoFeishu/);
assert.match(markup, /dim-logoDingtalk/);
assert.equal((markup.match(/role="tab"/g) ?? []).length, 3);
assert.equal((markup.match(/aria-selected="true"/g) ?? []).length, 1);
assert.doesNotMatch(markup, /role="switch"|type="checkbox"/);
assert.doesNotMatch(markup, /dim-chevron|扫码绑定<\/small>|扫码接入<\/small>/);
assert.doesNotMatch(markup, />INSTANT MESSAGING<|>Channel<|>微信设置);
});
test('the DingTalk QR card stacks within the narrow combined-channel panel', async () => {
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('Feishu bot cards place the application identifier under the bot name', async () => {
const styles = await readFile(FEISHU_STYLES_URL, 'utf8');
const markup = renderToStaticMarkup(React.createElement(FeishuBotCard, {
connection: {
botId: 'bot-feishu-card',
state: 'connected',
connected: true,
bot: {
name: '今天是牢梁',
appIdMasked: 'cli_aaf4••••1234',
domain: 'feishu',
avatarUrl: 'https://example.com/custom-bot-avatar.png',
},
health: {
summary: '长连接运行正常',
lastCheckedAt: '2026-08-15T07:30:49.000Z',
},
},
onReconnect() {},
onRequestRemove() {},
onConfirmRemove() {},
onCancelRemove() {},
}));
assert.match(markup, /
]*>今天是牢梁<\/h3>
]*>cli_aaf4••••1234<\/p>/);
assert.match(markup, /data-im-channel-logo="feishu"/);
assert.match(markup, /class="bxf-card bxf-botCard dim-botCard"/);
assert.match(markup, /class="bxf-healthPill dim-botHealth"/);
assert.match(markup, /