Files
portal/app/tests/Frontend/DashboardPageHead.spec.ts
T
Дмитрий ba49805689 fix(dashboard): приветствие по реальному имени пользователя + по времени суток
DashboardPageHead показывал захардкоженное «Доброе утро, Иван» любому
пользователю. Теперь имя берётся из auth-store (first_name), а приветствие —
по времени суток (ночь/утро/день/вечер). Fallback «коллега» при отсутствии user.
TDD: DashboardPageHead.spec.ts (RED→GREEN).

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

43 lines
1.6 KiB
TypeScript

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('при отсутствии user приветствие рендерится без падения', () => {
const wrapper = mountHead(null);
expect(wrapper.find('.page-greet').exists()).toBe(true);
expect(wrapper.find('.page-greet').text().length).toBeGreaterThan(0);
});
});