@@ -3,7 +3,6 @@ import type { RenderResult } from '@testing-library/react';
3
3
import {
4
4
render ,
5
5
screen ,
6
- fireEvent ,
7
6
waitFor ,
8
7
waitForElementToBeRemoved ,
9
8
act ,
@@ -184,6 +183,20 @@ const MOCKS = [
184
183
} ,
185
184
} ,
186
185
} ,
186
+ {
187
+ request : {
188
+ query : ORGANIZATIONS_MEMBER_CONNECTION_LIST ,
189
+ variables : { orgId : '' , firstName_contains : '' } ,
190
+ } ,
191
+ error : new Error ( 'Network error' ) ,
192
+ } ,
193
+ {
194
+ request : {
195
+ query : ORGANIZATION_ADMINS_LIST ,
196
+ variables : { id : '' } ,
197
+ } ,
198
+ error : new Error ( 'GraphQL error' ) ,
199
+ } ,
187
200
] ;
188
201
189
202
const link = new StaticMockLink ( MOCKS , true ) ;
@@ -321,8 +334,9 @@ describe('Testing People Screen [User Portal]', () => {
321
334
</ MockedProvider > ,
322
335
) ;
323
336
324
- expect ( screen . getByText ( 'Loading...' ) ) . toBeInTheDocument ( ) ;
325
- await wait ( ) ;
337
+ const loadingElement = screen . getByText ( 'Loading...' ) ;
338
+ expect ( loadingElement ) . toBeInTheDocument ( ) ;
339
+ await waitForElementToBeRemoved ( loadingElement ) ;
326
340
} ) ;
327
341
} ) ;
328
342
@@ -883,33 +897,6 @@ describe('Testing People Screen Edge Cases [User Portal]', () => {
883
897
884
898
describe ( 'People Component Additional Coverage Tests' , ( ) => {
885
899
// Mock for testing error states
886
-
887
- // Test case to cover line 142: handleSearchByEnter with non-Enter key
888
- it ( 'should not trigger search for non-Enter key press' , async ( ) => {
889
- render (
890
- < MockedProvider addTypename = { false } mocks = { [ ] } >
891
- < BrowserRouter >
892
- < Provider store = { store } >
893
- < I18nextProvider i18n = { i18nForTest } >
894
- < People />
895
- </ I18nextProvider >
896
- </ Provider >
897
- </ BrowserRouter >
898
- </ MockedProvider > ,
899
- ) ;
900
-
901
- const searchInput = screen . getByTestId ( 'searchInput' ) ;
902
- fireEvent . keyUp ( searchInput , { key : 'A' , code : 'KeyA' } ) ;
903
-
904
- // Wait a bit to ensure no search is triggered
905
- await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
906
- // The loading state should not appear
907
- expect ( screen . queryByText ( 'Loading...' ) ) . not . toBeInTheDocument ( ) ;
908
- // Ensure no new data is fetched
909
- expect ( screen . queryByText ( 'John Cena' ) ) . not . toBeInTheDocument ( ) ;
910
- expect ( screen . queryByText ( 'Noble Mittal' ) ) . not . toBeInTheDocument ( ) ;
911
- } ) ;
912
-
913
900
// Test case to cover line 151: handleSearchByBtnClick with empty input
914
901
it ( 'should handle search with empty input value' , async ( ) => {
915
902
render (
@@ -931,7 +918,10 @@ describe('People Component Additional Coverage Tests', () => {
931
918
userEvent . clear ( searchInput ) ;
932
919
userEvent . click ( searchBtn ) ;
933
920
934
- await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
921
+ await waitFor ( ( ) => {
922
+ expect ( ( searchInput as HTMLInputElement ) . value ) . toBe ( '' ) ;
923
+ expect ( screen . queryByText ( 'Loading...' ) ) . not . toBeInTheDocument ( ) ;
924
+ } ) ;
935
925
} ) ;
936
926
937
927
it ( 'Sets userType to Admin if user is found in admins list' , async ( ) : Promise < void > => {
0 commit comments