dsh-im-ops/test/channels/discord/client-ui.test.mjs
2026-08-16 14:47:16 +08:00

42 lines
1.5 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import {
DiscordAccountCard,
DiscordSettingsTab,
} from '../../../plugin-src/client/channels/discord/index.js';
test('Discord settings exposes a Bot Token action without a fake QR action', () => {
const markup = renderToStaticMarkup(React.createElement(DiscordSettingsTab, {
rpcCall: async () => ({ ok: true, value: { bots: [] } }),
}));
assert.match(markup, /aria-label="使用 Bot Token 接入 Discord 机器人"/);
assert.match(markup, />手动接入</);
assert.doesNotMatch(markup, /扫码接入机器人|dim-scanButton/);
});
test('Discord account card matches the unified compact card layout', () => {
const markup = renderToStaticMarkup(React.createElement(DiscordAccountCard, {
account: {
botId: 'discord_test',
connected: true,
state: 'connected',
bot: { name: 'Harness Bot', username: 'HarnessBot', idMasked: '123•••' },
health: { summary: 'Discord Gateway 长连接运行正常', lastCheckedAt: Date.now() },
error: null,
},
onReconnect() {},
onRequestRemove() {},
onConfirmRemove() {},
onCancelRemove() {},
}));
assert.match(markup, /data-im-channel-logo="discord"/);
assert.match(markup, /@HarnessBot/);
assert.match(markup, />Gateway 长连接</);
assert.match(markup, />检查连接</);
assert.match(markup, />移除接入</);
assert.doesNotMatch(markup, /dim-cardSummary/);
});