import { mount, flushPromises } from '@vue/test-utils'; import { createVuetify } from 'vuetify'; import { describe, expect, it, vi, beforeEach } from 'vitest'; function card(overrides: Record = {}) { return { id: 1, sales_user_id: 1, stage: 'new', source: 'search', firm_name: 'ООО Демо', city: 'Ростов', phone: null, site: null, inn: null, rating_label: 'горячая', payload: {}, next_call_at: null, reason: null, registered_email: null, notes: null, ...overrides, }; } vi.mock('../../resources/js/api/sales', () => ({ listProspects: vi.fn().mockResolvedValue({ prospects: [], by_stage: {}, stages: [] }), updateProspect: vi.fn().mockResolvedValue({ id: 1, stage: 'in_work' }), createProspect: vi.fn().mockResolvedValue({ id: 2, stage: 'new', source: 'manager' }), extractSalesErrorMessage: () => 'err', })); import SalesProspectsView from '../../resources/js/views/sales/SalesProspectsView.vue'; import { listProspects, updateProspect, createProspect } from '../../resources/js/api/sales'; const vuetify = createVuetify(); interface ViewVm { open: (p: unknown) => Promise | void; createCandidate: (p: Record) => Promise; } describe('SalesProspectsView', () => { beforeEach(() => { vi.clearAllMocks(); (listProspects as ReturnType).mockResolvedValue({ prospects: [card()], by_stage: {}, stages: [], }); }); it('загружает и показывает карточки менеджера', async () => { const w = mount(SalesProspectsView, { global: { plugins: [vuetify] } }); await flushPromises(); expect(listProspects).toHaveBeenCalledWith(undefined); expect(w.text()).toContain('ООО Демо'); }); it('открытие карточки из «Новые» помечает её взятой в работу (action=opened)', async () => { const w = mount(SalesProspectsView, { global: { plugins: [vuetify] } }); await flushPromises(); await (w.vm as unknown as ViewVm).open(card({ id: 7, stage: 'new' })); await flushPromises(); expect(updateProspect).toHaveBeenCalledWith(7, { action: 'opened' }); }); it('открытие карточки НЕ из «Новые» ничего не помечает', async () => { const w = mount(SalesProspectsView, { global: { plugins: [vuetify] } }); await flushPromises(); await (w.vm as unknown as ViewVm).open(card({ id: 8, stage: 'negotiation' })); await flushPromises(); expect(updateProspect).not.toHaveBeenCalled(); }); it('создаёт своего кандидата через createProspect', async () => { const w = mount(SalesProspectsView, { global: { plugins: [vuetify] } }); await flushPromises(); await (w.vm as unknown as ViewVm).createCandidate({ firm_name: 'ООО Своя', city: 'Омск' }); await flushPromises(); expect(createProspect).toHaveBeenCalledWith({ firm_name: 'ООО Своя', city: 'Омск' }); }); });