diff --git a/src/components/common/CreatorProfileHeader.tsx b/src/components/common/CreatorProfileHeader.tsx index 886795c..6bbf0cd 100644 --- a/src/components/common/CreatorProfileHeader.tsx +++ b/src/components/common/CreatorProfileHeader.tsx @@ -148,4 +148,4 @@ const CreatorProfileHeader: React.FC = ({ ); }; -export default CreatorProfileHeader; +export default CreatorProfileHeader; \ No newline at end of file diff --git a/src/components/common/__tests__/CreatorInitialsAvatar.test.tsx b/src/components/common/__tests__/CreatorInitialsAvatar.test.tsx index 5157bd8..98fedf7 100644 --- a/src/components/common/__tests__/CreatorInitialsAvatar.test.tsx +++ b/src/components/common/__tests__/CreatorInitialsAvatar.test.tsx @@ -17,11 +17,10 @@ describe('CreatorInitialsAvatar', () => { it('renders initials fallback with hashed background when image is missing', () => { render(); - const initials = screen.getByLabelText('Alex Rivers initials avatar'); - const avatar = initials.parentElement; + const avatar = screen.getByRole('img', { name: 'Alex Rivers avatar' }); const colors = getFallbackAvatarColors('creator-123'); - expect(initials).toHaveTextContent('AR'); + expect(avatar).toHaveTextContent('AR'); expect(avatar).toHaveStyle({ background: colors.background, color: colors.textColor, diff --git a/src/components/common/__tests__/CreatorProfileHeader.test.tsx b/src/components/common/__tests__/CreatorProfileHeader.test.tsx new file mode 100644 index 0000000..186cd75 --- /dev/null +++ b/src/components/common/__tests__/CreatorProfileHeader.test.tsx @@ -0,0 +1,34 @@ +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { describe, expect, it } from 'vitest'; + +import CreatorProfileHeader from '@/components/common/CreatorProfileHeader'; + +describe('CreatorProfileHeader', () => { + it('closes the profile image lightbox with Escape and returns focus to the trigger', async () => { + render( + + ); + + const avatarTrigger = screen.getByRole('button', { + name: 'Open Alex Rivers profile image', + }); + + fireEvent.click(avatarTrigger); + + expect( + screen.getByRole('dialog', { name: 'Alex Rivers profile image' }) + ).toBeInTheDocument(); + + fireEvent.keyDown(screen.getByRole('dialog'), { key: 'Escape' }); + + await waitFor(() => { + expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); + }); + expect(avatarTrigger).toHaveFocus(); + }); +});