Skip to content

Commit

Permalink
prevented unnecessary page reload with complementary test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhiren-Mhatre committed Jan 7, 2025
1 parent 01d0101 commit a460ad2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 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
4 changes: 1 addition & 3 deletions src/components/OrgPeopleListCard/OrgPeopleListCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ function orgPeopleListCard(
// 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 a460ad2

Please sign in to comment.