Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevented unnecessary page reload with complementary test #3202

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Dhiren-Mhatre marked this conversation as resolved.
Show resolved Hide resolved
if (data) {
toast.success(t('memberRemoved') as string);
setTimeout(() => {
window.location.reload();
}, 2000);
props.toggleRemoveModal();
}
} catch (error: unknown) {
errorHandler(t, error);
Expand Down
Loading