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

describe('VBadge.vue', () => {
  it('renders with required text prop and default variant', () => {
    const wrapper = mount(VBadge, { props: { text: 'Test Badge' } });
    expect(wrapper.text()).toBe('Test Badge');
    expect(wrapper.classes()).toContain('item-badge');
    expect(wrapper.classes()).toContain('badge-secondary'); // Default variant
  });

  it('renders with specified variant', () => {
    const wrapper = mount(VBadge, {
      props: { text: 'Accent Badge', variant: 'accent' },
    });
    expect(wrapper.classes()).toContain('badge-accent');
  });

  it('applies sticky class when variant is accent and sticky is true', () => {
    const wrapper = mount(VBadge, {
      props: { text: 'Sticky Accent', variant: 'accent', sticky: true },
    });
    expect(wrapper.classes()).toContain('badge-sticky');
  });

  it('does not apply sticky class when sticky is true but variant is not accent', () => {
    const wrapper = mount(VBadge, {
      props: { text: 'Sticky Secondary', variant: 'secondary', sticky: true },
    });
    expect(wrapper.classes()).not.toContain('badge-sticky');
  });

  it('does not apply sticky class when variant is accent but sticky is false', () => {
    const wrapper = mount(VBadge, {
      props: { text: 'Non-sticky Accent', variant: 'accent', sticky: false },
    });
    expect(wrapper.classes()).not.toContain('badge-sticky');
  });

  it('validates the variant prop', () => {
    const validator = VBadge.props.variant.validator;
    expect(validator('secondary')).toBe(true);
    expect(validator('accent')).toBe(true);
    expect(validator('settled')).toBe(true);
    expect(validator('pending')).toBe(true);
    expect(validator('invalid-variant')).toBe(false);
  });

  // Test for required prop 'text' (Vue Test Utils will warn if not provided)
  it('Vue Test Utils should warn if required prop text is missing', () => {
    const spy = vi.spyOn(console, 'warn').mockImplementation(() => {});
    // Mount without the required 'text' prop
    // @ts-expect-error testing missing required prop
    mount(VBadge, { props: { variant: 'accent'} });
    // Check if Vue's warning about missing required prop was logged
    // This depends on Vue's warning messages and might need adjustment
    expect(spy.mock.calls.some(call => call[0].includes('[Vue warn]: Missing required prop: "text"'))).toBe(true);
    spy.mockRestore();
  });
});
