Files
portal/app/tests/Frontend/EditProjectDialog.spec.ts
T
Дмитрий 55a9d3fe00 fix(types): unify Project interface + NavItem.countKey + drop legacy Record
vue-tsc was emitting 9 errors from two issues:

1. ProjectCard.vue had a local `interface Project` missing region_mask /
   region_mode / delivery_days_mask, while stores/projectsStore.ts
   exported the canonical one with those fields. ProjectsView.vue passed
   the canonical Project to ProjectCard handler signatures which expected
   the local incomplete one → 5× TS2322.

2. EditProjectDialog passed `project: Project | Record<string, unknown>`
   to NewProjectDialog which expected `Record<string, unknown> | null`.
   Project lacks an index signature → TS2322.

3. AppSidebar.vue template referenced `item.countKey` not declared in
   NavItem interface → 2× TS2339.

Changes:
- ProjectCard.vue: drop local Project, import from projectsStore.
- NewProjectDialog.vue: project prop type → Project | null (was Record).
  Drop `as { id: number }` cast on PATCH URL.
- EditProjectDialog.vue: project prop type → Project | null.
- AppSidebar.vue: add `countKey?: string` to NavItem.
- projectsStore.ts: make region_mask/region_mode/delivery_days_mask
  optional (backward-compat for mock fixtures; production rows always
  populate them by schema).
- Test/story fixtures expanded with delivered_today/is_active/archived_at/
  sync_status to match strict Project shape.

Verification:
- npx vue-tsc --noEmit → 0 errors (was 9).
- npx vitest run on 5 affected specs → 16/16 passed + 2 skipped.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 20:15:26 +03:00

69 lines
2.3 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' 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 () => {
(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);
});
});