@@ -2,23 +2,21 @@ import { BaseInstructionCard } from '@components/common/BaseInstructionCard';
22import { intoTransactionInstructionFromVersionedMessage } from '@components/inspector/utils' ;
33import { ComputeBudgetProgram , MessageCompiledInstruction } from '@solana/web3.js' ;
44import { render , screen } from '@testing-library/react' ;
5- import { useSearchParams } from 'next/navigation' ;
65
6+ import * as stubs from '@/app/__tests__/mock-stubs' ;
7+ import * as mock from '@/app/__tests__/mocks' ;
78import { ClusterProvider } from '@/app/providers/cluster' ;
89import { ScrollAnchorProvider } from '@/app/providers/scroll-anchor' ;
910
10- import * as mock from '../../inspector/__tests__/mocks' ;
1111import { ComputeBudgetDetailsCard } from '../ComputeBudgetDetailsCard' ;
1212
1313jest . mock ( 'next/navigation' ) ;
14- // @ts -expect-error does not contain `mockReturnValue`
15- useSearchParams . mockReturnValue ( {
16- get : ( ) => 'devnet' ,
17- has : ( _query ?: string ) => false ,
18- toString : ( ) => '' ,
19- } ) ;
2014
21- describe ( 'ComputeBudgetDetailsCard' , ( ) => {
15+ describe ( 'instruction::ComputeBudgetDetailsCard' , ( ) => {
16+ beforeEach ( ( ) => {
17+ mock . mockUseSearchParams ( ) ;
18+ } ) ;
19+
2220 afterEach ( ( ) => {
2321 jest . clearAllMocks ( ) ;
2422 } ) ;
@@ -30,30 +28,25 @@ describe('ComputeBudgetDetailsCard', () => {
3028 programIdIndex : 6 ,
3129 } ;
3230
33- const ti = intoTransactionInstructionFromVersionedMessage (
34- compiledInstruction ,
35- mock . deserialize ( mock . message1 ) ,
36- ComputeBudgetProgram . programId
37- ) ;
38- expect ( ti ) . not . toBeUndefined ( ) ;
39- expect ( ti ?. programId ) . toBe ( ComputeBudgetProgram . programId ) ;
31+ const index = 0 ;
32+ const m = mock . deserializeMessageV0 ( stubs . computeBudgetMsg ) ;
33+ const ti = intoTransactionInstructionFromVersionedMessage ( compiledInstruction , m ) ;
34+ expect ( ti . programId . equals ( ComputeBudgetProgram . programId ) ) . toBeTruthy ( ) ;
4035
4136 // check that component is rendered properly
42- ti &&
43- render (
44- < ScrollAnchorProvider >
45- < ClusterProvider >
46- < ComputeBudgetDetailsCard
47- key = { 1 }
48- ix = { ti }
49- index = { 1 }
50- result = { { err : null } }
51- signature = { '' }
52- InstructionCardComponent = { BaseInstructionCard }
53- />
54- </ ClusterProvider >
55- </ ScrollAnchorProvider >
56- ) ;
37+ render (
38+ < ScrollAnchorProvider >
39+ < ClusterProvider >
40+ < ComputeBudgetDetailsCard
41+ ix = { ti }
42+ index = { index }
43+ result = { { err : null } }
44+ signature = { '' }
45+ InstructionCardComponent = { BaseInstructionCard }
46+ />
47+ </ ClusterProvider >
48+ </ ScrollAnchorProvider >
49+ ) ;
5750 expect ( screen . getByText ( / 7 .1 8 7 8 1 2 l a m p o r t s p e r c o m p u t e u n i t / ) ) . toBeInTheDocument ( ) ;
5851 } ) ;
5952
@@ -64,30 +57,25 @@ describe('ComputeBudgetDetailsCard', () => {
6457 programIdIndex : 6 ,
6558 } ;
6659
67- const ti = intoTransactionInstructionFromVersionedMessage (
68- compiledInstruction ,
69- mock . deserialize ( mock . message1 ) ,
70- ComputeBudgetProgram . programId
71- ) ;
72- expect ( ti ) . not . toBeUndefined ( ) ;
73- expect ( ti ?. programId ) . toBe ( ComputeBudgetProgram . programId ) ;
60+ const index = 1 ;
61+ const m = mock . deserializeMessageV0 ( stubs . computeBudgetMsg ) ;
62+ const ti = intoTransactionInstructionFromVersionedMessage ( compiledInstruction , m ) ;
63+ expect ( ti . programId . equals ( ComputeBudgetProgram . programId ) ) . toBeTruthy ( ) ;
7464
7565 // check that component is rendered properly
76- ti &&
77- render (
78- < ScrollAnchorProvider >
79- < ClusterProvider >
80- < ComputeBudgetDetailsCard
81- key = { 1 }
82- ix = { ti }
83- index = { 1 }
84- result = { { err : null } }
85- signature = { '' }
86- InstructionCardComponent = { BaseInstructionCard }
87- />
88- </ ClusterProvider >
89- </ ScrollAnchorProvider >
90- ) ;
66+ render (
67+ < ScrollAnchorProvider >
68+ < ClusterProvider >
69+ < ComputeBudgetDetailsCard
70+ ix = { ti }
71+ index = { index }
72+ result = { { err : null } }
73+ signature = { '' }
74+ InstructionCardComponent = { BaseInstructionCard }
75+ />
76+ </ ClusterProvider >
77+ </ ScrollAnchorProvider >
78+ ) ;
9179 expect ( screen . getByText ( / 1 5 5 .6 6 6 c o m p u t e u n i t s / ) ) . toBeInTheDocument ( ) ;
9280 } ) ;
9381} ) ;
0 commit comments