49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { OIDCCallbackNotice } from './OIDCCallbackNotice';
|
|
|
|
describe('OIDCCallbackNotice', () => {
|
|
it('renders a one-click fresh login action for an invalid transaction', () => {
|
|
const html = renderToStaticMarkup(
|
|
<OIDCCallbackNotice
|
|
error={{ code: 'OIDC_LOGIN_INVALID', message: '登录事务已过期', retryable: true }}
|
|
onRetry={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(html).toContain('登录事务已过期');
|
|
expect(html).toContain('>重新登录</button>');
|
|
});
|
|
|
|
it('does not retry non-transaction callback failures', () => {
|
|
const html = renderToStaticMarkup(
|
|
<OIDCCallbackNotice
|
|
error={{ code: 'OIDC_TOKEN_EXCHANGE_FAILED', message: '登录结果无效', retryable: false }}
|
|
onRetry={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(html).toContain('登录结果无效');
|
|
expect(html).not.toContain('<button');
|
|
});
|
|
|
|
it('shows a safe diagnostic id without exposing callback parameters', () => {
|
|
const html = renderToStaticMarkup(
|
|
<OIDCCallbackNotice
|
|
error={{
|
|
code: 'OIDC_LOGIN_INVALID',
|
|
reason: 'STATE_MISMATCH',
|
|
diagnosticId: 'diag-123',
|
|
message: '认证回调与当前登录事务不匹配',
|
|
retryable: true,
|
|
}}
|
|
onRetry={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(html).toContain('诊断编号:diag-123');
|
|
expect(html).not.toContain('state=');
|
|
expect(html).not.toContain('code=');
|
|
});
|
|
});
|