import { mount } from '@vue/test-utils';
import VIcon from './VIcon.vue';
import { describe, it, expect } from 'vitest';

describe('VIcon.vue', () => {
  it('renders the icon with the correct name class', () => {
    const wrapper = mount(VIcon, {
      props: { name: 'alert' },
    });
    expect(wrapper.classes()).toContain('icon');
    expect(wrapper.classes()).toContain('icon-alert');
  });

  it('renders the icon with the correct size class when size is provided', () => {
    const wrapper = mount(VIcon, {
      props: { name: 'search', size: 'sm' },
    });
    expect(wrapper.classes()).toContain('icon-sm');
  });

  it('renders the icon without a size class when size is not provided', () => {
    const wrapper = mount(VIcon, {
      props: { name: 'close' },
    });
    expect(wrapper.classes().find(cls => cls.startsWith('icon-sm') || cls.startsWith('icon-lg'))).toBeUndefined();
  });

  it('renders nothing if name is not provided (due to required prop)', () => {
    // Vue Test Utils might log a warning about missing required prop, which is expected.
    // We are testing the component's behavior in such a scenario.
    // Depending on error handling, it might render an empty <i> tag or nothing.
    // Here, we assume it renders the <i> tag due to the template structure.
    const wrapper = mount(VIcon, {
      // @ts-expect-error testing missing required prop
      props: { size: 'lg' },
    });
    // It will still render the <i> tag, but without the icon-name class if `name` is truly not passed.
    // However, Vue's prop validation will likely prevent mounting or cause errors.
    // For a robust test, one might check for console warnings or specific error handling.
    // Given the current setup, it will have 'icon' but not 'icon-undefined' or similar.
    expect(wrapper.find('i').exists()).toBe(true);
    // It should not have an `icon-undefined` or similar class if name is not passed.
    // The behavior might depend on how Vue handles missing required props at runtime in test env.
    // A more accurate test would be to check that the specific icon name class is NOT present.
    expect(wrapper.classes().some(cls => cls.startsWith('icon-') && cls !== 'icon-sm' && cls !== 'icon-lg')).toBe(false);
  });

  it('validates the size prop', () => {
    const validator = VIcon.props.size.validator;
    expect(validator('sm')).toBe(true);
    expect(validator('lg')).toBe(true);
    expect(validator('md')).toBe(false);
    expect(validator('')).toBe(false);
  });
});
