增加TG代理选项,增加测试用例

This commit is contained in:
Shinku
2026-03-20 01:03:21 +08:00
parent 54203d64a3
commit c5d55f0ab0
3 changed files with 157 additions and 0 deletions
@@ -43,6 +43,7 @@ describe('NotificationSettings', () => {
telegramApiBaseUrl: 'https://tg-proxy.example.com',
telegramChatId: '-1001234567890',
telegramBotTokenMasked: '1234****token',
telegramUseSystemProxy: false,
smtpEnabled: false,
smtpHost: '',
smtpPort: 587,
@@ -105,4 +106,73 @@ describe('NotificationSettings', () => {
root?.unmount();
}
});
it('loads and saves telegram use system proxy toggle', async () => {
apiMock.getRuntimeSettings.mockResolvedValue({
webhookUrl: '',
barkUrl: '',
webhookEnabled: true,
barkEnabled: true,
serverChanEnabled: false,
telegramEnabled: true,
telegramApiBaseUrl: 'https://api.telegram.org',
telegramChatId: '-1001234567890',
telegramBotTokenMasked: '1234****token',
telegramUseSystemProxy: false,
smtpEnabled: false,
smtpHost: '',
smtpPort: 587,
smtpSecure: false,
smtpUser: '',
smtpFrom: '',
smtpTo: '',
notifyCooldownSec: 300,
});
let root: ReturnType<typeof create> | null = null;
try {
await act(async () => {
root = create(
<MemoryRouter>
<ToastProvider>
<NotificationSettings />
</ToastProvider>
</MemoryRouter>,
);
});
await flushMicrotasks();
const allCheckboxes = root.root.findAll((node) => (
node.type === 'input' && node.props.type === 'checkbox'
));
const proxyCheckbox = allCheckboxes.find((node) => {
const parent = node.parent;
if (!parent) return false;
const text = collectText(parent);
return text.includes('使用系统代理');
});
expect(proxyCheckbox).toBeTruthy();
expect(proxyCheckbox!.props.checked).toBe(false);
await act(async () => {
proxyCheckbox!.props.onChange({ target: { checked: true } });
});
const saveButton = root.root.find((node) => (
node.type === 'button'
&& typeof node.props.onClick === 'function'
&& collectText(node).includes('保存通知设置')
));
await act(async () => {
saveButton.props.onClick();
});
await flushMicrotasks();
expect(apiMock.updateRuntimeSettings).toHaveBeenCalledWith(expect.objectContaining({
telegramUseSystemProxy: true,
}));
} finally {
root?.unmount();
}
});
});