import { describe, it, expect } from 'vitest'; import { isDemo, demoTryOnLimit } from './config'; import type { WidgetConfig } from '../types'; const base: WidgetConfig = { apiBaseUrl: 'https://brain.example/api/storefront/tryon', publishableKey: 'pk_test', productImage: 'https://shop.example/garment.jpg', productTitle: 'Amalfi Linen Dress', productId: '12', }; describe( 'isDemo', () => { it( 'is off when the merchant config says nothing', () => { expect( isDemo( base ) ).toBe( false ); } ); it( 'is off for a truthy value that is not literally true', () => { expect( isDemo( { ...base, demo: 1 as unknown as boolean } ) ).toBe( false ); expect( isDemo( { ...base, demo: 'yes' as unknown as boolean } ) ).toBe( false ); } ); it( 'is on only for an explicit true', () => { expect( isDemo( { ...base, demo: true } ) ).toBe( true ); } ); } ); describe( 'demoTryOnLimit', () => { it( 'reports the configured limit', () => { expect( demoTryOnLimit( { ...base, demoTryOnLimit: 5 } ) ).toBe( 5 ); } ); it( 'is zero when unset, so no number is put on screen', () => { expect( demoTryOnLimit( base ) ).toBe( 0 ); } ); it( 'refuses a nonsensical limit rather than counting down from it', () => { expect( demoTryOnLimit( { ...base, demoTryOnLimit: -3 } ) ).toBe( 0 ); expect( demoTryOnLimit( { ...base, demoTryOnLimit: Number.NaN } ) ).toBe( 0 ); } ); it( 'floors a fractional limit', () => { expect( demoTryOnLimit( { ...base, demoTryOnLimit: 5.9 } ) ).toBe( 5 ); } ); } );