@@ -98,20 +98,86 @@ describe('AddOnSpotAttendee Component', () => {
98
98
expect ( screen . getByLabelText ( 'Gender' ) ) . toBeInTheDocument ( ) ;
99
99
} ) ;
100
100
101
- it ( 'handles form input changes correctly' , async ( ) => {
102
- renderAddOnSpotAttendee ( ) ;
101
+ it ( 'handles case where signUp response is undefined' , async ( ) => {
102
+ const mockWithoutSignUp = [
103
+ {
104
+ request : {
105
+ query : SIGNUP_MUTATION ,
106
+ variables : {
107
+ firstName : 'John' ,
108
+ lastName : 'Doe' ,
109
+ email : 'john@example.com' ,
110
+ phoneNo : '1234567890' ,
111
+ gender : 'Male' ,
112
+ password : '123456' ,
113
+ orgId : '123' ,
114
+ } ,
115
+ } ,
116
+ result : {
117
+ data : { } , // No signUp property
118
+ } ,
119
+ } ,
120
+ ] ;
121
+
122
+ render (
123
+ < MockedProvider mocks = { mockWithoutSignUp } addTypename = { false } >
124
+ < Provider store = { store } >
125
+ < I18nextProvider i18n = { i18nForTest } >
126
+ < BrowserRouter >
127
+ < AddOnSpotAttendee { ...mockProps } />
128
+ </ BrowserRouter >
129
+ </ I18nextProvider >
130
+ </ Provider >
131
+ </ MockedProvider > ,
132
+ ) ;
133
+
134
+ userEvent . type ( screen . getByLabelText ( 'First Name' ) , 'John' ) ;
135
+ userEvent . type ( screen . getByLabelText ( 'Last Name' ) , 'Doe' ) ;
136
+ userEvent . type ( screen . getByLabelText ( 'Email' ) , 'john@example.com' ) ;
137
+ userEvent . type ( screen . getByLabelText ( 'Phone No.' ) , '1234567890' ) ;
138
+ const genderSelect = screen . getByLabelText ( 'Gender' ) ;
139
+ fireEvent . change ( genderSelect , { target : { value : 'Male' } } ) ;
140
+
141
+ fireEvent . submit ( screen . getByTestId ( 'onspot-attendee-form' ) ) ;
103
142
104
- const firstNameInput = screen . getByLabelText ( 'First Name' ) ;
105
- const lastNameInput = screen . getByLabelText ( 'Last Name' ) ;
106
- const emailInput = screen . getByLabelText ( 'Email' ) ;
143
+ await waitFor ( ( ) => {
144
+ expect ( toast . success ) . not . toHaveBeenCalled ( ) ; // Ensure success toast is not shown
145
+ expect ( toast . error ) . not . toHaveBeenCalled ( ) ; // Ensure no unexpected error toast
146
+ expect ( mockProps . reloadMembers ) . not . toHaveBeenCalled ( ) ; // Reload should not be triggered
147
+ expect ( mockProps . handleClose ) . not . toHaveBeenCalled ( ) ; // Modal should not close
148
+ } ) ;
149
+ } ) ;
107
150
108
- userEvent . type ( firstNameInput , 'John' ) ;
109
- userEvent . type ( lastNameInput , 'Doe' ) ;
110
- userEvent . type ( emailInput , 'john@example.com' ) ;
151
+ it ( 'handles error during form submission' , async ( ) => {
152
+ render (
153
+ < MockedProvider mocks = { ERROR_MOCKS } addTypename = { false } >
154
+ < Provider store = { store } >
155
+ < I18nextProvider i18n = { i18nForTest } >
156
+ < BrowserRouter >
157
+ < AddOnSpotAttendee { ...mockProps } />
158
+ </ BrowserRouter >
159
+ </ I18nextProvider >
160
+ </ Provider >
161
+ </ MockedProvider > ,
162
+ ) ;
163
+
164
+ // Fill the form
165
+ userEvent . type ( screen . getByLabelText ( 'First Name' ) , 'John' ) ;
166
+ userEvent . type ( screen . getByLabelText ( 'Last Name' ) , 'Doe' ) ;
167
+ userEvent . type ( screen . getByLabelText ( 'Email' ) , 'john@example.com' ) ;
168
+ userEvent . type ( screen . getByLabelText ( 'Phone No.' ) , '1234567890' ) ;
169
+ const genderSelect = screen . getByLabelText ( 'Gender' ) ;
170
+ fireEvent . change ( genderSelect , { target : { value : 'Male' } } ) ;
171
+
172
+ // Submit the form
173
+ fireEvent . submit ( screen . getByTestId ( 'onspot-attendee-form' ) ) ;
111
174
112
- expect ( firstNameInput ) . toHaveValue ( 'John' ) ;
113
- expect ( lastNameInput ) . toHaveValue ( 'Doe' ) ;
114
- expect ( emailInput ) . toHaveValue ( 'john@example.com' ) ;
175
+ // Wait for the error to be handled
176
+ await waitFor ( ( ) => {
177
+ expect ( toast . error ) . toHaveBeenCalledWith (
178
+ expect . stringContaining ( 'Failed to add attendee' ) ,
179
+ ) ;
180
+ } ) ;
115
181
} ) ;
116
182
117
183
it ( 'submits form successfully and calls necessary callbacks' , async ( ) => {
0 commit comments