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(' { const header = source.split('')[0]; const footer = source.split('')[0]; expect(source.match(/ { 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 }; 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>/); } }); 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 ||'); }); });