import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { QuotaBlockedView } from './QuotaBlockedView';
import { en } from '../i18n/en';

describe('QuotaBlockedView shopper-safe quota copy', () => {
  it('uses the neutral default without exposing quota or billing', () => {
    render(
      <QuotaBlockedView
        status="quota_exhausted"
        planName={null}
        onClose={vi.fn()}
        t={en.quota}
      />
    );

    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(
      <QuotaBlockedView
        status="quota_exhausted"
        planName={null}
        onClose={vi.fn()}
        t={en.quota}
        customContent={{
          title: 'Our fitting room is having a glow-up',
          message: 'Explore the latest arrivals and come back soon.',
          buttonLabel: 'See new arrivals',
          buttonUrl: 'https://shop.example/new',
        }}
      />
    );

    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');
    vi.unstubAllGlobals();
  });
});
