@@ -8,16 +8,6 @@ jest.mock('@configs/firebase', () => ({
88 logAnalyticsEvent : jest . fn ( ) ,
99} ) ) ;
1010
11- // Mock the aaaahhhh helper
12- jest . mock ( '@helpers/aaaahhhh' , ( ) => ( {
13- aaaahhhh : jest . fn ( ) ,
14- } ) ) ;
15-
16- // Mock lodash debounce
17- jest . mock ( 'lodash' , ( ) => ( {
18- debounce : jest . fn ( ( fn ) => fn ) ,
19- } ) ) ;
20-
2111// Mock Next.js Image component to capture the original src prop
2212jest . mock ( 'next/image' , ( ) => {
2313 const MockImage = React . forwardRef < HTMLImageElement , any > (
@@ -63,81 +53,41 @@ describe('Avatar', () => {
6353 expect ( avatar ) . toHaveAttribute ( 'src' , '/images/drawn/profile_pic_drawn.webp' ) ;
6454 } ) ;
6555
66- it ( 'should start sneeze animation on every 5th hover' , async ( ) => {
67- const { logAnalyticsEvent } = jest . requireMock ( '@configs/firebase' ) ;
56+ it ( 'should handle click events' , ( ) => {
6857 render ( < Avatar /> ) ;
6958
7059 const avatar = screen . getByTestId ( 'profile_pic' ) ;
7160
72- // Hover 4 times - no sneeze
73- for ( let i = 0 ; i < 4 ; i ++ ) {
74- fireEvent . mouseEnter ( avatar ) ;
75- }
76-
77- // 5th hover should trigger sneeze
78- fireEvent . mouseEnter ( avatar ) ;
79-
80- act ( ( ) => {
81- jest . advanceTimersByTime ( 500 ) ;
82- } ) ;
83-
84- act ( ( ) => {
85- jest . advanceTimersByTime ( 300 ) ;
86- } ) ;
87-
88- act ( ( ) => {
89- jest . advanceTimersByTime ( 1000 ) ;
90- } ) ;
91-
92- expect ( logAnalyticsEvent ) . toHaveBeenCalledWith ( 'trigger_sneeze' , {
93- name : 'trigger_sneeze' ,
94- type : 'hover' ,
95- } ) ;
61+ expect ( ( ) => fireEvent . click ( avatar ) ) . not . toThrow ( ) ;
9662 } ) ;
9763
98- it ( 'should trigger aaaahhhh effect on 6th sneeze' , async ( ) => {
99- const { logAnalyticsEvent } = jest . requireMock ( '@configs/firebase' ) ;
100- const { aaaahhhh } = jest . requireMock ( '@helpers/aaaahhhh' ) ;
101-
64+ it ( 'should have proper styling' , ( ) => {
10265 render ( < Avatar /> ) ;
10366
10467 const avatar = screen . getByTestId ( 'profile_pic' ) ;
10568
106- // Trigger sneezes 6 times (5 hovers each = 30 hovers total)
107- for ( let sneeze = 0 ; sneeze < 6 ; sneeze ++ ) {
108- for ( let hover = 0 ; hover < 5 ; hover ++ ) {
109- fireEvent . mouseEnter ( avatar ) ;
110- }
111-
112- if ( sneeze < 5 ) {
113- act ( ( ) => {
114- jest . advanceTimersByTime ( 2000 ) ; // Allow sneeze animation to complete
115- } ) ;
116- }
117- }
118-
119- expect ( logAnalyticsEvent ) . toHaveBeenCalledWith ( 'trigger_aaaahhhh' , {
120- name : 'trigger_aaaahhhh' ,
121- type : 'hover' ,
69+ expect ( avatar ) . toHaveStyle ( {
70+ borderRadius : '50%' ,
12271 } ) ;
123- expect ( aaaahhhh ) . toHaveBeenCalled ( ) ;
12472 } ) ;
12573
126- it ( 'should handle click events ' , ( ) => {
74+ it ( 'should be accessible by keyboard (tab/focus/enter) ' , ( ) => {
12775 render ( < Avatar /> ) ;
128-
12976 const avatar = screen . getByTestId ( 'profile_pic' ) ;
130-
131- expect ( ( ) => fireEvent . click ( avatar ) ) . not . toThrow ( ) ;
77+ avatar . tabIndex = 0 ;
78+ avatar . focus ( ) ;
79+ expect ( document . activeElement ) . toBe ( avatar ) ;
80+ fireEvent . keyDown ( avatar , { key : 'Enter' , code : 'Enter' } ) ;
81+ // Should not throw and should remain accessible
82+ expect ( avatar ) . toBeInTheDocument ( ) ;
13283 } ) ;
13384
134- it ( 'should have proper styling ' , ( ) => {
85+ it ( 'should handle image error gracefully ' , ( ) => {
13586 render ( < Avatar /> ) ;
136-
13787 const avatar = screen . getByTestId ( 'profile_pic' ) ;
138-
139- expect ( avatar ) . toHaveStyle ( {
140- borderRadius : '50%' ,
141- } ) ;
88+ // Simulate image error event
89+ fireEvent . error ( avatar ) ;
90+ // Should still be in the document
91+ expect ( avatar ) . toBeInTheDocument ( ) ;
14292 } ) ;
14393} ) ;
0 commit comments