ba49805689
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>
43 lines
1.6 KiB
TypeScript
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);
|
|
});
|
|
});
|