import { render } from '@testing-library/react';
import React from 'react';
import { describe, expect, it } from 'vitest';
import { LinkField } from './LinkField';

describe('LinkField', () => {
  it('renders the component without crashing', () => {
    const { container } = render(<LinkField />);

    expect(container).toBeTruthy();
  });

  it('displays a label', () => {
    const mockLabel = 'mockLabel';
    const { container } = render(<LinkField label={mockLabel} />);

    const label = container.querySelector('label');

    expect(label?.textContent).toBe(mockLabel);
  });

  it('renders a link', () => {
    const mockUrl = '/test';
    const { container } = render(<LinkField url={mockUrl} />);

    const value = container.querySelector('.value') as HTMLAnchorElement;

    expect(value.href).toContain(mockUrl);
  });

  it('sets the download file name', () => {
    const mockFileName = 'test.json';
    const { container } = render(<LinkField download={mockFileName} />);

    const value = container.querySelector('.value') as HTMLAnchorElement;

    expect(value.download).toBe(mockFileName);
  });

  it('renders a string value', () => {
    const mockValue = 'mockLabel';
    const { container } = render(<LinkField value={mockValue} />);

    const value = container.querySelector('.value');

    expect(value?.textContent).toBe(mockValue);
  });

  it('renders a numeric value', () => {
    const mockValue = 3;
    const { container } = render(<LinkField value={mockValue} />);

    const value = container.querySelector('.value');

    expect(value?.textContent).toBe(String(mockValue));
  });

  it('defaults to empty strings for label and value', () => {
    const mockDefaults = '';
    const { container } = render(<LinkField />);

    const label = container.querySelector('label');
    const value = container.querySelector('.value');

    expect(label?.textContent).toBe(mockDefaults);
    expect(value?.textContent).toBe(mockDefaults);
  });
});
