@@ -3,6 +3,7 @@ import React from 'react';
33import Routes from '../../../../../constants/navigation/Routes' ;
44import renderWithProvider from '../../../../../util/test/renderWithProvider' ;
55import { useUnrealizedPnL } from '../../hooks/useUnrealizedPnL' ;
6+ import { usePredictPositions } from '../../hooks/usePredictPositions' ;
67import { PredictPosition , PredictPositionStatus } from '../../types' ;
78import MarketsWonCard from './PredictPositionsHeader' ;
89
@@ -94,14 +95,9 @@ jest.mock('../../hooks/usePredictActionGuard', () => ({
9495} ) ) ;
9596
9697const mockRefetchClaimablePositions = jest . fn ( ) ;
97- jest . mock ( '../../hooks/usePredictPositions' , ( ) => ( {
98- usePredictPositions : ( ) => ( {
99- data : [ { id : 'position-1' } ] ,
100- isLoading : false ,
101- error : null ,
102- refetch : mockRefetchClaimablePositions ,
103- } ) ,
104- } ) ) ;
98+ let mockActivePositions : PredictPosition [ ] = [ ] ;
99+ let mockClaimablePositions : PredictPosition [ ] = [ ] ;
100+ jest . mock ( '../../hooks/usePredictPositions' ) ;
105101
106102const mockClaim = jest . fn ( ) ;
107103jest . mock ( '../../hooks/usePredictClaim' , ( ) => ( {
@@ -127,36 +123,13 @@ jest.mock('../../../../../../locales/i18n', () => ({
127123 } ) ,
128124} ) ) ;
129125
130- function createTestState (
131- _availableBalance ?: number ,
132- claimableAmount ?: number ,
133- privacyMode = false ,
134- ) {
126+ function createTestState ( _availableBalance ?: number , privacyMode = false ) {
135127 const testAddress = '0x1234567890123456789012345678901234567890' ;
136128 const testAccountId = 'test-account-id' ;
137129
138- const claimablePositions = claimableAmount
139- ? ( [
140- {
141- id : 'position-1' ,
142- status : PredictPositionStatus . WON ,
143- cashPnl : claimableAmount ,
144- currentValue : claimableAmount ,
145- marketId : 'market-1' ,
146- title : 'Test Market' ,
147- outcome : 'Yes' ,
148- } ,
149- ] as unknown as PredictPosition [ ] )
150- : [ ] ;
151-
152130 return {
153131 engine : {
154132 backgroundState : {
155- PredictController : {
156- claimablePositions : {
157- [ testAddress ] : claimablePositions ,
158- } ,
159- } ,
160133 AccountsController : {
161134 internalAccounts : {
162135 selectedAccount : testAccountId ,
@@ -185,11 +158,16 @@ describe('MarketsWonCard', () => {
185158 const mockUseUnrealizedPnL = useUnrealizedPnL as jest . MockedFunction <
186159 typeof useUnrealizedPnL
187160 > ;
161+ const mockUsePredictPositions = usePredictPositions as jest . MockedFunction <
162+ typeof usePredictPositions
163+ > ;
188164
189165 beforeEach ( ( ) => {
190166 jest . clearAllMocks ( ) ;
191167 mockBalanceResult . data = 100.5 ;
192168 mockBalanceResult . isLoading = false ;
169+ mockActivePositions = [ { id : 'position-1' } as PredictPosition ] ;
170+ mockClaimablePositions = [ ] ;
193171
194172 mockUseUnrealizedPnL . mockReturnValue ( {
195173 data : {
@@ -201,13 +179,35 @@ describe('MarketsWonCard', () => {
201179 isFetching : false ,
202180 error : null ,
203181 } as unknown as ReturnType < typeof useUnrealizedPnL > ) ;
182+ mockUsePredictPositions . mockImplementation (
183+ ( { claimable } : { claimable ?: boolean } = { } ) =>
184+ ( {
185+ data : claimable ? mockClaimablePositions : mockActivePositions ,
186+ isLoading : false ,
187+ error : null ,
188+ refetch : mockRefetchClaimablePositions ,
189+ } ) as unknown as ReturnType < typeof usePredictPositions > ,
190+ ) ;
204191 } ) ;
205192
206193 afterEach ( ( ) => {
207- jest . resetAllMocks ( ) ;
194+ jest . clearAllMocks ( ) ;
208195 } ) ;
209196
210197 describe ( 'rendering' , ( ) => {
198+ it ( 'does not enable live updates for active position count query' , ( ) => {
199+ const state = createTestState ( 100.5 ) ;
200+
201+ renderWithProvider ( < MarketsWonCard /> , { state } ) ;
202+
203+ const activePositionsCall = mockUsePredictPositions . mock . calls . find (
204+ ( [ options ] ) => options ?. claimable === false ,
205+ ) ;
206+
207+ expect ( activePositionsCall ?. [ 0 ] ) . toMatchObject ( { claimable : false } ) ;
208+ expect ( activePositionsCall ?. [ 0 ] ?. livePriceUpdates ) . toBeUndefined ( ) ;
209+ } ) ;
210+
211211 it ( 'displays available balance and unrealized P&L' , ( ) => {
212212 const state = createTestState ( 100.5 ) ;
213213
@@ -230,15 +230,26 @@ describe('MarketsWonCard', () => {
230230 } ) ;
231231
232232 it ( 'hides monetary values when privacy mode is enabled' , ( ) => {
233- const state = createTestState ( 100.5 , 24.66 , true ) ;
233+ mockClaimablePositions = [
234+ {
235+ id : 'position-1' ,
236+ status : PredictPositionStatus . WON ,
237+ cashPnl : 24.66 ,
238+ currentValue : 24.66 ,
239+ marketId : 'market-1' ,
240+ title : 'Test Market' ,
241+ outcome : 'Yes' ,
242+ } as PredictPosition ,
243+ ] ;
244+ const state = createTestState ( 100.5 , true ) ;
234245
235246 renderWithProvider ( < MarketsWonCard /> , { state } ) ;
236247
237248 expect ( screen . queryByText ( '$100.50' ) ) . toBeNull ( ) ;
238249 expect ( screen . queryByText ( '+$8.63 (+3.9%)' ) ) . toBeNull ( ) ;
239250 expect ( screen . queryByText ( 'Claim $24.66' ) ) . toBeNull ( ) ;
240251 expect ( screen . getByText ( '••••••••••••' ) ) . toBeOnTheScreen ( ) ;
241- expect ( screen . getByText ( '•••••••••' ) ) . toBeOnTheScreen ( ) ;
252+ expect ( screen . getAllByText ( '•••••••••' ) . length ) . toBeGreaterThan ( 0 ) ;
242253 } ) ;
243254 } ) ;
244255
0 commit comments