bb2fe2f34d
Этап 1 Task 10. Селектор результата, поля по стадии, отказ скрыт при user, обязательные причина/время. Тесты через vm (v-dialog телепортит контент). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
78 lines
2.7 KiB
TypeScript
78 lines
2.7 KiB
TypeScript
import { mount } from '@vue/test-utils';
|
||
import { createVuetify } from 'vuetify';
|
||
import { describe, expect, it } from 'vitest';
|
||
import SalesProspectDialog from '../../resources/js/components/sales/SalesProspectDialog.vue';
|
||
import type { SalesProspect } from '../../resources/js/api/sales';
|
||
|
||
const vuetify = createVuetify();
|
||
|
||
function prospect(overrides: Partial<SalesProspect> = {}): SalesProspect {
|
||
return {
|
||
id: 1,
|
||
sales_user_id: 1,
|
||
stage: 'new',
|
||
firm_name: 'ООО Тест',
|
||
city: 'Ростов',
|
||
phone: '+7800',
|
||
site: 'test.ru',
|
||
inn: '6161',
|
||
rating_label: 'горячая',
|
||
payload: {},
|
||
next_call_at: null,
|
||
reason: null,
|
||
registered_email: null,
|
||
notes: null,
|
||
...overrides,
|
||
};
|
||
}
|
||
|
||
interface DialogVm {
|
||
action: string;
|
||
reason: string;
|
||
nextCallAt: string;
|
||
siteHref: string | null;
|
||
availableActions: { value: string; title: string }[];
|
||
submit: () => void;
|
||
}
|
||
|
||
function factory(p: SalesProspect) {
|
||
return mount(SalesProspectDialog, {
|
||
props: { modelValue: true, prospect: p },
|
||
global: { plugins: [vuetify] },
|
||
});
|
||
}
|
||
|
||
describe('SalesProspectDialog', () => {
|
||
it('siteHref добавляет https к домену', () => {
|
||
const w = factory(prospect());
|
||
expect((w.vm as unknown as DialogVm).siteHref).toBe('https://test.ru');
|
||
});
|
||
|
||
it('для stage=user действие «Отказ» недоступно', () => {
|
||
const w = factory(prospect({ stage: 'user' }));
|
||
const values = (w.vm as unknown as DialogVm).availableActions.map((a) => a.value);
|
||
expect(values).not.toContain('rejected');
|
||
});
|
||
|
||
it('для обычной стадии «Отказ» доступен', () => {
|
||
const w = factory(prospect({ stage: 'negotiation' }));
|
||
const values = (w.vm as unknown as DialogVm).availableActions.map((a) => a.value);
|
||
expect(values).toContain('rejected');
|
||
});
|
||
|
||
it('«Переговоры» без даты — submit не эмитит save', () => {
|
||
const w = factory(prospect());
|
||
(w.vm as unknown as DialogVm).action = 'negotiation';
|
||
(w.vm as unknown as DialogVm).submit();
|
||
expect(w.emitted('save')).toBeFalsy();
|
||
});
|
||
|
||
it('«Отказ» с причиной — эмитит save с action=rejected', () => {
|
||
const w = factory(prospect({ stage: 'negotiation' }));
|
||
(w.vm as unknown as DialogVm).action = 'rejected';
|
||
(w.vm as unknown as DialogVm).reason = 'дорого';
|
||
(w.vm as unknown as DialogVm).submit();
|
||
expect(w.emitted('save')?.[0]?.[0]).toMatchObject({ action: 'rejected', reason: 'дорого' });
|
||
});
|
||
});
|