11import React from 'react' ;
2- import { render , screen } from '@testing-library/react' ;
2+ import { act , render , screen } from '@testing-library/react' ;
33import ReactModal from 'react-modal' ;
44import { IntroQuestModal } from './IntroQuestModal' ;
5+ import { QUEST_CLAIMED_STAMP_REVEAL_DELAY_MS } from '../quest/QuestCard' ;
56import { ActionType } from '../../graphql/actions' ;
67import { useActions , useViewSize } from '../../hooks' ;
78import { useQuestDashboard } from '../../hooks/useQuestDashboard' ;
9+ import { useClaimQuestReward } from '../../hooks/useClaimQuestReward' ;
810import {
911 QuestRewardType ,
1012 QuestStatus ,
@@ -14,10 +16,24 @@ import {
1416
1517ReactModal . setAppElement ( 'body' ) ;
1618
19+ jest . mock ( 'next/router' , ( ) => ( {
20+ useRouter : ( ) => ( {
21+ push : jest . fn ( ) ,
22+ } ) ,
23+ } ) ) ;
24+
1725jest . mock ( '../../hooks/useQuestDashboard' , ( ) => ( {
1826 useQuestDashboard : jest . fn ( ) ,
1927} ) ) ;
2028
29+ jest . mock ( '../../hooks/useClaimQuestReward' , ( ) => ( {
30+ useClaimQuestReward : jest . fn ( ) ,
31+ } ) ) ;
32+
33+ jest . mock ( '../tooltip/Tooltip' , ( ) => ( {
34+ Tooltip : ( { children } : { children : React . ReactNode } ) => children ,
35+ } ) ) ;
36+
2137jest . mock ( '../../hooks' , ( ) => ( {
2238 ViewSize : {
2339 MobileL : 'mobileL' ,
@@ -29,6 +45,7 @@ jest.mock('../../hooks', () => ({
2945const mockUseActions = useActions as jest . Mock ;
3046const mockUseViewSize = useViewSize as jest . Mock ;
3147const mockUseQuestDashboard = useQuestDashboard as jest . Mock ;
48+ const mockUseClaimQuestReward = useClaimQuestReward as jest . Mock ;
3249const completeAction = jest . fn ( ) ;
3350
3451const buildIntroQuest = ( overrides : Partial < UserQuest > = { } ) : UserQuest => ( {
@@ -62,6 +79,11 @@ describe('IntroQuestModal', () => {
6279 completeAction,
6380 } ) ;
6481 mockUseViewSize . mockReturnValue ( false ) ;
82+ mockUseClaimQuestReward . mockReturnValue ( {
83+ mutate : jest . fn ( ) ,
84+ isPending : false ,
85+ variables : undefined ,
86+ } ) ;
6587 } ) ;
6688
6789 afterEach ( ( ) => {
@@ -109,14 +131,14 @@ describe('IntroQuestModal', () => {
109131 expect ( screen . getByText ( 'Completed' ) ) . toBeInTheDocument ( ) ;
110132 expect ( screen . getByText ( 'In progress' ) ) . toBeInTheDocument ( ) ;
111133 expect (
112- screen . getByRole ( 'link ' , {
134+ screen . getByRole ( 'button ' , {
113135 name : 'Go to Notifications' ,
114136 hidden : true ,
115137 } ) ,
116- ) . toHaveAttribute ( 'href' , '/settings/notifications' ) ;
138+ ) . toBeInTheDocument ( ) ;
117139 } ) ;
118140
119- it ( 'does not render destination link for completed quests' , ( ) => {
141+ it ( 'does not render destination button for completed quests' , ( ) => {
120142 mockUseQuestDashboard . mockReturnValue ( {
121143 data : {
122144 intro : [
@@ -141,13 +163,53 @@ describe('IntroQuestModal', () => {
141163 render ( < IntroQuestModal isOpen onRequestClose = { jest . fn ( ) } /> ) ;
142164
143165 expect (
144- screen . queryByRole ( 'link ' , {
166+ screen . queryByRole ( 'button ' , {
145167 name : 'Go to Notifications' ,
146168 hidden : true ,
147169 } ) ,
148170 ) . not . toBeInTheDocument ( ) ;
149171 } ) ;
150172
173+ it ( 'shows the claim button and claimed stamp for claimable intro quests' , async ( ) => {
174+ jest . useFakeTimers ( ) ;
175+ const mutate = jest . fn ( ( _variables , callbacks ) => callbacks ?. onSuccess ?.( ) ) ;
176+ mockUseClaimQuestReward . mockReturnValue ( {
177+ mutate,
178+ isPending : false ,
179+ variables : undefined ,
180+ } ) ;
181+ mockUseQuestDashboard . mockReturnValue ( {
182+ data : {
183+ intro : [
184+ buildIntroQuest ( {
185+ status : QuestStatus . Completed ,
186+ progress : 1 ,
187+ claimable : true ,
188+ } ) ,
189+ ] ,
190+ } ,
191+ isPending : false ,
192+ isError : false ,
193+ } ) ;
194+
195+ render ( < IntroQuestModal isOpen onRequestClose = { jest . fn ( ) } /> ) ;
196+
197+ act ( ( ) => {
198+ screen . getByRole ( 'button' , { name : 'Claim' , hidden : true } ) . click ( ) ;
199+ } ) ;
200+
201+ expect ( mutate ) . toHaveBeenCalled ( ) ;
202+ expect ( screen . queryByText ( 'CLAIMED' ) ) . not . toBeInTheDocument ( ) ;
203+
204+ act ( ( ) => {
205+ jest . advanceTimersByTime ( QUEST_CLAIMED_STAMP_REVEAL_DELAY_MS ) ;
206+ } ) ;
207+
208+ expect ( screen . getByText ( 'CLAIMED' ) ) . toBeInTheDocument ( ) ;
209+
210+ jest . useRealTimers ( ) ;
211+ } ) ;
212+
151213 it ( 'shows a loading message while pending' , ( ) => {
152214 mockUseQuestDashboard . mockReturnValue ( {
153215 data : undefined ,
0 commit comments