import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import { createVuetify } from 'vuetify';
import DealsBulkBar from '../../resources/js/components/deals/DealsBulkBar.vue';

const vuetify = createVuetify();
const leadStatuses = [
    { slug: 'new', nameRu: 'Новые', isSystem: true, sortOrder: 1, colorHex: '#3B82F6' },
    { slug: 'viewed', nameRu: 'Просмотрено', isSystem: true, sortOrder: 2, colorHex: '#8B5CF6' },
];

describe('DealsBulkBar', () => {
    it('скрыт при selectedCount=0', () => {
        const w = mount(DealsBulkBar, {
            props: { selectedCount: 0, statusMenuOpen: false, leadStatuses },
            global: { plugins: [vuetify] },
        });
        expect(w.find('[data-testid="bulk-bar"]').exists()).toBe(false);
    });

    it('виден при selectedCount>0 и показывает количество', () => {
        const w = mount(DealsBulkBar, {
            props: { selectedCount: 3, statusMenuOpen: false, leadStatuses },
            global: { plugins: [vuetify] },
        });
        const bar = w.find('[data-testid="bulk-bar"]');
        expect(bar.exists()).toBe(true);
        expect(bar.text()).toContain('3');
    });

    it('НЕ содержит кнопок Экспорт/Удалить', () => {
        const w = mount(DealsBulkBar, {
            props: { selectedCount: 2, statusMenuOpen: false, leadStatuses },
            global: { plugins: [vuetify] },
        });
        expect(w.find('[data-testid="bulk-export-btn"]').exists()).toBe(false);
        expect(w.find('[data-testid="bulk-delete-btn"]').exists()).toBe(false);
    });

    it('✕ эмитит clear-selected', async () => {
        const w = mount(DealsBulkBar, {
            props: { selectedCount: 2, statusMenuOpen: false, leadStatuses },
            global: { plugins: [vuetify] },
        });
        await w.find('[data-testid="bulk-clear-btn"]').trigger('click');
        expect(w.emitted('clear-selected')).toBeTruthy();
    });
});
