Files
portal/app/tests/Frontend/DashboardPageHead.spec.ts
T
Дмитрий 34e55a9c7e fix/dashboard: нейтральное приветствие без коллега когда имя не задано U2
Без имени дашборд звал коллега — звучит как к чужому. Теперь Доброе утро! без обращения;
имя клиент задаёт в Настройки Профиль. U6 автопополнение уже имел тултип-пояснение.
Тест DashboardPageHead 6/6.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 12:28:38 +03:00

92 lines
3.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import { createPinia, setActivePinia } from 'pinia';
import { createVuetify } from 'vuetify';
import DashboardPageHead from '../../resources/js/components/dashboard/DashboardPageHead.vue';
import { useAuthStore } from '../../resources/js/stores/auth';
import type { AuthUser } from '../../resources/js/api/auth';
const mockUser: AuthUser = {
id: 1,
email: 'petr.sidorov@example.ru',
first_name: 'Пётр',
last_name: 'Сидоров',
tenant_id: 1,
totp_enabled: false,
last_login_at: null,
};
const mountHead = (user: AuthUser | null = mockUser) => {
setActivePinia(createPinia());
useAuthStore().user = user;
return mount(DashboardPageHead, {
props: { modelValue: 'today' },
global: { plugins: [createVuetify()] },
});
};
describe('DashboardPageHead.vue', () => {
it('приветствие использует имя залогиненного пользователя, не захардкоженное «Иван»', () => {
const wrapper = mountHead();
const greet = wrapper.find('.page-greet').text();
expect(greet).toContain('Пётр');
expect(greet).not.toContain('Иван');
});
it('без имени приветствие нейтральное, без «коллега» (U2)', () => {
const wrapper = mountHead(null);
const greet = wrapper.find('.page-greet').text();
expect(greet.length).toBeGreaterThan(0);
expect(greet).not.toContain('коллега');
expect(greet).toContain('!'); // «Доброе утро!» — без обращения к чужому
});
// F5: meta-строка раньше была захардкоженной «рыбой» (+3 / 11 / 38 / 2 248 ₽).
// Теперь числа приходят пропами из реальных данных дашборда.
const mountMeta = (props: Record<string, unknown>) => {
setActivePinia(createPinia());
useAuthStore().user = mockUser;
return mount(DashboardPageHead, {
props: { modelValue: 'today', ...props },
global: { plugins: [createVuetify()] },
});
};
it('сегодня/вчера — настоящие из пропов, не захардкоженные 11/38', () => {
const meta = mountMeta({ leadsToday: 7, leadsYesterday: 12, avgLeadCostRub: 500 })
.find('.page-meta')
.text();
expect(meta).toContain('сегодня 7');
expect(meta).toContain('вчера 12');
expect(meta).not.toContain('сегодня 11');
expect(meta).not.toContain('вчера 38');
});
it('средняя стоимость — настоящая из пропа, не захардкоженные 2 248', () => {
const meta = mountMeta({ leadsToday: 7, leadsYesterday: 12, avgLeadCostRub: 500 })
.find('.page-meta')
.text();
expect(meta).toContain('средняя стоимость');
expect(meta).toContain('500');
expect(meta).not.toContain('2 248');
});
it('средняя стоимость = «—» когда avgLeadCostRub null', () => {
const meta = mountMeta({ leadsToday: 0, leadsYesterday: 0, avgLeadCostRub: null })
.find('.page-meta')
.text();
expect(meta).toContain('средняя стоимость');
expect(meta).toContain('—');
expect(meta).not.toContain('2 248');
});
it('строка больше не содержит выдуманное «+3 … с утра»', () => {
const meta = mountMeta({ leadsToday: 7, leadsYesterday: 12, avgLeadCostRub: 500 })
.find('.page-meta')
.text();
expect(meta).not.toContain('с утра');
expect(meta).not.toContain('+3');
});
});