Files
hnh-map/frontend-nuxt/components/__tests__/UserAvatar.test.ts
Nikolay Tatarinov 8f769543f4 Refactor frontend components and enhance API integration
- Updated frontend-nuxt.mdc to specify usage of composables for API calls.
- Added new AuthCard and ConfirmModal components for improved UI consistency.
- Introduced UserAvatar component for user profile display, replacing previous Gravatar implementation.
- Implemented useFormSubmit composable for handling form submissions with loading and error states.
- Enhanced vitest.config.ts to include coverage reporting for composables and components.
- Removed deprecated useAdminApi and useAuth composables to streamline API interactions.
- Updated login and setup pages to utilize new components and composables for better user experience.
2026-03-04 00:14:05 +03:00

41 lines
1.3 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'
import UserAvatar from '../UserAvatar.vue'
const useGravatarUrlMock = vi.fn(() => 'https://gravatar.example/avatar')
vi.stubGlobal('useGravatarUrl', useGravatarUrlMock)
describe('UserAvatar', () => {
beforeEach(() => {
useGravatarUrlMock.mockReturnValue('https://gravatar.example/avatar')
})
it('renders fallback initial when no email', () => {
const wrapper = mount(UserAvatar, {
props: { username: 'alice' },
global: {
stubs: { useGravatarUrl: false },
},
})
const fallback = wrapper.find('.bg-primary')
expect(fallback.exists()).toBe(true)
expect(fallback.text()).toBe('A')
})
it('renders fallback initial for username', () => {
const wrapper = mount(UserAvatar, {
props: { username: 'bob' },
})
expect(wrapper.find('.bg-primary').text()).toBe('B')
})
it('uses size for style', () => {
const wrapper = mount(UserAvatar, {
props: { username: 'x', size: 40 },
})
const div = wrapper.find('.rounded-full')
expect(div.attributes('style')).toContain('width: 40px')
expect(div.attributes('style')).toContain('height: 40px')
})
})