From 011f9abe37947bfe3fb0b015227d5e61e29ff250 Mon Sep 17 00:00:00 2001 From: Dhiren-Mhatre <130587526+Dhiren-Mhatre@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:21:45 +0530 Subject: [PATCH] prevented unnecessary page reload with complementary test (#3202) * prevented unnecessary page reload with complementary test * Update jest.config.js * Fixes #2986 - Multiple UI Updates (#3165) * UI fixes on organisation pages * Added TSDoc for Truncated Text * Added Debouncer * Update src/components/OrgListCard/OrgListCard.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Added code rabbit suggestions * Fixed test error --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * refactore src/screens/OrgList from jest to vitest (#3200) * Improved Code Coverage in src/components/Venues/VenueModal.tsx (#3203) * Improved Code Coverage in src/components/Venues/VenueModal.tsx * removed the ignore statements from VenueModal.tsx * Removed istanbul ignore lines. Code coverage remians 100% (#3207) * refactored src/screens/FundCampaignPledge from jest to vitest (#3208) * prettier formatting and disabled ts-specific rules for js in eslint (#3186) * Improve Code Coverage in src/screens/UserPortal/Settings/Settings.tsx (#3189) * Preventing Overflow of images in Advertisement and Venue Post modals (#3204) * improve code coverage of src/screens/EventManagement (#3149) * code coverage * jest global coverage decreased * global jest coverage * rename file problem solved * changes requested resolved * fix: update Chat section title to 'Chats' (#3216) * removed stale comment line * Revert "removed stale comment line" This reverts commit e0fa8942491defaf39658f8e8171df52a218c4e4. * removed stale comment line --------- Co-authored-by: Peter Harrison <16875803+palisadoes@users.noreply.github.com> Co-authored-by: Mehul Aggarwal <88583647+AceHunterr@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Syed Ali Ul Hasan Co-authored-by: harshk-89 <133699216+harshk-89@users.noreply.github.com> Co-authored-by: Amaan ali Co-authored-by: Yugal Sadhwani Co-authored-by: Pranav Nathe <93403830+pranavnathe@users.noreply.github.com> Co-authored-by: prathmesh703 <146568950+prathmesh703@users.noreply.github.com> Co-authored-by: Nivedita <141390434+Nivedita-Chhokar@users.noreply.github.com> --- .../OrgPeopleListCard.spec.tsx | 48 +++++++++++++++---- .../OrgPeopleListCard/OrgPeopleListCard.tsx | 5 +- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/components/OrgPeopleListCard/OrgPeopleListCard.spec.tsx b/src/components/OrgPeopleListCard/OrgPeopleListCard.spec.tsx index 3023c82319..485ad1ae11 100644 --- a/src/components/OrgPeopleListCard/OrgPeopleListCard.spec.tsx +++ b/src/components/OrgPeopleListCard/OrgPeopleListCard.spec.tsx @@ -83,6 +83,45 @@ describe('Testing Organization People List Card', () => { }); }); + const NULL_DATA_MOCKS = [ + { + request: { + query: REMOVE_MEMBER_MUTATION, + variables: { + userid: '1', + orgid: '456', + }, + }, + result: { + data: null, + }, + }, + ]; + + test('should handle null data response from mutation', async () => { + const link = new StaticMockLink(NULL_DATA_MOCKS, true); + + render( + + + + + + + , + ); + + // Click remove button + const removeButton = screen.getByTestId('removeMemberBtn'); + await userEvent.click(removeButton); + + // Verify that success toast and toggleRemoveModal were not called + await waitFor(() => { + expect(toast.success).not.toHaveBeenCalled(); + expect(props.toggleRemoveModal).not.toHaveBeenCalled(); + }); + }); + test('should render modal and handle successful member removal', async () => { const link = new StaticMockLink(MOCKS, true); @@ -123,14 +162,7 @@ describe('Testing Organization People List Card', () => { await waitFor( () => { expect(toast.success).toHaveBeenCalled(); - }, - { timeout: 3000 }, - ); - - // Check if page reload is triggered after delay - await waitFor( - () => { - expect(window.location.reload).toHaveBeenCalled(); + expect(props.toggleRemoveModal).toHaveBeenCalled(); }, { timeout: 3000 }, ); diff --git a/src/components/OrgPeopleListCard/OrgPeopleListCard.tsx b/src/components/OrgPeopleListCard/OrgPeopleListCard.tsx index 8a028227f1..e7171bff71 100644 --- a/src/components/OrgPeopleListCard/OrgPeopleListCard.tsx +++ b/src/components/OrgPeopleListCard/OrgPeopleListCard.tsx @@ -55,12 +55,9 @@ function orgPeopleListCard( orgid: currentUrl, }, }); - // If the mutation is successful, show a success message and reload the page if (data) { toast.success(t('memberRemoved') as string); - setTimeout(() => { - window.location.reload(); - }, 2000); + props.toggleRemoveModal(); } } catch (error: unknown) { errorHandler(t, error);