1- import { render , screen } from 'src/utilities/testingLibrary'
1+ import { render , screen , waitFor } from 'src/utilities/testingLibrary'
22import React from 'react'
33
44import VerifyExistingMember from 'src/views/verification/VerifyExistingMember'
55import { ReadableStatuses } from 'src/const/Statuses'
6-
7- describe ( 'VerifyExistingMember Test' , ( ) => {
8- const onAddNewMock = vi . fn ( )
9- beforeEach ( ( ) => {
10- render ( < VerifyExistingMember members = { mockMembers } onAddNew = { onAddNewMock } /> )
11- } )
12- afterEach ( ( ) => {
13- vi . clearAllMocks ( )
14- } )
15-
16- it ( 'should render a list of members, only those that support IAV and are managed by the user' , ( ) => {
17- expect ( screen . getByText ( 'Member 1' ) ) . toBeInTheDocument ( )
18- expect ( screen . queryByText ( 'Member 2' ) ) . not . toBeInTheDocument ( )
19- expect ( screen . queryByText ( 'Member 3' ) ) . not . toBeInTheDocument ( )
20- } )
21-
22- it ( 'should render a title and paragraph' , ( ) => {
23- expect ( screen . getByText ( 'Select your institution' ) ) . toBeInTheDocument ( )
24- expect (
25- screen . getByText (
26- 'Choose an institution that’s already connected and select accounts to share, or search for a different one.' ,
27- ) ,
28- ) . toBeInTheDocument ( )
29- } )
30-
31- it ( 'should render a count of connected institutions' , ( ) => {
32- expect ( screen . getByText ( '1 Connected institution' ) ) . toBeInTheDocument ( )
33- } )
34-
35- it ( 'should render a button to search for more institutions' , ( ) => {
36- const button = screen . getByText ( 'Search more institutions' )
37- expect ( button ) . toBeInTheDocument ( )
38-
39- button . click ( )
40- expect ( onAddNewMock ) . toHaveBeenCalled ( )
41- } )
42- } )
6+ import { ApiProvider } from 'src/context/ApiContext'
7+ import { initialState } from 'src/services/mockedData'
8+ import { COMBO_JOB_DATA_TYPES } from 'src/const/comboJobDataTypes'
439
4410const mockMembers = [
4511 {
4612 guid : 'MBR-123' ,
4713 name : 'Member 1' ,
14+ institution_guid : 'INS-123' ,
4815 verification_is_enabled : true ,
4916 is_managed_by_user : true ,
5017 aggregation_status : 1 ,
5118 connection_status : ReadableStatuses . CONNECTED ,
52- institution_guid : 'INS-123' ,
5319 institution_url : 'https://example.com' ,
5420 is_being_aggregated : false ,
5521 is_manual : false ,
@@ -59,11 +25,11 @@ const mockMembers = [
5925 {
6026 guid : 'MBR-456' ,
6127 name : 'Member 2' ,
28+ institution_guid : 'INS-456' ,
6229 verification_is_enabled : true ,
63- is_managed_by_user : false ,
30+ is_managed_by_user : true ,
6431 aggregation_status : 6 ,
6532 connection_status : ReadableStatuses . CONNECTED ,
66- institution_guid : 'INS-456' ,
6733 institution_url : 'https://example.com' ,
6834 is_being_aggregated : false ,
6935 is_manual : false ,
@@ -73,15 +39,131 @@ const mockMembers = [
7339 {
7440 guid : 'MBR-789' ,
7541 name : 'Member 3' ,
42+ institution_guid : 'INS-789' ,
7643 verification_is_enabled : false ,
7744 is_managed_by_user : true ,
7845 aggregation_status : 6 ,
7946 connection_status : ReadableStatuses . CONNECTED ,
80- institution_guid : 'INS-789' ,
8147 institution_url : 'https://example.com' ,
8248 is_being_aggregated : false ,
8349 is_manual : false ,
8450 is_oauth : true ,
8551 user_guid : 'USR-789' ,
8652 } ,
8753]
54+
55+ const mockInstitutions = new Map ( [
56+ [
57+ 'INS-123' ,
58+ {
59+ guid : 'INS-123' ,
60+ name : 'Institution 1' ,
61+ account_verification_is_enabled : true ,
62+ account_identification_is_enabled : false ,
63+ } ,
64+ ] ,
65+ [
66+ 'INS-456' ,
67+ {
68+ guid : 'INS-456' ,
69+ name : 'Institution 2' ,
70+ account_verification_is_enabled : true ,
71+ account_identification_is_enabled : true ,
72+ } ,
73+ ] ,
74+ [
75+ 'INS-789' ,
76+ {
77+ guid : 'INS-789' ,
78+ name : 'Institution 3' ,
79+ account_identification_is_enabled : true ,
80+ account_verification_is_enabled : false ,
81+ } ,
82+ ] ,
83+ ] )
84+
85+ describe ( 'VerifyExistingMember Component' , ( ) => {
86+ beforeEach ( ( ) => {
87+ vi . resetAllMocks ( ) // Clear mocks before each test
88+ } )
89+
90+ const loadInstitutionByGuidMock = ( guid ) => {
91+ return Promise . resolve ( mockInstitutions . get ( guid ) )
92+ }
93+
94+ const onAddNewMock = vi . fn ( )
95+
96+ // Helper function to render the component with consistent setup
97+ const renderComponent = ( config = { } ) => {
98+ return render (
99+ < ApiProvider apiValue = { { loadInstitutionByGuid : loadInstitutionByGuidMock } } >
100+ < VerifyExistingMember members = { mockMembers } onAddNew = { onAddNewMock } />
101+ </ ApiProvider > ,
102+ {
103+ preloadedState : {
104+ config : {
105+ ...initialState . config ,
106+ ...config ,
107+ } ,
108+ } ,
109+ } ,
110+ )
111+ }
112+
113+ it ( 'should render a list of members, only those that support IAV and are managed by the user' , async ( ) => {
114+ renderComponent ( {
115+ data_request : { products : [ COMBO_JOB_DATA_TYPES . ACCOUNT_NUMBER ] } ,
116+ } )
117+
118+ await waitFor ( ( ) => screen . getByText ( 'Member 1' ) )
119+
120+ expect ( screen . getByText ( 'Member 1' ) ) . toBeInTheDocument ( )
121+ expect ( screen . queryByText ( 'Member 2' ) ) . toBeInTheDocument ( )
122+ expect ( screen . queryByText ( 'Member 3' ) ) . not . toBeInTheDocument ( )
123+ } )
124+
125+ it ( 'should render a list of members, only those that support ACCOUNT_OWNER and are managed by the user' , async ( ) => {
126+ renderComponent ( {
127+ data_request : { products : [ COMBO_JOB_DATA_TYPES . ACCOUNT_OWNER ] } ,
128+ } )
129+
130+ await waitFor ( ( ) => screen . getByText ( 'Member 2' ) )
131+
132+ expect ( screen . getByText ( 'Member 2' ) ) . toBeInTheDocument ( )
133+ expect ( screen . queryByText ( 'Member 1' ) ) . not . toBeInTheDocument ( )
134+ expect ( screen . queryByText ( 'Member 3' ) ) . not . toBeInTheDocument ( )
135+ } )
136+
137+ it ( 'should render a title and paragraph' , async ( ) => {
138+ renderComponent ( )
139+
140+ await waitFor ( ( ) => {
141+ expect ( screen . getByRole ( 'heading' , { name : / S e l e c t y o u r i n s t i t u t i o n / i } ) ) . toBeInTheDocument ( )
142+ expect (
143+ screen . getByText (
144+ 'Choose an institution that’s already connected and select accounts to share, or search for a different one.' ,
145+ ) ,
146+ ) . toBeInTheDocument ( )
147+ } )
148+ } )
149+
150+ it ( 'should render a count of connected institutions' , async ( ) => {
151+ renderComponent ( {
152+ data_request : { products : [ COMBO_JOB_DATA_TYPES . ACCOUNT_OWNER ] } ,
153+ } )
154+
155+ await waitFor ( ( ) => screen . getByText ( '1 Connected institution' ) )
156+ expect ( screen . getByText ( '1 Connected institution' ) ) . toBeInTheDocument ( )
157+ } )
158+
159+ it ( 'should call onAddNew when the search more institutions button is clicked' , async ( ) => {
160+ const { user } = renderComponent ( )
161+
162+ await waitFor ( async ( ) => {
163+ const button = screen . getByRole ( 'button' , { name : / S e a r c h m o r e i n s t i t u t i o n s / i } )
164+ await user . click ( button )
165+
166+ expect ( onAddNewMock ) . toHaveBeenCalledTimes ( 1 )
167+ } )
168+ } )
169+ } )
0 commit comments