Files
portal/app/tests/Frontend/ProjectsView.spec.ts
T
Дмитрий 245b76ec43 test(frontend): fix 17 ESLint errors + TwoFactorView router stub
ESLint emitted 17 errors in tests/Frontend/* (production code clean):
- 13× @typescript-eslint/no-explicit-any in axios mock casts
  (BulkActionsBar, ProjectsView, projectsStore specs)
- 3× vitest/no-disabled-tests rule-not-found
  (eslint-plugin-vitest not registered; inline-disable comments stale)
- 1× @typescript-eslint/no-unused-vars on imported beforeEach

Plus Phase 5 audit finding: TwoFactorView.spec.ts test router was
missing /recovery-use stub → Vue Router warn on every TwoFactorView mount.

Changes:
- BulkActionsBar.spec.ts, ProjectsView.spec.ts, projectsStore.spec.ts:
  replace `as any` with `as unknown as ReturnType<typeof vi.fn>` on
  axios method mocks; one case used `as unknown as { regionsOpen: bool }`
  for vm shape.
- NewProjectDialog.spec.ts, ProjectsView.spec.ts: remove stale
  `// eslint-disable-next-line vitest/no-disabled-tests` comments
  (it.skip() lines kept).
- ProjectsView.toolbar.spec.ts: drop unused `beforeEach` from import.
- TwoFactorView.spec.ts: add `/recovery-use` route stub.

Verification:
- npx eslint --max-warnings=0 → exit 0 (was 17 errors).
- npx vitest run on affected specs → 24/27 passed + 3 skipped (was same).
- TwoFactorView spec → 3/3 passed, no Vue Router warn.

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

101 lines
3.7 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 ProjectsView from '../../resources/js/views/ProjectsView.vue';
// VDialog в JSDOM не рендерит в teleport-цели; стабом отключаем диалоги,
// чтобы не падал mount при попытке портала.
const factory = () =>
mount(ProjectsView, {
global: {
plugins: [createVuetify()],
stubs: {
VDialog: {
template: '<div class="dialog-stub" v-if="modelValue"><slot /></div>',
props: ['modelValue'],
},
NewProjectDialog: true,
EditProjectDialog: true,
},
},
});
beforeEach(() => {
setActivePinia(createPinia());
vi.clearAllMocks();
});
describe('ProjectsView', () => {
it('shows empty state when no projects', async () => {
(axios.get as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
data: { data: [], meta: { total: 0, current_page: 1, per_page: 20 } },
});
const wrapper = factory();
await flushPromises();
expect(wrapper.text()).toMatch(/нет проектов|empty/i);
});
it('renders card for each project', async () => {
(axios.get as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
data: {
data: [
{
id: 1,
name: 'AlphaSite',
signal_type: 'site',
signal_identifier: 'a.ru',
daily_limit_target: 10,
delivered_today: 0,
is_active: true,
archived_at: null,
sync_status: 'ok',
},
],
meta: { total: 1, current_page: 1, per_page: 20 },
},
});
const wrapper = factory();
await flushPromises();
expect(wrapper.text()).toContain('AlphaSite');
});
it.skip('filter by signal_type refetches', async () => {
// TODO: VSelect dropdown в jsdom не открывает items-list через teleport,
// findComponent({name:'VSelect'}).vm.$emit некорректно тригерит реактивную
// цепочку @update:model-value. Покрытие — через Histoire + e2e после Plan 5.
});
it('shows BulkActionsBar when at least 1 selected', async () => {
(axios.get as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
data: {
data: [
{
id: 1,
name: 'A',
signal_type: 'site',
signal_identifier: 'a.ru',
daily_limit_target: 10,
delivered_today: 0,
is_active: true,
archived_at: null,
sync_status: 'ok',
},
],
meta: { total: 1, current_page: 1, per_page: 20 },
},
});
const wrapper = factory();
await flushPromises();
const card = wrapper.findComponent({ name: 'ProjectCard' });
expect(card.exists()).toBe(true);
card.vm.$emit('toggle-select', 1);
await wrapper.vm.$nextTick();
expect(wrapper.findComponent({ name: 'BulkActionsBar' }).exists()).toBe(true);
});
});