|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | + |
| 3 | +import { resolveCalculatorUrlSeed } from './url-seed'; |
| 4 | +import { Model, Precision, Sequence } from '@/lib/data-mappings'; |
| 5 | + |
| 6 | +describe('resolveCalculatorUrlSeed', () => { |
| 7 | + it('returns the model when g_model is a known enum value', () => { |
| 8 | + expect(resolveCalculatorUrlSeed({ g_model: 'DeepSeek-V4-Pro' })).toEqual({ |
| 9 | + model: Model.DeepSeek_V4_Pro, |
| 10 | + }); |
| 11 | + }); |
| 12 | + |
| 13 | + it('ignores unknown g_model values so SSR falls back to the default', () => { |
| 14 | + expect(resolveCalculatorUrlSeed({ g_model: 'not-a-model' })).toEqual({}); |
| 15 | + }); |
| 16 | + |
| 17 | + it('returns the sequence when i_seq is a known enum value', () => { |
| 18 | + expect(resolveCalculatorUrlSeed({ i_seq: '1k/1k' })).toEqual({ |
| 19 | + sequence: Sequence.OneK_OneK, |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + it('parses i_prec as a comma-separated list, dropping unknown precisions', () => { |
| 24 | + expect(resolveCalculatorUrlSeed({ i_prec: 'fp8,not-real,bf16' })).toEqual({ |
| 25 | + precisions: [Precision.FP8, Precision.BF16], |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + it('omits precisions when none of the supplied values are known', () => { |
| 30 | + expect(resolveCalculatorUrlSeed({ i_prec: 'garbage' })).toEqual({}); |
| 31 | + }); |
| 32 | + |
| 33 | + it('combines model, sequence, and precisions from the same URL', () => { |
| 34 | + expect( |
| 35 | + resolveCalculatorUrlSeed({ |
| 36 | + g_model: 'DeepSeek-V4-Pro', |
| 37 | + i_seq: '1k/8k', |
| 38 | + i_prec: 'fp4,fp8', |
| 39 | + }), |
| 40 | + ).toEqual({ |
| 41 | + model: Model.DeepSeek_V4_Pro, |
| 42 | + sequence: Sequence.OneK_EightK, |
| 43 | + precisions: [Precision.FP4, Precision.FP8], |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + it('picks the first value when a param is repeated as an array', () => { |
| 48 | + expect(resolveCalculatorUrlSeed({ g_model: ['DeepSeek-V4-Pro', 'GLM-5'] })).toEqual({ |
| 49 | + model: Model.DeepSeek_V4_Pro, |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + it('returns an empty seed for an empty searchParams object', () => { |
| 54 | + expect(resolveCalculatorUrlSeed({})).toEqual({}); |
| 55 | + }); |
| 56 | +}); |
0 commit comments