import { describe, expect, it } from 'vitest'; import { defaultEdits, normalizeEdits } from './edits'; import { DENOISE_MODELS, denoiseModelLabel, denoiseProgressLabel, withDenoiseRender, } from './denoiseModels'; describe('AI denoise edit normalization', () => { it('keeps the model the user picked', () => { for (const model of ['guided', 'scunet', 'nlm'] as const) { expect(normalizeEdits({ aiDenoise: { model } } as never).aiDenoise.model).toBe(model); } }); it('defaults an unknown or missing model to guided', () => { expect(normalizeEdits({}).aiDenoise.model).toBe('guided'); expect(normalizeEdits({ aiDenoise: {} } as never).aiDenoise.model).toBe('guided'); expect(normalizeEdits({ aiDenoise: { model: 'swinir' } } as never).aiDenoise.model).toBe( 'guided', ); }); it('keeps the render key and the amount, and drops an unusable key', () => { const kept = normalizeEdits({ aiDenoise: { model: 'nlm', key: 'abc123', amount: 40 } } as never); expect(kept.aiDenoise).toEqual({ model: 'nlm', key: 'abc123', amount: 40 }); const dropped = normalizeEdits({ aiDenoise: { key: '' } } as never); expect(dropped.aiDenoise.key).toBeNull(); }); }); describe('AI denoise model selection', () => { it('commits the render under the base that produced it', () => { // The regression: the panel's completion path used to spread a copy of the // edit captured before the chip click, which put the previous model back. const previous = { ...defaultEdits().aiDenoise, model: 'guided' as const, amount: 70 }; const next = withDenoiseRender(previous, 'scunet', 'key-scunet'); expect(next).toEqual({ model: 'scunet', key: 'key-scunet', amount: 70 }); expect(previous).toEqual({ model: 'guided', key: null, amount: 70 }); }); it('keeps a stale picker honest for every base', () => { const previous = { ...defaultEdits().aiDenoise, model: 'guided' as const }; for (const option of DENOISE_MODELS) { expect(withDenoiseRender(previous, option.value, `key-${option.value}`).model).toBe( option.value, ); } }); it('names the stage and tile count a running render reports', () => { expect(denoiseProgressLabel({ stage: 'base', done: 12, total: 40 }, 'scunet', 31)).toBe( 'Rendering with SCUNet · denoising 12/40 tiles · 31s elapsed', ); expect(denoiseProgressLabel({ stage: 'gate' }, 'guided', 7.4)).toBe( 'Rendering with Guided · mapping detail · 7s elapsed', ); // No tile counter for the classical models, and no stage at all before the // first poll lands. expect(denoiseProgressLabel({ stage: 'base' }, 'nlm', 2)).toBe( 'Rendering with NLM · denoising · 2s elapsed', ); expect(denoiseProgressLabel(null, 'scunet', 0)).toBe( 'Rendering with SCUNet · starting · 0s elapsed', ); // A worker that over-counts cannot report past the end of the run. expect(denoiseProgressLabel({ stage: 'base', done: 99, total: 40 }, 'scunet', 90)).toContain( '40/40 tiles', ); }); it('offers each selectable model exactly once, with a label', () => { const values = DENOISE_MODELS.map((option) => option.value); expect(new Set(values).size).toBe(values.length); expect(values).toEqual(['guided', 'scunet', 'nlm']); for (const option of DENOISE_MODELS) { expect(option.label, option.value).toBeTruthy(); expect(option.title, option.value).toBeTruthy(); expect(denoiseModelLabel(option.value)).toBe(option.label); } }); });