labels.test.ts
1,274 bytes
| 1 | import type { ConfigStatus } from 'shared/types' |
|---|---|
| 2 | import { describe, expect, it } from 'vitest' |
| 3 | import { connectionDetail, connectionLabel } from './labels' |
| 4 | |
| 5 | function status(overrides: Partial<ConfigStatus> = {}): ConfigStatus { |
| 6 | return { |
| 7 | mode: 'unconfigured', |
| 8 | demoLocked: false, |
| 9 | anthropicKeySet: false, |
| 10 | openaiKeySet: false, |
| 11 | anthropicKeyHint: null, |
| 12 | openaiKeyHint: null, |
| 13 | ...overrides, |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | describe('connection labels', () => { |
| 18 | it('names each provider mode in plain language', () => { |
| 19 | expect(connectionLabel(status())).toBe('Setup needed') |
| 20 | expect(connectionLabel(status({ mode: 'demo' }))).toBe('Demo mode') |
| 21 | expect(connectionLabel(status({ mode: 'real' }))).toBe('Your own keys') |
| 22 | }) |
| 23 | |
| 24 | it('explains a demo server started with the demo command', () => { |
| 25 | expect(connectionDetail(status({ mode: 'demo', demoLocked: true }))).toContain('npm run demo') |
| 26 | expect(connectionDetail(status({ mode: 'demo' }))).not.toContain('npm run demo') |
| 27 | }) |
| 28 | |
| 29 | it('shows only key hints when real providers are in use', () => { |
| 30 | const detail = connectionDetail( |
| 31 | status({ mode: 'real', anthropicKeyHint: '...abcd', openaiKeyHint: '...wxyz' }), |
| 32 | ) |
| 33 | expect(detail).toContain('...abcd') |
| 34 | expect(detail).toContain('...wxyz') |
| 35 | }) |
| 36 | }) |
| 37 | |