11import { fireEvent , render , screen } from '@testing-library/react'
2- import { useIsMobile } from 'hooks/useIsMobile'
32import { useRouter } from 'next/navigation'
43import React from 'react'
54
65import { ClaimStatusEnum } from 'types/__generated__/graphql'
76import ClaimHighlight from 'components/ClaimHighlight'
87
9- jest . mock ( 'hooks/useIsMobile' , ( ) => ( {
10- useIsMobile : jest . fn ( ( ) => false ) ,
11- } ) )
12-
13- jest . mock ( '@heroui/tooltip' , ( ) => ( {
14- Tooltip : ( { content, children } : { content : React . ReactNode ; children : React . ReactNode } ) => (
15- < >
16- < div data-testid = "tooltip-content" > { content } </ div >
17- { children }
18- </ >
19- ) ,
20- } ) )
21-
228jest . mock ( '@heroui/react' , ( ) => ( {
239 Popover : ( { children } : { children : React . ReactNode } ) => < div > { children } </ div > ,
2410 PopoverTrigger : ( { children } : { children : React . ReactNode } ) => < > { children } </ > ,
@@ -27,7 +13,21 @@ jest.mock('@heroui/react', () => ({
2713 ) ,
2814} ) )
2915
30- const mockUseIsMobile = useIsMobile as jest . Mock
16+ jest . mock ( '@heroui/button' , ( ) => ( {
17+ Button : ( {
18+ children,
19+ onPress,
20+ className,
21+ } : {
22+ children : React . ReactNode
23+ onPress ?: ( ) => void
24+ className ?: string
25+ } ) => (
26+ < button type = "button" onClick = { onPress } className = { className } >
27+ { children }
28+ </ button >
29+ ) ,
30+ } ) )
3131
3232const renderHighlight = ( extra : Record < string , unknown > = { } ) =>
3333 render (
@@ -46,7 +46,6 @@ const renderHighlight = (extra: Record<string, unknown> = {}) =>
4646describe ( 'ClaimHighlight' , ( ) => {
4747 beforeEach ( ( ) => {
4848 jest . clearAllMocks ( )
49- mockUseIsMobile . mockReturnValue ( false )
5049 } )
5150
5251 it ( 'renders a plain span when no claim key is present' , ( ) => {
@@ -59,49 +58,32 @@ describe('ClaimHighlight', () => {
5958 expect ( span ) . not . toBeNull ( )
6059 expect ( span ?. className ) . toBe ( 'foo' )
6160 expect ( span ?. textContent ) . toBe ( 'plain text' )
62- expect ( screen . queryByTestId ( 'tooltip -content' ) ) . not . toBeInTheDocument ( )
61+ expect ( screen . queryByTestId ( 'popover -content' ) ) . not . toBeInTheDocument ( )
6362 } )
6463
65- it ( 'renders desktop tooltip with claim name and status badge' , ( ) => {
64+ it ( 'renders a popover with claim name, status badge, and View claim button ' , ( ) => {
6665 renderHighlight ( )
67- const tooltip = screen . getByTestId ( 'tooltip-content' )
68- expect ( tooltip ) . toHaveTextContent ( 'My Claim' )
69- expect ( tooltip ) . toHaveTextContent ( 'Approved' )
70- expect ( tooltip ) . toHaveTextContent ( 'Click to view' )
71- expect ( screen . getByRole ( 'link' , { name : / C l a i m : M y C l a i m , s t a t u s A p p r o v e d / i } ) ) . toBeVisible ( )
66+ const popover = screen . getByTestId ( 'popover-content' )
67+ expect ( popover ) . toHaveTextContent ( 'My Claim' )
68+ expect ( popover ) . toHaveTextContent ( 'Approved' )
69+ expect ( screen . getByRole ( 'button' , { name : / V i e w c l a i m / i } ) ) . toBeInTheDocument ( )
7270 } )
7371
74- it ( 'navigates on click when in desktop mode ' , ( ) => {
72+ it ( 'navigates when the View claim button is clicked ' , ( ) => {
7573 const push = ( useRouter ( ) as unknown as { push : jest . Mock } ) . push
7674 renderHighlight ( )
77- fireEvent . click ( screen . getByRole ( 'link' ) )
75+ fireEvent . click ( screen . getByRole ( 'button' , { name : / V i e w c l a i m / i } ) )
7876 expect ( push ) . toHaveBeenCalledWith ( '/board/2025/candidates/alice/claims/my-claim' )
7977 } )
8078
81- it ( 'navigates on Enter key press' , ( ) => {
82- const push = ( useRouter ( ) as unknown as { push : jest . Mock } ) . push
83- renderHighlight ( )
84- fireEvent . keyDown ( screen . getByRole ( 'link' ) , { key : 'Enter' } )
85- expect ( push ) . toHaveBeenCalledWith ( '/board/2025/candidates/alice/claims/my-claim' )
86- } )
87-
88- it ( 'navigates on Space key press' , ( ) => {
89- const push = ( useRouter ( ) as unknown as { push : jest . Mock } ) . push
90- renderHighlight ( )
91- fireEvent . keyDown ( screen . getByRole ( 'link' ) , { key : ' ' } )
92- expect ( push ) . toHaveBeenCalledWith ( '/board/2025/candidates/alice/claims/my-claim' )
79+ it ( 'falls back to Draft style when status is unknown' , ( ) => {
80+ renderHighlight ( { 'data-claim-status' : 'MYSTERY' } )
81+ expect ( screen . getByTestId ( 'popover-content' ) ) . toHaveTextContent ( 'Draft' )
9382 } )
9483
95- it ( 'ignores unrelated keys' , ( ) => {
96- const push = ( useRouter ( ) as unknown as { push : jest . Mock } ) . push
84+ it ( 'exposes the claim in the aria-label on the trigger' , ( ) => {
9785 renderHighlight ( )
98- fireEvent . keyDown ( screen . getByRole ( 'link' ) , { key : 'a' } )
99- expect ( push ) . not . toHaveBeenCalled ( )
100- } )
101-
102- it ( 'falls back to Draft style when status is unknown' , ( ) => {
103- renderHighlight ( { 'data-claim-status' : 'MYSTERY' } )
104- expect ( screen . getByTestId ( 'tooltip-content' ) ) . toHaveTextContent ( 'Draft' )
86+ expect ( screen . getByLabelText ( 'Claim: My Claim, status Approved' ) ) . toBeInTheDocument ( )
10587 } )
10688
10789 it ( 'falls back to unnamed in aria-label when name is missing' , ( ) => {
@@ -117,33 +99,4 @@ describe('ClaimHighlight', () => {
11799 )
118100 expect ( screen . getByLabelText ( 'Claim: unnamed, status Draft' ) ) . toBeInTheDocument ( )
119101 } )
120-
121- describe ( 'mobile' , ( ) => {
122- beforeEach ( ( ) => {
123- mockUseIsMobile . mockReturnValue ( true )
124- } )
125-
126- it ( 'renders a popover with a View claim button' , ( ) => {
127- renderHighlight ( )
128- const popover = screen . getByTestId ( 'popover-content' )
129- expect ( popover ) . toHaveTextContent ( 'My Claim' )
130- expect ( popover ) . toHaveTextContent ( 'Approved' )
131- expect ( screen . getByRole ( 'button' , { name : / V i e w c l a i m / i } ) ) . toBeInTheDocument ( )
132- expect ( screen . queryByRole ( 'link' ) ) . not . toBeInTheDocument ( )
133- } )
134-
135- it ( 'navigates when the View claim button is clicked' , ( ) => {
136- const push = ( useRouter ( ) as unknown as { push : jest . Mock } ) . push
137- renderHighlight ( )
138- fireEvent . click ( screen . getByRole ( 'button' , { name : / V i e w c l a i m / i } ) )
139- expect ( push ) . toHaveBeenCalledWith ( '/board/2025/candidates/alice/claims/my-claim' )
140- } )
141-
142- it ( 'does not navigate on click of the highlight trigger' , ( ) => {
143- const push = ( useRouter ( ) as unknown as { push : jest . Mock } ) . push
144- renderHighlight ( )
145- fireEvent . click ( screen . getByRole ( 'button' , { name : / C l a i m : M y C l a i m , s t a t u s A p p r o v e d / i } ) )
146- expect ( push ) . not . toHaveBeenCalled ( )
147- } )
148- } )
149102} )
0 commit comments