Files
Supra4E8C af75f6539e Refactor tests to enhance InfoTip functionality and localization
- Updated `providerErrorRulesUi.test.ts` to ensure controls are disabled while saving or disconnected, and added tests for InfoTips related to regex conditions and rule-order hints.
- Created `providerFormHints.test.ts` to validate the transformation of notes into InfoTips, ensuring accessibility and proper descriptions for various form elements.
- Enhanced `providerModelOptions.test.ts` to confirm that field notes are represented as InfoTips and that existing thinking JSON adds preservation notes.
- Added tests in `quotaBodyRendering.test.ts` for Antigravity and Plugin quota groups to ensure descriptions are displayed as InfoTips.
- Implemented `quotaTimelineRendering.test.ts` to verify InfoTip functionality in the QuotaTimeline component.
- Updated `routingPage.test.ts` to check that policy explanations are presented as InfoTips and that the preview caveat is correctly positioned.
- Introduced `tooltipMarkup.test.ts` to validate the structure and behavior of InfoTips and Tooltips, ensuring proper accessibility attributes.
- Added `tooltipPosition.test.ts` to test the positioning logic of tooltips within the viewport.
- Fixed Turkish locale test to ensure correct hint extraction from the configuration.
2026-11-14 20:40:37 +08:00

85 lines
3.8 KiB
TypeScript

import { describe, expect, test } from 'bun:test';
import { readFileSync } from 'node:fs';
// The quota host binds CSS-module classes at import time, which Bun cannot render.
// Keep these source contracts small; browser checks cover the actual card interactions.
const source = readFileSync(
new URL('../src/features/authFiles/components/AuthFileCard.tsx', import.meta.url),
'utf8'
);
const styles = readFileSync(
new URL('../src/features/authFiles/components/AuthFileCard.module.scss', import.meta.url),
'utf8'
);
describe('auth file card presentation contract', () => {
test('uses identity rather than logos or duplicate status badges', () => {
expect(source).not.toContain('<img');
expect(source).not.toContain('getAuthFileIcon');
expect(source).not.toContain('stateBadge');
expect(source).toContain('<h3');
expect(source).toContain('{identity.primary}');
expect(source).toContain('{identity.secondary}');
});
test('uses one footer toggle and credential-specific accessible names', () => {
const header = source.split('<header')[1].split('</header>')[0];
const footer = source.split('<footer')[1].split('</footer>')[0];
expect(source.match(/<ToggleSwitch/g)).toHaveLength(1);
expect(header).not.toContain('<ToggleSwitch');
expect(header).toContain("ariaLabel={t('auth_files.card_select', { name: file.name })}");
expect(header).not.toContain('aria-label=');
expect(footer).toContain('<ToggleSwitch');
expect(footer).toContain("t('auth_files.card_toggle', { name: file.name })");
expect(footer).toContain('checked={!file.disabled}');
expect(footer).toContain('statusUpdating[getAuthFileRefreshKey(file)] === true ||');
expect(footer).toContain('isManualRefreshing');
expect(footer).toContain('!isRuntimeOnly &&');
});
test('dims disabled card content but keeps the re-enable controls clear', () => {
expect(source).toContain("file.disabled === true ? styles.cardDisabled : ''");
expect(styles).toMatch(/\.cardDisabled\s*>\s*:not\(\.actions\)\s*\{\s*opacity:\s*0\.68;/);
expect(styles).not.toMatch(/\.cardDisabled\s*\{[^}]*opacity:/);
});
test('uses a plain-text weight tooltip while preserving the details link', () => {
expect(source).toContain("title={t('auth_files.weight_tooltip')}");
expect(source).not.toContain("title={t('auth_files.weight_hint')}");
const detailsSource = readFileSync(
new URL('../src/features/authFiles/components/AuthFileDetailsSheet.tsx', import.meta.url),
'utf8'
);
// Details sheet: plain semantics in the InfoTip, the link sentence as a visible note.
expect(detailsSource).toContain("hint={t('auth_files.weight_hint')}");
expect(detailsSource).toContain('i18nKey="auth_files.weight_strategy_note"');
for (const locale of ['en', 'zh-CN', 'zh-TW', 'ru', 'vi', 'ko', 'tr']) {
const { auth_files: messages } = JSON.parse(
readFileSync(new URL(`../src/i18n/locales/${locale}.json`, import.meta.url), 'utf8')
) as { auth_files: Record<string, string> };
expect(messages.weight_tooltip).toBeTruthy();
expect(messages.weight_tooltip).not.toMatch(/<[^>]+>/);
expect(messages.weight_hint).toBeTruthy();
expect(messages.weight_hint).not.toMatch(/<[^>]+>/);
expect(messages.weight_strategy_note).toMatch(/<settingsLink>[^<]+<\/settingsLink>/);
}
});
test('retains individual management actions and warning detail', () => {
for (const handler of [
'onShowModels(file)',
'onDownload(file.name)',
'onManualRefresh(file)',
'onCooldownReset(file)',
'onOpenPrefixProxyEditor(file)',
'onDelete(file.name)',
]) {
expect(source).toContain(handler);
}
expect(source).toContain('rawStatusMessage && hasStatusWarning');
expect(source).toContain('showManualRefreshButton');
expect(source).toContain('file.disabled ||');
});
});