|
1 | 1 | import { describe, expect, it, vi } from 'vitest'; |
2 | | -import { applyLocaleChange } from './Settings'; |
| 2 | +import { applyLocaleChange, computeModelOptions } from './Settings'; |
3 | 3 |
|
4 | 4 | vi.mock('@open-codesign/i18n', () => ({ |
5 | 5 | setLocale: vi.fn((locale: string) => Promise.resolve(locale)), |
@@ -34,3 +34,57 @@ describe('applyLocaleChange', () => { |
34 | 34 | expect(result).toBe('zh-CN'); |
35 | 35 | }); |
36 | 36 | }); |
| 37 | + |
| 38 | +describe('computeModelOptions', () => { |
| 39 | + const suffix = '(active, not in provider list)'; |
| 40 | + |
| 41 | + it('returns null while the list is still loading', () => { |
| 42 | + expect( |
| 43 | + computeModelOptions({ models: null, activeModelId: 'opus-4-7', notInListSuffix: suffix }), |
| 44 | + ).toBeNull(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('returns null when the provider returned an empty list', () => { |
| 48 | + expect( |
| 49 | + computeModelOptions({ models: [], activeModelId: 'opus-4-7', notInListSuffix: suffix }), |
| 50 | + ).toBeNull(); |
| 51 | + }); |
| 52 | + |
| 53 | + it('returns the fetched list unchanged when the active model is in it', () => { |
| 54 | + const result = computeModelOptions({ |
| 55 | + models: ['haiku', 'sonnet', 'opus-4-7'], |
| 56 | + activeModelId: 'opus-4-7', |
| 57 | + notInListSuffix: suffix, |
| 58 | + }); |
| 59 | + expect(result).toEqual([ |
| 60 | + { value: 'haiku', label: 'haiku' }, |
| 61 | + { value: 'sonnet', label: 'sonnet' }, |
| 62 | + { value: 'opus-4-7', label: 'opus-4-7' }, |
| 63 | + ]); |
| 64 | + }); |
| 65 | + |
| 66 | + it('pins the active model at the top when it is not in the fetched list (issue #136)', () => { |
| 67 | + const result = computeModelOptions({ |
| 68 | + models: ['haiku', 'sonnet'], |
| 69 | + activeModelId: 'opus-4-7', |
| 70 | + notInListSuffix: suffix, |
| 71 | + }); |
| 72 | + expect(result).toEqual([ |
| 73 | + { value: 'opus-4-7', label: `opus-4-7 ${suffix}` }, |
| 74 | + { value: 'haiku', label: 'haiku' }, |
| 75 | + { value: 'sonnet', label: 'sonnet' }, |
| 76 | + ]); |
| 77 | + }); |
| 78 | + |
| 79 | + it('does not inject anything for inactive rows (activeModelId = null)', () => { |
| 80 | + const result = computeModelOptions({ |
| 81 | + models: ['haiku', 'sonnet'], |
| 82 | + activeModelId: null, |
| 83 | + notInListSuffix: suffix, |
| 84 | + }); |
| 85 | + expect(result).toEqual([ |
| 86 | + { value: 'haiku', label: 'haiku' }, |
| 87 | + { value: 'sonnet', label: 'sonnet' }, |
| 88 | + ]); |
| 89 | + }); |
| 90 | +}); |
0 commit comments