@@ -3,12 +3,12 @@ import { render, screen, waitFor } from '@testing-library/react'
33import { QueryClient , QueryClientProvider } from '@tanstack/react-query'
44import { PartyHeader } from './party-header'
55
6- const mockGetParticipant = vi . fn ( )
6+ const mockRetrieveParty = vi . fn ( )
77
88vi . mock ( '@/api/context' , ( ) => ( {
99 useClients : vi . fn ( ( ) => ( {
1010 party : {
11- getParticipant : mockGetParticipant ,
11+ retrieveParty : mockRetrieveParty ,
1212 } ,
1313 } ) ) ,
1414} ) )
@@ -33,12 +33,11 @@ function renderPartyHeader(partyId = 'test-party-1') {
3333describe ( 'PartyHeader - loading state' , ( ) => {
3434 beforeEach ( ( ) => {
3535 vi . clearAllMocks ( )
36- mockGetParticipant . mockReturnValue ( new Promise ( ( ) => { } ) ) // never resolves
36+ mockRetrieveParty . mockReturnValue ( new Promise ( ( ) => { } ) ) // never resolves
3737 } )
3838
3939 it ( 'renders skeleton placeholders while loading' , ( ) => {
4040 renderPartyHeader ( )
41- // Skeletons are rendered during loading - check for loading container
4241 const container = document . querySelector ( '.space-y-4' )
4342 expect ( container ) . toBeInTheDocument ( )
4443 } )
@@ -52,183 +51,77 @@ describe('PartyHeader - loading state', () => {
5251describe ( 'PartyHeader - error/not found state' , ( ) => {
5352 beforeEach ( ( ) => {
5453 vi . clearAllMocks ( )
55- mockGetParticipant . mockResolvedValue ( undefined )
54+ mockRetrieveParty . mockResolvedValue ( { party : undefined } )
5655 } )
5756
5857 it ( 'shows "Party not found" when party data is undefined' , async ( ) => {
5958 renderPartyHeader ( )
60-
6159 await waitFor ( ( ) => {
6260 expect ( screen . getByText ( 'Party not found' ) ) . toBeInTheDocument ( )
6361 } )
6462 } )
6563} )
6664
67- describe ( 'PartyHeader - INDIVIDUAL party type ' , ( ) => {
65+ describe ( 'PartyHeader - PARTY_TYPE_PERSON ' , ( ) => {
6866 beforeEach ( ( ) => {
6967 vi . clearAllMocks ( )
70- mockGetParticipant . mockResolvedValue ( {
71- partyId : 'indv-001' ,
72- name : 'Jane Smith' ,
73- partyType : 'INDIVIDUAL' ,
74- status : 'ACTIVE' ,
68+ mockRetrieveParty . mockResolvedValue ( {
69+ party : {
70+ partyId : 'indv-001' ,
71+ legalName : 'Jane Smith' ,
72+ partyType : 'PARTY_TYPE_PERSON' ,
73+ status : 'PARTY_STATUS_ACTIVE' ,
74+ } ,
7575 } )
7676 } )
7777
78- it ( 'renders party name' , async ( ) => {
78+ it ( 'renders party legal name' , async ( ) => {
7979 renderPartyHeader ( 'indv-001' )
8080 await waitFor ( ( ) => {
8181 expect ( screen . getByText ( 'Jane Smith' ) ) . toBeInTheDocument ( )
8282 } )
8383 } )
8484
85- it ( 'renders INDIVIDUAL party type label' , async ( ) => {
85+ it ( 'renders party type label' , async ( ) => {
8686 renderPartyHeader ( 'indv-001' )
8787 await waitFor ( ( ) => {
88- expect ( screen . getByText ( 'INDIVIDUAL ' ) ) . toBeInTheDocument ( )
88+ expect ( screen . getByText ( 'PARTY_TYPE_PERSON ' ) ) . toBeInTheDocument ( )
8989 } )
9090 } )
9191
92- it ( 'renders ACTIVE status badge' , async ( ) => {
92+ it ( 'renders status badge' , async ( ) => {
9393 renderPartyHeader ( 'indv-001' )
9494 await waitFor ( ( ) => {
95- expect ( screen . getByText ( ' ACTIVE' ) ) . toBeInTheDocument ( )
95+ expect ( screen . getByText ( / A C T I V E / ) ) . toBeInTheDocument ( )
9696 } )
9797 } )
9898} )
9999
100- describe ( 'PartyHeader - ORGANIZATION party type ' , ( ) => {
100+ describe ( 'PartyHeader - PARTY_TYPE_ORGANIZATION ' , ( ) => {
101101 beforeEach ( ( ) => {
102102 vi . clearAllMocks ( )
103- mockGetParticipant . mockResolvedValue ( {
104- partyId : 'org-001' ,
105- name : 'Acme Corp' ,
106- partyType : 'ORGANIZATION' ,
107- status : 'INACTIVE' ,
103+ mockRetrieveParty . mockResolvedValue ( {
104+ party : {
105+ partyId : 'org-001' ,
106+ legalName : 'Acme Corp' ,
107+ partyType : 'PARTY_TYPE_ORGANIZATION' ,
108+ status : 'PARTY_STATUS_RESTRICTED' ,
109+ } ,
108110 } )
109111 } )
110112
111- it ( 'renders party name' , async ( ) => {
113+ it ( 'renders party legal name' , async ( ) => {
112114 renderPartyHeader ( 'org-001' )
113115 await waitFor ( ( ) => {
114116 expect ( screen . getByText ( 'Acme Corp' ) ) . toBeInTheDocument ( )
115117 } )
116118 } )
117119
118- it ( 'renders ORGANIZATION party type label' , async ( ) => {
120+ it ( 'renders party type label' , async ( ) => {
119121 renderPartyHeader ( 'org-001' )
120122 await waitFor ( ( ) => {
121- expect ( screen . getByText ( 'ORGANIZATION' ) ) . toBeInTheDocument ( )
122- } )
123- } )
124-
125- it ( 'renders INACTIVE status badge' , async ( ) => {
126- renderPartyHeader ( 'org-001' )
127- await waitFor ( ( ) => {
128- expect ( screen . getByText ( 'INACTIVE' ) ) . toBeInTheDocument ( )
129- } )
130- } )
131- } )
132-
133- describe ( 'PartyHeader - GOVERNMENT party type' , ( ) => {
134- beforeEach ( ( ) => {
135- vi . clearAllMocks ( )
136- mockGetParticipant . mockResolvedValue ( {
137- partyId : 'gov-001' ,
138- name : 'HM Treasury' ,
139- partyType : 'GOVERNMENT' ,
140- status : 'SUSPENDED' ,
141- } )
142- } )
143-
144- it ( 'renders party name' , async ( ) => {
145- renderPartyHeader ( 'gov-001' )
146- await waitFor ( ( ) => {
147- expect ( screen . getByText ( 'HM Treasury' ) ) . toBeInTheDocument ( )
148- } )
149- } )
150-
151- it ( 'renders GOVERNMENT party type label' , async ( ) => {
152- renderPartyHeader ( 'gov-001' )
153- await waitFor ( ( ) => {
154- expect ( screen . getByText ( 'GOVERNMENT' ) ) . toBeInTheDocument ( )
155- } )
156- } )
157-
158- it ( 'renders SUSPENDED status badge' , async ( ) => {
159- renderPartyHeader ( 'gov-001' )
160- await waitFor ( ( ) => {
161- expect ( screen . getByText ( 'SUSPENDED' ) ) . toBeInTheDocument ( )
162- } )
163- } )
164- } )
165-
166- describe ( 'PartyHeader - status badge variants' , ( ) => {
167- beforeEach ( ( ) => {
168- vi . clearAllMocks ( )
169- } )
170-
171- it ( 'renders PENDING_VERIFICATION status' , async ( ) => {
172- mockGetParticipant . mockResolvedValue ( {
173- partyId : 'party-pv' ,
174- name : 'Pending Party' ,
175- partyType : 'INDIVIDUAL' ,
176- status : 'PENDING_VERIFICATION' ,
177- } )
178- renderPartyHeader ( 'party-pv' )
179- await waitFor ( ( ) => {
180- // StatusBadge renders the status, which may format underscores as spaces
181- expect ( screen . getByText ( / p e n d i n g .? v e r i f i c a t i o n / i) ) . toBeInTheDocument ( )
182- } )
183- } )
184- } )
185-
186- describe ( 'PartyHeader - verification status' , ( ) => {
187- beforeEach ( ( ) => {
188- vi . clearAllMocks ( )
189- } )
190-
191- it ( 'shows verification status when provided' , async ( ) => {
192- mockGetParticipant . mockResolvedValue ( {
193- partyId : 'party-v' ,
194- name : 'Verified Party' ,
195- partyType : 'ORGANIZATION' ,
196- status : 'ACTIVE' ,
197- verificationStatus : 'KYC_COMPLETE' ,
198- } )
199- renderPartyHeader ( 'party-v' )
200- await waitFor ( ( ) => {
201- expect ( screen . getByText ( 'Verification: KYC_COMPLETE' ) ) . toBeInTheDocument ( )
202- } )
203- } )
204-
205- it ( 'does not show verification section when verificationStatus is absent' , async ( ) => {
206- mockGetParticipant . mockResolvedValue ( {
207- partyId : 'party-nv' ,
208- name : 'Unverified Party' ,
209- partyType : 'INDIVIDUAL' ,
210- status : 'ACTIVE' ,
211- } )
212- renderPartyHeader ( 'party-nv' )
213- await waitFor ( ( ) => {
214- expect ( screen . getByText ( 'Unverified Party' ) ) . toBeInTheDocument ( )
215- } )
216- expect ( screen . queryByText ( / v e r i f i c a t i o n : / i) ) . not . toBeInTheDocument ( )
217- } )
218-
219- it ( 'does not show verification section when verificationStatus is empty string' , async ( ) => {
220- mockGetParticipant . mockResolvedValue ( {
221- partyId : 'party-ev' ,
222- name : 'Empty Verification' ,
223- partyType : 'INDIVIDUAL' ,
224- status : 'ACTIVE' ,
225- verificationStatus : '' ,
226- } )
227- renderPartyHeader ( 'party-ev' )
228- await waitFor ( ( ) => {
229- expect ( screen . getByText ( 'Empty Verification' ) ) . toBeInTheDocument ( )
123+ expect ( screen . getByText ( 'PARTY_TYPE_ORGANIZATION' ) ) . toBeInTheDocument ( )
230124 } )
231- expect ( screen . queryByText ( / v e r i f i c a t i o n : / i) ) . not . toBeInTheDocument ( )
232125 } )
233126} )
234127
@@ -238,11 +131,13 @@ describe('PartyHeader - party name display', () => {
238131 } )
239132
240133 it ( 'renders party name as heading level 2' , async ( ) => {
241- mockGetParticipant . mockResolvedValue ( {
242- partyId : 'party-h2' ,
243- name : 'Test Corporation' ,
244- partyType : 'ORGANIZATION' ,
245- status : 'ACTIVE' ,
134+ mockRetrieveParty . mockResolvedValue ( {
135+ party : {
136+ partyId : 'party-h2' ,
137+ legalName : 'Test Corporation' ,
138+ partyType : 'PARTY_TYPE_ORGANIZATION' ,
139+ status : 'PARTY_STATUS_ACTIVE' ,
140+ } ,
246141 } )
247142 renderPartyHeader ( 'party-h2' )
248143 await waitFor ( ( ) => {
@@ -251,16 +146,18 @@ describe('PartyHeader - party name display', () => {
251146 } )
252147 } )
253148
254- it ( 'calls getParticipant with the correct partyId' , async ( ) => {
255- mockGetParticipant . mockResolvedValue ( {
256- partyId : 'specific-id' ,
257- name : 'Specific Party' ,
258- partyType : 'INDIVIDUAL' ,
259- status : 'ACTIVE' ,
149+ it ( 'calls retrieveParty with the correct partyId' , async ( ) => {
150+ mockRetrieveParty . mockResolvedValue ( {
151+ party : {
152+ partyId : 'specific-id' ,
153+ legalName : 'Specific Party' ,
154+ partyType : 'PARTY_TYPE_PERSON' ,
155+ status : 'PARTY_STATUS_ACTIVE' ,
156+ } ,
260157 } )
261158 renderPartyHeader ( 'specific-id' )
262159 await waitFor ( ( ) => {
263- expect ( mockGetParticipant ) . toHaveBeenCalledWith ( { partyId : 'specific-id' } )
160+ expect ( mockRetrieveParty ) . toHaveBeenCalledWith ( { partyId : 'specific-id' } )
264161 } )
265162 } )
266163} )
0 commit comments