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

describe('VSpinner.vue', () => {
  it('applies default "md" size (no specific class for md, just .spinner-dots)', () => {
    const wrapper = mount(VSpinner);
    expect(wrapper.classes()).toContain('spinner-dots');
    // Check that it does NOT have sm class unless specified
    expect(wrapper.classes()).not.toContain('spinner-dots-sm');
  });

  it('applies .spinner-dots-sm class when size is "sm"', () => {
    const wrapper = mount(VSpinner, { props: { size: 'sm' } });
    expect(wrapper.classes()).toContain('spinner-dots'); // Base class
    expect(wrapper.classes()).toContain('spinner-dots-sm'); // Size specific class
  });

  it('does not apply .spinner-dots-sm class when size is "md"', () => {
    const wrapper = mount(VSpinner, { props: { size: 'md' } });
    expect(wrapper.classes()).toContain('spinner-dots');
    expect(wrapper.classes()).not.toContain('spinner-dots-sm');
  });


  it('sets aria-label attribute with the label prop value', () => {
    const labelText = 'Fetching data, please wait...';
    const wrapper = mount(VSpinner, { props: { label: labelText } });
    expect(wrapper.attributes('aria-label')).toBe(labelText);
  });

  it('sets default aria-label "Loading..." if label prop is not provided', () => {
    const wrapper = mount(VSpinner); // No label prop
    expect(wrapper.attributes('aria-label')).toBe('Loading...');
  });

  it('has role="status" attribute', () => {
    const wrapper = mount(VSpinner);
    expect(wrapper.attributes('role')).toBe('status');
  });

  it('renders three <span> elements for the dots', () => {
    const wrapper = mount(VSpinner);
    const dotSpans = wrapper.findAll('span');
    expect(dotSpans.length).toBe(3);
  });

  it('validates size prop correctly', () => {
    const validator = VSpinner.props.size.validator;
    expect(validator('sm')).toBe(true);
    expect(validator('md')).toBe(true);
    expect(validator('lg')).toBe(false); // lg is not a valid size
    expect(validator('')).toBe(false);
  });
});
