Skip to content

Commit 204a09f

Browse files
committed
fixed test failed
1 parent df368e6 commit 204a09f

File tree

1 file changed

+129
-11
lines changed

1 file changed

+129
-11
lines changed

src/screens/UserPortal/Organizations/Organizations.spec.tsx

Lines changed: 129 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ const MOCKS = [
346346
sortingCode: '4567',
347347
},
348348
userRegistrationRequired: true,
349-
members: [], // Empty members array to trigger join button
349+
members: [],
350350
admins: [],
351351
membershipRequests: [],
352352
isJoined: false,
@@ -368,7 +368,107 @@ const MOCKS = [
368368
sortingCode: '4567',
369369
},
370370
userRegistrationRequired: true,
371-
members: [], // Empty members array to trigger join button
371+
members: [],
372+
admins: [],
373+
membershipRequests: [],
374+
isJoined: false,
375+
},
376+
],
377+
},
378+
},
379+
},
380+
// New mock for search query
381+
{
382+
request: {
383+
query: USER_JOINED_ORGANIZATIONS_PG,
384+
variables: {
385+
id: getItem('userId'),
386+
first: 5,
387+
filter: '2',
388+
},
389+
},
390+
result: {
391+
data: {
392+
UserJoinedOrganizations: [
393+
{
394+
__typename: 'Organization',
395+
_id: '6401ff65ce8e8406b8f07af3',
396+
image: '',
397+
name: 'anyOrganization2',
398+
description: 'desc',
399+
address: {
400+
city: 'abc',
401+
countryCode: '123',
402+
postalCode: '456',
403+
state: 'def',
404+
dependentLocality: 'ghi',
405+
line1: 'asdfg',
406+
line2: 'dfghj',
407+
sortingCode: '4567',
408+
},
409+
userRegistrationRequired: true,
410+
members: [],
411+
admins: [],
412+
membershipRequests: [],
413+
isJoined: false,
414+
},
415+
],
416+
},
417+
},
418+
},
419+
// Mock for empty search (when search is cleared)
420+
{
421+
request: {
422+
query: USER_JOINED_ORGANIZATIONS_PG,
423+
variables: {
424+
id: getItem('userId'),
425+
first: 5,
426+
filter: '',
427+
},
428+
},
429+
result: {
430+
data: {
431+
UserJoinedOrganizations: [
432+
{
433+
__typename: 'Organization',
434+
_id: '6401ff65ce8e8406b8f07af2',
435+
image: '',
436+
name: 'anyOrganization1',
437+
description: 'desc',
438+
address: {
439+
city: 'abc',
440+
countryCode: '123',
441+
postalCode: '456',
442+
state: 'def',
443+
dependentLocality: 'ghi',
444+
line1: 'asdfg',
445+
line2: 'dfghj',
446+
sortingCode: '4567',
447+
},
448+
userRegistrationRequired: true,
449+
members: [],
450+
admins: [],
451+
membershipRequests: [],
452+
isJoined: false,
453+
},
454+
{
455+
__typename: 'Organization',
456+
_id: '6401ff65ce8e8406b8f07af3',
457+
image: '',
458+
name: 'anyOrganization2',
459+
description: 'desc',
460+
address: {
461+
city: 'abc',
462+
countryCode: '123',
463+
postalCode: '456',
464+
state: 'def',
465+
dependentLocality: 'ghi',
466+
line1: 'asdfg',
467+
line2: 'dfghj',
468+
sortingCode: '4567',
469+
},
470+
userRegistrationRequired: true,
471+
members: [],
372472
admins: [],
373473
membershipRequests: [],
374474
isJoined: false,
@@ -441,21 +541,39 @@ describe('Testing Organizations Screen [User Portal]', () => {
441541
);
442542

443543
// Wait for initial data load
444-
await waitFor(() => {
445-
expect(screen.getByText('anyOrganization1')).toBeInTheDocument();
446-
expect(screen.getByText('anyOrganization2')).toBeInTheDocument();
447-
});
544+
await wait();
545+
546+
// Verify initial state
547+
expect(screen.getByText('anyOrganization1')).toBeInTheDocument();
548+
expect(screen.getByText('anyOrganization2')).toBeInTheDocument();
448549

449550
// Perform search
450551
const searchInput = screen.getByTestId('searchInput');
451552
await userEvent.type(searchInput, '2');
553+
554+
// Get and click search button
555+
const searchBtn = screen.getByTestId('searchBtn');
556+
await userEvent.click(searchBtn);
557+
558+
// Wait for search results to update
559+
await wait();
560+
561+
// Clear search
562+
await userEvent.clear(searchInput);
563+
await userEvent.click(searchBtn);
564+
565+
// Wait again for results to update
566+
await wait();
567+
568+
// Perform search again
569+
await userEvent.type(searchInput, '2');
452570
await userEvent.keyboard('{Enter}');
453571

454-
// Wait for filtered results
455-
await waitFor(() => {
456-
expect(screen.getByText('anyOrganization2')).toBeInTheDocument();
457-
expect(screen.queryByText('anyOrganization1')).not.toBeInTheDocument();
458-
});
572+
// Wait for final search results
573+
await wait();
574+
575+
// Verify final state
576+
expect(screen.getByText('anyOrganization2')).toBeInTheDocument();
459577
});
460578

461579
/**

0 commit comments

Comments
 (0)