@@ -30,6 +30,7 @@ import { descriptionListAssertion } from '@/tests/assertions/description-list-as
3030import { tableAssertion } from '@/tests/assertions/table-assertion'
3131import { modelsv2 , indexerModels } from 'algosdk'
3232import { transactionResultMother } from '@/tests/object-mother/transaction-result'
33+ import { refreshButtonLabel } from '@/features/common/components/refresh-button'
3334
3435describe ( 'application-page' , ( ) => {
3536 describe ( 'when rendering an application using an invalid application Id' , ( ) => {
@@ -218,4 +219,90 @@ describe('application-page', () => {
218219 )
219220 } )
220221 } )
222+
223+ describe ( 'when rendering an application that becomes stale' , ( ) => {
224+ const applicationResult = applicationResultMother [ 'mainnet-80441968' ] ( ) . build ( )
225+
226+ it ( 'should be rendered with the refresh button' , ( ) => {
227+ const myStore = createStore ( )
228+ myStore . set ( applicationResultsAtom , new Map ( [ [ applicationResult . id , atom ( applicationResult ) ] ] ) )
229+
230+ vi . mocked ( useParams ) . mockImplementation ( ( ) => ( { applicationId : applicationResult . id . toString ( ) } ) )
231+ vi . mocked ( indexer . searchForApplicationBoxes ( 0 ) . nextToken ( '' ) . limit ( 10 ) . do ) . mockImplementation ( ( ) =>
232+ Promise . resolve (
233+ new indexerModels . BoxesResponse ( {
234+ applicationId : 80441968 ,
235+ boxes : [
236+ new modelsv2 . BoxDescriptor ( {
237+ name : 'AAAAAAAAAAAAAAAAABhjNpJEU5krRanhldfCDWa2Rs8=' ,
238+ } ) ,
239+ new modelsv2 . BoxDescriptor ( {
240+ name : 'AAAAAAAAAAAAAAAAAB3fFPhSWjPaBhjzsx3NbXvlBK4=' ,
241+ } ) ,
242+ new modelsv2 . BoxDescriptor ( {
243+ name : 'AAAAAAAAAAAAAAAAACctz98iaZ1MeSEbj+XCnD5CCwQ=' ,
244+ } ) ,
245+ new modelsv2 . BoxDescriptor ( {
246+ name : 'AAAAAAAAAAAAAAAAACh7tCy49kQrUL7ykRWDmayeLKk=' ,
247+ } ) ,
248+ new modelsv2 . BoxDescriptor ( {
249+ name : 'AAAAAAAAAAAAAAAAAECfyDmi7C5tEjBUI9N80BEnnAk=' ,
250+ } ) ,
251+ new modelsv2 . BoxDescriptor ( {
252+ name : 'AAAAAAAAAAAAAAAAAEKTl0iZ2Q9UxPJphTgwplTfk6U=' ,
253+ } ) ,
254+ new modelsv2 . BoxDescriptor ( {
255+ name : 'AAAAAAAAAAAAAAAAAEO4cIhnhmQ0qdQDLoXi7q0+G7o=' ,
256+ } ) ,
257+ new modelsv2 . BoxDescriptor ( {
258+ name : 'AAAAAAAAAAAAAAAAAEVLZkp/l5eUQJZ/QEYYy9yNtuc=' ,
259+ } ) ,
260+ new modelsv2 . BoxDescriptor ( {
261+ name : 'AAAAAAAAAAAAAAAAAEkbM2/K1+8IrJ/jdkgEoF/O5k0=' ,
262+ } ) ,
263+ new modelsv2 . BoxDescriptor ( {
264+ name : 'AAAAAAAAAAAAAAAAAFwILIUnvVR4R/Xe9jTEV2SzTck=' ,
265+ } ) ,
266+ ] ,
267+ nextToken : 'b64:AAAAAAAAAAAAAAAAAFwILIUnvVR4R/Xe9jTEV2SzTck=' ,
268+ } )
269+ )
270+ )
271+ vi . mocked ( indexer . searchForTransactions ( ) . applicationID ( applicationResult . id ) . limit ( 3 ) . do ) . mockImplementation ( ( ) =>
272+ Promise . resolve ( { currentRound : 123 , transactions : [ ] , nextToken : '' } )
273+ )
274+
275+ return executeComponentTest (
276+ ( ) => {
277+ return render ( < ApplicationPage /> , undefined , myStore )
278+ } ,
279+ async ( component ) => {
280+ await waitFor ( async ( ) => {
281+ const detailsCard = component . getByLabelText ( applicationDetailsLabel )
282+ descriptionListAssertion ( {
283+ container : detailsCard ,
284+ items : [ { term : applicationIdLabel , description : '80441968' } ] ,
285+ } )
286+
287+ const refreshButton = component . queryByLabelText ( refreshButtonLabel )
288+ expect ( refreshButton ) . toBeFalsy ( )
289+ } )
290+
291+ // Simulate the application being evicted from the store, due to staleness
292+ myStore . set ( applicationResultsAtom , new Map ( ) )
293+
294+ await waitFor ( async ( ) => {
295+ const detailsCard = component . getByLabelText ( applicationDetailsLabel )
296+ descriptionListAssertion ( {
297+ container : detailsCard ,
298+ items : [ { term : applicationIdLabel , description : '80441968' } ] ,
299+ } )
300+
301+ const refreshButton = component . getByLabelText ( refreshButtonLabel )
302+ expect ( refreshButton ) . toBeTruthy ( )
303+ } )
304+ }
305+ )
306+ } )
307+ } )
221308} )
0 commit comments