import { cleanup, fireEvent, render, screen } from '@testing-library/react'; import { afterEach, describe, expect, it, vi } from 'vitest'; import { QuotaBlockedView } from './QuotaBlockedView'; import { en } from '../i18n/en'; describe('QuotaBlockedView shopper-safe quota copy', () => { afterEach( () => { cleanup(); vi.unstubAllGlobals(); } ); it('uses the neutral default without exposing quota or billing', () => { render( ); expect(screen.getByText('Virtual try-on will be back soon')).toBeTruthy(); expect(screen.getByText(/refreshing the virtual fitting room/i)).toBeTruthy(); expect(screen.queryByText(/quota|billing|store owner/i)).toBeNull(); expect(screen.getByRole('button').textContent).toBe('Continue shopping'); }); it('uses merchant copy and follows its same-site CTA', () => { const assign = vi.fn(); vi.stubGlobal('location', { assign }); render( ); expect(screen.getByText('Our fitting room is having a glow-up')).toBeTruthy(); fireEvent.click(screen.getByRole('button', { name: 'See new arrivals' })); expect(assign).toHaveBeenCalledWith('https://shop.example/new'); }); it.each( [ [ 'no_subscription', en.quota.noSubscriptionTitle ], [ 'subscription_inactive', en.quota.temporarilyUnavailableTitle ], [ 'free_tier_exhausted', en.quota.freeTierExhaustedTitle ], ] as const )( 'renders the %s state and closes locally', ( status, title ) => { const onClose = vi.fn(); render( ); expect( screen.getByText( title ) ).toBeTruthy(); fireEvent.click( screen.getByRole( 'button', { name: en.quota.close } ) ); expect( onClose ).toHaveBeenCalledOnce(); } ); it( 'shows the visitor cooldown and closes locally', () => { const onClose = vi.fn(); render( ); expect( screen.getByText( /17 minutes/ ) ).toBeTruthy(); fireEvent.click( screen.getByRole( 'button', { name: en.quota.close } ) ); expect( onClose ).toHaveBeenCalledOnce(); } ); });