|
| 1 | +import { render, screen } from '@testing-library/react'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | +import CreatorInitialsAvatar from '@/components/common/CreatorInitialsAvatar'; |
| 4 | +import { getFallbackAvatarColors } from '@/utils/avatarColor.util'; |
| 5 | + |
| 6 | +describe('CreatorInitialsAvatar', () => { |
| 7 | + it('uses deterministic fallback colors for the same creator id', () => { |
| 8 | + const first = getFallbackAvatarColors('creator-123'); |
| 9 | + const second = getFallbackAvatarColors('creator-123'); |
| 10 | + const third = getFallbackAvatarColors('creator-456'); |
| 11 | + |
| 12 | + expect(first).toEqual(second); |
| 13 | + expect(first.background).not.toBe(third.background); |
| 14 | + expect(first.textColor).toBe('rgba(255, 255, 255, 0.95)'); |
| 15 | + }); |
| 16 | + |
| 17 | + it('renders initials fallback with hashed background when image is missing', () => { |
| 18 | + render(<CreatorInitialsAvatar name="Alex Rivers" creatorId="creator-123" />); |
| 19 | + |
| 20 | + const initials = screen.getByLabelText('Alex Rivers initials avatar'); |
| 21 | + const avatar = initials.parentElement; |
| 22 | + const colors = getFallbackAvatarColors('creator-123'); |
| 23 | + |
| 24 | + expect(initials).toHaveTextContent('AR'); |
| 25 | + expect(avatar).toHaveStyle({ |
| 26 | + background: colors.background, |
| 27 | + color: colors.textColor, |
| 28 | + }); |
| 29 | + }); |
| 30 | +}); |
0 commit comments