5ba553a0cc
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
47 lines
2.3 KiB
TypeScript
47 lines
2.3 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { mount } from '@vue/test-utils';
|
|
import { createPinia, setActivePinia } from 'pinia';
|
|
import { createVuetify } from 'vuetify';
|
|
import { reactive, ref } from 'vue';
|
|
import axios from 'axios';
|
|
|
|
vi.mock('axios');
|
|
import EditProjectScreen from '../../resources/js/views/autopodbor/screens/EditProjectScreen.vue';
|
|
|
|
const vuetify = createVuetify();
|
|
function makeNav(editProjectId: number | null = 99) {
|
|
return { go: vi.fn(), ctx: reactive({ runId: null, competitorId: 3, selectedSourceIds: [], loadMsg: '', loadSub: '', editProjectId, createdCount: 0, launched: false }), screen: ref('editproject') };
|
|
}
|
|
function mountEdit(nav: any) {
|
|
return mount(EditProjectScreen, { global: { plugins: [vuetify], provide: { autopodborNav: nav } } });
|
|
}
|
|
|
|
describe('EditProjectScreen', () => {
|
|
beforeEach(() => { setActivePinia(createPinia()); vi.clearAllMocks(); });
|
|
|
|
it('грузит проект и заполняет форму', async () => {
|
|
(axios.get as any).mockResolvedValue({ data: { data: { id: 99, name: 'Окна Комфорт 🎭', regions: [16], daily_limit_target: 20, delivery_days_mask: 127, signal_type: 'call', signal_identifier: '78003507700' } } });
|
|
const w = mountEdit(makeNav(99));
|
|
await new Promise(r => setTimeout(r, 0));
|
|
expect(axios.get).toHaveBeenCalledWith('/api/projects/99');
|
|
expect((w.vm as any).name).toBe('Окна Комфорт 🎭');
|
|
expect((w.vm as any).dailyLimit).toBe(20);
|
|
});
|
|
|
|
it('сохранение шлёт PATCH и возвращает на detail', async () => {
|
|
(axios.get as any).mockResolvedValue({ data: { data: { id: 99, name: 'Окна Комфорт 🎭', regions: [16], daily_limit_target: 20, delivery_days_mask: 127 } } });
|
|
(axios.patch as any).mockResolvedValue({ data: { data: { id: 99 } } });
|
|
const nav = makeNav(99);
|
|
const w = mountEdit(nav);
|
|
await new Promise(r => setTimeout(r, 0));
|
|
const btn = w.findAll('button').find(b => b.text().includes('Сохранить'));
|
|
await btn!.trigger('click');
|
|
await new Promise(r => setTimeout(r, 0));
|
|
expect(axios.patch).toHaveBeenCalled();
|
|
const [url, body] = (axios.patch as any).mock.calls[0];
|
|
expect(url).toBe('/api/projects/99');
|
|
expect(body.name).toBe('Окна Комфорт 🎭');
|
|
expect(nav.go).toHaveBeenCalledWith('detail');
|
|
});
|
|
});
|