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

Test for code Coverage For DeleteOrg.tsx #1220

Merged
Merged
Changes from all commits
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
79 changes: 78 additions & 1 deletion src/components/DeleteOrg/DeleteOrg.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { MockedProvider } from '@apollo/react-testing';
import { render, screen } from '@testing-library/react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import 'jest-location-mock';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
Expand Down Expand Up @@ -81,4 +81,81 @@ describe('Delete Organization Component', () => {
screen.getByTestId(/deleteOrganizationBtn/i).click();
expect(window.location).not.toBeNull();
});
test('should handle deletion failure gracefully', async () => {
window.location.assign('/orgsetting/id=456'); // Using an ID that triggers a failure
localStorage.setItem('UserType', 'SUPERADMIN');
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<DeleteOrg />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);

fireEvent.click(screen.getByTestId('openDeleteModalBtn'));
fireEvent.click(screen.getByTestId('deleteOrganizationBtn'));
expect(screen.queryByText(/Deletion failed!/i)).toBeNull();
});
test('should close the Delete Organization Modal when "Cancel" button is clicked', async () => {
window.location.assign('/orgsetting/id=123');
localStorage.setItem('UserType', 'SUPERADMIN');
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<DeleteOrg />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);
fireEvent.click(screen.getByTestId('openDeleteModalBtn'));
expect(screen.getByTestId('orgDeleteModal')).toBeInTheDocument();
fireEvent.click(screen.getByTestId('closeDelOrgModalBtn'));
await waitFor(() => {
expect(screen.queryByTestId('orgDeleteModal')).toBeNull();
});
expect(window.location).toBeAt('/orgsetting/id=123');
});
test('should open the Delete Organization Modal when "Delete" button is clicked', async () => {
window.location.assign('/orgsetting/id=123');
localStorage.setItem('UserType', 'SUPERADMIN');
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<DeleteOrg />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);
fireEvent.click(screen.getByTestId('openDeleteModalBtn'));
expect(screen.getByTestId('orgDeleteModal')).toBeInTheDocument();
expect(window.location).toBeAt('/orgsetting/id=123');
});
test('render Delete Organization Modal when "Delete" button is clicked', async () => {
window.location.assign('/orgsetting/id=123');
localStorage.setItem('UserType', 'SUPERADMIN');
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<DeleteOrg />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);
fireEvent.click(screen.getByTestId('openDeleteModalBtn'));
expect(screen.getByTestId('orgDeleteModal')).toBeInTheDocument();
expect(window.location).toBeAt('/orgsetting/id=123');
});
});