dsh-im-ops/test/channels/telegram/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 {
TelegramAccountCard,
TelegramSettingsTab,
} from '../../../plugin-src/client/channels/telegram/index.js';
test('Telegram settings exposes a Bot Token action without a fake QR action', () => {
const markup = renderToStaticMarkup(React.createElement(TelegramSettingsTab, {
rpcCall: async () => ({ ok: true, value: { bots: [] } }),
}));
assert.match(markup, /aria-label="使用 Bot Token 接入 Telegram 机器人"/);
assert.match(markup, />手动接入</);
assert.doesNotMatch(markup, /扫码接入机器人|dim-scanButton/);
});
test('Telegram account card matches the unified compact card layout', () => {
const markup = renderToStaticMarkup(React.createElement(TelegramAccountCard, {
account: {
botId: 'telegram_test',
connected: true,
state: 'connected',
bot: { name: 'Harness Bot', username: 'harness_bot', idMasked: '123•••' },
health: { summary: 'Telegram Bot API 长轮询运行正常', lastCheckedAt: Date.now() },
error: null,
},
onReconnect() {},
onRequestRemove() {},
onConfirmRemove() {},
onCancelRemove() {},
}));
assert.match(markup, /data-im-channel-logo="telegram"/);
assert.match(markup, /@harness_bot/);
assert.match(markup, />Bot API 长轮询</);
assert.match(markup, />检查连接</);
assert.match(markup, />移除接入</);
assert.doesNotMatch(markup, /dim-cardSummary/);
});