- 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.
41 lines
1.3 KiB
TypeScript
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')
|
|
})
|
|
})
|