b1c3efa1e1
Root causes: 1. Default axios без withXSRFToken не отправлял CSRF header → 419 silent fail (catch ловил только 422). 2. PDD regions UI (commits 4f60add..f982046) использовал 32-bit маску, несовместимую с schema's 8-битным CHECK chk_projects_region_mask_range → 500 silent fail. Changes (NewProjectDialog.vue): - Replace default axios import с apiClient + ensureCsrfCookie + extractErrorMessage из api/client.ts (same pattern как NewDealDialog). - await ensureCsrfCookie() перед mutating; apiClient.post/patch. - Remove regions <v-autocomplete> + selectedRegions ref + inverted region_mode watcher (interim A — proper 89-codes реализация в Plan 6). - Add general error banner для non-422 ошибок (419/401/500/network). - form.region_mask=255 + region_mode='include' (schema default = вся РФ). Changes (EditProjectDialog.spec.ts): - Switch mock с default axios на apiClient (cascading from above). Verified: Pest 742/739/3sk/0, Vitest 758/3sk/0, vue-tsc 0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
75 lines
2.5 KiB
TypeScript
75 lines
2.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { mount, flushPromises } from '@vue/test-utils';
|
|
import { createPinia, setActivePinia } from 'pinia';
|
|
import { createVuetify } from 'vuetify';
|
|
|
|
vi.mock('../../resources/js/api/client', () => ({
|
|
apiClient: {
|
|
post: vi.fn().mockResolvedValue({ data: {} }),
|
|
patch: vi.fn().mockResolvedValue({ data: {} }),
|
|
},
|
|
ensureCsrfCookie: vi.fn().mockResolvedValue(undefined),
|
|
extractErrorMessage: vi.fn(() => 'Произошла ошибка.'),
|
|
}));
|
|
|
|
import { apiClient } from '../../resources/js/api/client';
|
|
import EditProjectDialog from '../../resources/js/views/projects/EditProjectDialog.vue';
|
|
|
|
const sampleProject = {
|
|
id: 1,
|
|
name: 'X',
|
|
signal_type: 'site' as const,
|
|
signal_identifier: 'x.ru',
|
|
daily_limit_target: 10,
|
|
delivered_today: 0,
|
|
is_active: true,
|
|
archived_at: null,
|
|
sync_status: 'ok' as const,
|
|
region_mask: 0,
|
|
region_mode: 'include',
|
|
delivery_days_mask: 127,
|
|
};
|
|
|
|
// VDialog в JSDOM не рендерит через teleport — стаб делает <slot/> доступным
|
|
// для wrapper.text() / find(). Паттерн из NewProjectDialog.spec.ts.
|
|
const factory = (props: { modelValue: boolean; project: typeof sampleProject }) =>
|
|
mount(EditProjectDialog, {
|
|
props,
|
|
global: {
|
|
plugins: [createVuetify()],
|
|
stubs: {
|
|
VDialog: {
|
|
template: '<div class="dialog-stub" v-if="modelValue"><slot /></div>',
|
|
props: ['modelValue'],
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia());
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('EditProjectDialog', () => {
|
|
it('prefills form from project prop', async () => {
|
|
const wrapper = factory({ modelValue: true, project: sampleProject });
|
|
await flushPromises();
|
|
expect(wrapper.text()).toContain('Редактирование');
|
|
});
|
|
|
|
it('PATCH on submit', async () => {
|
|
const wrapper = factory({ modelValue: true, project: sampleProject });
|
|
await flushPromises();
|
|
await wrapper.find('[data-testid="submit-btn"]').trigger('click');
|
|
await flushPromises();
|
|
expect(apiClient.patch).toHaveBeenCalled();
|
|
});
|
|
|
|
it('signal_type tabs disabled in edit mode', async () => {
|
|
const wrapper = factory({ modelValue: true, project: sampleProject });
|
|
await flushPromises();
|
|
expect(wrapper.findComponent({ name: 'VTabs' }).props('disabled')).toBe(true);
|
|
});
|
|
});
|