import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import { createVuetify } from 'vuetify';
import KanbanCard from '../../resources/js/components/kanban/KanbanCard.vue';
import { MOCK_DEALS } from '../../resources/js/composables/mockDeals';

describe('KanbanCard.vue', () => {
    const factory = (deal = MOCK_DEALS[0]) =>
        mount(KanbanCard, {
            props: { deal },
            global: { plugins: [createVuetify()] },
        });

    it('рендерит имя, телефон, проект и стоимость', () => {
        const wrapper = factory(MOCK_DEALS[0]);
        const text = wrapper.text();
        expect(text).toContain('Анна Соколова');
        expect(text).toContain('+7 (916) 871-23-45');
        expect(text).toContain('Натяжные потолки');
        expect(text).toMatch(/1\s+850\s*₽/);
    });

    it('показывает initials менеджера', () => {
        const wrapper = factory(MOCK_DEALS[0]);
        expect(wrapper.text()).toContain('ИП');
    });

    it('emit-ит open(id) при клике', async () => {
        const wrapper = factory(MOCK_DEALS[0]);
        await wrapper.find('.kanban-card').trigger('click');
        expect(wrapper.emitted('open')).toBeTruthy();
        expect(wrapper.emitted('open')?.[0]).toEqual([MOCK_DEALS[0].id]);
    });
});
