Files
makelore/tests/unit/cloud-channel-enable.test.tsx
brother7 2e710db0fb
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled
feat(agents): 支持个人微信发布与渠道会话
2026-09-13 16:22:36 +08:00

32 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, expect, it, vi } from 'vitest';
import { CloudChannelEnableConfirmation } from '@/pages/CloudAgents/CloudChannelEnableConfirmation';
const api = vi.hoisted(() => ({ call: vi.fn() }));
vi.mock('@/lib/cloud-agents-api', () => ({ cloudAgentsApi: api }));
afterEach(() => { cleanup(); vi.resetAllMocks(); });
const binding = { id: 'wechat', address: 'wechat:creator', display_name: '创作微信', target_agent_address: 'yuxi:makelore:agent',
route_revision: 1, provider_generation: 'generation', binding_id: 'binding', enabled: false, status: 'bound', worker_online: true, access_mode: 'self_only' };
it('shows actual budget values and published audience before enabling, including a zero limit', async () => {
api.call.mockResolvedValue({ request_limit_points: '0.00', daily_limit_points: null });
const enable = vi.fn();
render(<CloudChannelEnableConfirmation slug="agent" binding={binding} publishedVersion={2} busy={false} onEnable={enable} onCancel={() => undefined} />);
expect(screen.getByRole('button', { name: '确认启用', exact: true })).toBeDisabled();
await screen.findByText('每次任务上限0.00 词元点数');
expect(screen.getByText('每日上限:不设额外上限')).toBeVisible();
expect(screen.getByRole('dialog')).toHaveTextContent('当前发布版本 v2允许仅本人');
fireEvent.click(screen.getByRole('button', { name: '确认启用', exact: true }));
expect(enable).toHaveBeenCalledOnce();
});
it('keeps enable unavailable until a failed budget read can be retried', async () => {
api.call.mockRejectedValueOnce(new Error('费用服务暂不可用')).mockResolvedValueOnce({ request_limit_points: '2.00', daily_limit_points: '10.00' });
render(<CloudChannelEnableConfirmation slug="agent" binding={binding} publishedVersion={2} busy={false} onEnable={() => undefined} onCancel={() => undefined} />);
await screen.findByRole('alert');
expect(screen.getByRole('button', { name: '确认启用', exact: true })).toBeDisabled();
fireEvent.click(screen.getByRole('button', { name: '重新读取上限' }));
await screen.findByText('每日上限10.00 词元点数');
expect(screen.getByRole('button', { name: '确认启用', exact: true })).toBeEnabled();
});