65 lines
2.2 KiB
TypeScript
65 lines
2.2 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';
|
|
import axios from 'axios';
|
|
|
|
vi.mock('axios');
|
|
|
|
import EditProjectDialog from '../../resources/js/views/projects/EditProjectDialog.vue';
|
|
|
|
const sampleProject = {
|
|
id: 1,
|
|
name: 'X',
|
|
signal_type: 'site',
|
|
signal_identifier: 'x.ru',
|
|
daily_limit_target: 10,
|
|
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 () => {
|
|
(axios.patch as ReturnType<typeof vi.fn>).mockResolvedValue({ data: { data: { id: 1 } } });
|
|
const wrapper = factory({ modelValue: true, project: sampleProject });
|
|
await flushPromises();
|
|
await wrapper.find('[data-testid="submit-btn"]').trigger('click');
|
|
await flushPromises();
|
|
expect(axios.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);
|
|
});
|
|
});
|