import { describe, it, expect } from 'vitest';
import { demoCounterLabel } from './quotaLabel';
import { en } from '../i18n/en';
import { it as itTranslations } from '../i18n/it';

describe( 'demoCounterLabel', () => {
	it( 'words the try-ons left', () => {
		expect( demoCounterLabel( 3, 5, en ) ).toBe( '3 try-ons left' );
	} );

	it( 'is singular at one', () => {
		expect( demoCounterLabel( 1, 5, en ) ).toBe( '1 try-on left' );
	} );

	// The point of the counter is that the wall is never a surprise, so zero is
	// a number worth saying out loud.
	it( 'still speaks at zero', () => {
		expect( demoCounterLabel( 0, 5, en ) ).toBe( '0 try-ons left' );
	} );

	it( 'says nothing when the demo never advertised a limit', () => {
		expect( demoCounterLabel( 3, 0, en ) ).toBeNull();
	} );

	it( 'says nothing rather than guessing on a nonsensical remainder', () => {
		expect( demoCounterLabel( -1, 5, en ) ).toBeNull();
		expect( demoCounterLabel( Number.NaN, 5, en ) ).toBeNull();
	} );

	it( 'agrees in Italian, with the same numbers', () => {
		expect( demoCounterLabel( 3, 5, itTranslations ) ).toBe( '3 prove rimanenti' );
		expect( demoCounterLabel( 1, 5, itTranslations ) ).toBe( '1 prova rimanente' );
	} );
} );
