Files
portal/app/tests/Frontend/TwoFactorView.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

55 lines
2.3 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import { createPinia, setActivePinia } from 'pinia';
import { createVuetify } from 'vuetify';
import { createRouter, createMemoryHistory } from 'vue-router';
import TwoFactorView from '../../resources/js/views/auth/TwoFactorView.vue';
import { useAuthStore } from '../../resources/js/stores/auth';
const mountTwoFactor = async () => {
setActivePinia(createPinia());
// Эмулируем pending-2FA state — иначе onMounted редиректит на /login.
const auth = useAuthStore();
auth.requires2fa = true;
const router = createRouter({
history: createMemoryHistory(),
routes: [
{ path: '/2fa', component: TwoFactorView },
{ path: '/login', component: { template: '<div>stub</div>' } },
{ path: '/dashboard', component: { template: '<div>stub</div>' } },
{ path: '/recovery', component: { template: '<div>stub</div>' } },
{ path: '/recovery-use', component: { template: '<div>stub</div>' } },
],
});
await router.push('/2fa');
await router.isReady();
return mount(TwoFactorView, {
global: { plugins: [createVuetify(), router] },
});
};
describe('TwoFactorView.vue', () => {
it('монтируется и содержит заголовок', async () => {
const wrapper = await mountTwoFactor();
expect(wrapper.text()).toContain('Двухфакторная проверка');
});
it('содержит ровно 6 input-cell для кода', async () => {
const wrapper = await mountTwoFactor();
const cells = wrapper.findAll('.code-cell');
expect(cells).toHaveLength(6);
// Каждая cell — numeric inputmode + maxlength=1.
cells.forEach((cell) => {
expect(cell.attributes('inputmode')).toBe('numeric');
expect(cell.attributes('maxlength')).toBe('1');
});
});
it('содержит ссылку на резервный код', async () => {
const wrapper = await mountTwoFactor();
const links = wrapper.findAll('a').map((a) => a.text());
expect(links.some((t) => t.includes('резервный код'))).toBe(true);
});
});