import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import FilterChip from '../../resources/js/components/ui/FilterChip.vue';

describe('FilterChip', () => {
    it('renders label', () => {
        const w = mount(FilterChip, { props: { label: 'Статус' } });
        expect(w.text()).toContain('Статус');
    });

    it('renders count badge when count > 0', () => {
        const w = mount(FilterChip, { props: { label: 'Статус', count: 3 } });
        expect(w.find('.ld-filter-chip__count').exists()).toBe(true);
        expect(w.find('.ld-filter-chip__count').text()).toBe('3');
    });

    it('hides count badge when count is 0 or undefined', () => {
        expect(
            mount(FilterChip, { props: { label: 'X', count: 0 } })
                .find('.ld-filter-chip__count')
                .exists(),
        ).toBe(false);
        expect(
            mount(FilterChip, { props: { label: 'X' } })
                .find('.ld-filter-chip__count')
                .exists(),
        ).toBe(false);
    });

    it('applies active class when active=true', () => {
        const w = mount(FilterChip, { props: { label: 'X', active: true } });
        expect(w.classes()).toContain('ld-filter-chip--active');
    });

    it('emits click on click', async () => {
        const w = mount(FilterChip, { props: { label: 'X' } });
        await w.trigger('click');
        expect(w.emitted('click')).toHaveLength(1);
    });
});
