Skip to content

Commit

Permalink
prevented unnecessary page reload with complementary test (#3202)
Browse files Browse the repository at this point in the history
* 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 e0fa894.

* 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 <syedaliulhasan19@gmail.com>
Co-authored-by: harshk-89 <133699216+harshk-89@users.noreply.github.com>
Co-authored-by: Amaan ali <amaan.ali.ug22@nsut.ac.in>
Co-authored-by: Yugal Sadhwani <yashsadhwani544@gmail.com>
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>
  • Loading branch information
11 people authored Jan 9, 2025
1 parent 50cd26d commit 011f9ab
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
48 changes: 40 additions & 8 deletions src/components/OrgPeopleListCard/OrgPeopleListCard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<OrgPeopleListCard {...props} />
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
);

// 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);

Expand Down Expand Up @@ -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 },
);
Expand Down
5 changes: 1 addition & 4 deletions src/components/OrgPeopleListCard/OrgPeopleListCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 011f9ab

Please sign in to comment.