69 lines
3.1 KiB
TypeScript
69 lines
3.1 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
||
import { mount } from '@vue/test-utils';
|
||
import { createVuetify } from 'vuetify';
|
||
import { createRouter, createMemoryHistory } from 'vue-router';
|
||
import AdminIncidentsView from '../../resources/js/views/admin/AdminIncidentsView.vue';
|
||
|
||
const mountView = async () => {
|
||
const router = createRouter({
|
||
history: createMemoryHistory(),
|
||
routes: [
|
||
{ path: '/admin/incidents', name: 'admin-incidents', component: AdminIncidentsView },
|
||
{ path: '/admin/incidents/:id', name: 'admin-incident-detail', component: { template: '<div />' } },
|
||
],
|
||
});
|
||
await router.push('/admin/incidents');
|
||
await router.isReady();
|
||
return { wrapper: mount(AdminIncidentsView, { global: { plugins: [createVuetify(), router] } }), router };
|
||
};
|
||
|
||
describe('AdminIncidentsView.vue', () => {
|
||
it('монтируется и содержит заголовок «Инциденты»', async () => {
|
||
const { wrapper } = await mountView();
|
||
expect(wrapper.text()).toContain('Инциденты');
|
||
});
|
||
|
||
it('содержит 3 stats: Открыто / Расследуется / РКН-уведомлений', async () => {
|
||
const { wrapper } = await mountView();
|
||
const text = wrapper.text();
|
||
expect(text).toContain('Открыто');
|
||
expect(text).toContain('Расследуется');
|
||
expect(text).toContain('РКН-уведомлений');
|
||
});
|
||
|
||
it('содержит фильтр-toggle по статусам (5 значений)', async () => {
|
||
const { wrapper } = await mountView();
|
||
const text = wrapper.text();
|
||
expect(text).toContain('Все');
|
||
expect(text).toContain('Открыты');
|
||
expect(text).toContain('Решены');
|
||
expect(text).toContain('Закрыты');
|
||
});
|
||
|
||
it('показывает PDN-breach с РКН pending chip', async () => {
|
||
const { wrapper } = await mountView();
|
||
const text = wrapper.text();
|
||
expect(text).toContain('Утечка ПДн');
|
||
expect(text).toContain('РКН pending');
|
||
});
|
||
|
||
it('содержит incident_id в формате INC-YYYY-MMDD-NNNN', async () => {
|
||
const { wrapper } = await mountView();
|
||
const text = wrapper.text();
|
||
expect(text).toContain('INC-2026-0507-0034');
|
||
expect(text).toContain('INC-2026-0506-0028');
|
||
});
|
||
|
||
it('клик по строке инцидента вызывает router.push на admin-incident-detail', async () => {
|
||
const { wrapper, router } = await mountView();
|
||
const pushSpy = vi.spyOn(router, 'push');
|
||
// get first row — mock data has id from ADMIN_INCIDENTS[0]
|
||
const vm = wrapper.vm as unknown as { rowsState: Array<{ id: number }> };
|
||
const firstId = vm.rowsState[0].id;
|
||
const row = wrapper.find(`[data-testid="incident-row-${firstId}"]`);
|
||
expect(row.exists()).toBe(true);
|
||
await row.trigger('click');
|
||
expect(pushSpy).toHaveBeenCalledWith({ name: 'admin-incident-detail', params: { id: firstId } });
|
||
});
|
||
});
|