import { render, screen, fireEvent } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { SocialShare } from '../social-share';

describe('SocialShare', () => {
  it('renders Facebook, Zalo and copy-link actions', () => {
    render(<SocialShare listingId="abc-123" listingTitle="Căn hộ mẫu" />);
    expect(screen.getByLabelText('Chia sẻ lên Facebook')).toBeInTheDocument();
    expect(screen.getByLabelText('Chia sẻ lên Zalo')).toBeInTheDocument();
    expect(screen.getByLabelText('Sao chép liên kết')).toBeInTheDocument();
  });

  it('shows the backend QR code image when toggled on', () => {
    render(<SocialShare listingId="abc-123" listingTitle="Căn hộ mẫu" />);
    const toggle = screen.getByLabelText('Hiện mã QR');
    fireEvent.click(toggle);
    const img = screen.getByAltText('Mã QR cho Căn hộ mẫu') as HTMLImageElement;
    expect(img).toBeInTheDocument();
    expect(img.src).toContain('/listings/abc-123/qr-code');
  });
});
