From a7a1ab773e50f46c016ed3c917c95ee99928cef7 Mon Sep 17 00:00:00 2001 From: VaibhavTalkhande Date: Thu, 21 Dec 2023 11:33:38 +0530 Subject: [PATCH 1/2] added more test for deleteOrganisation --- src/components/DeleteOrg/DeleteOrg.test.tsx | 59 ++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/components/DeleteOrg/DeleteOrg.test.tsx b/src/components/DeleteOrg/DeleteOrg.test.tsx index 936cf44e03..d5acf51d4c 100644 --- a/src/components/DeleteOrg/DeleteOrg.test.tsx +++ b/src/components/DeleteOrg/DeleteOrg.test.tsx @@ -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 } from '@testing-library/react'; import 'jest-location-mock'; import { I18nextProvider } from 'react-i18next'; import { Provider } from 'react-redux'; @@ -81,4 +81,61 @@ describe('Delete Organization Component', () => { screen.getByTestId(/deleteOrganizationBtn/i).click(); expect(window.location).not.toBeNull(); }); + test('should handle deletion of non-sample organization', async () => { + window.location.assign('/orgsetting/id=123'); + localStorage.setItem('UserType', 'SUPERADMIN'); + render( + + + + + + + + + + ); + fireEvent.click(screen.getByTestId('openDeleteModalBtn')); + fireEvent.click(screen.getByTestId('deleteOrganizationBtn')); + await expect(screen.queryByTestId('orgDeleteModal')).toBeInTheDocument(); + expect(window.location).not.toBeNull(); + }); + test('should handle deletion of sample organization', async () => { + window.location.assign('/orgsetting/id=123'); + localStorage.setItem('UserType', 'SUPERADMIN'); + render( + + + + + + + + + + ); + fireEvent.click(screen.getByTestId('openDeleteModalBtn')); + fireEvent.click(screen.getByTestId('deleteOrganizationBtn')); + await expect(screen.queryByTestId('orgDeleteModal')).toBeInTheDocument(); + 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( + + + + + + + + + + ); + + fireEvent.click(screen.getByTestId('openDeleteModalBtn')); + fireEvent.click(screen.getByTestId('deleteOrganizationBtn')); + expect(screen.queryByText(/Deletion failed!/i)).toBeNull(); + }); }); From 3c3d5b3bd4c299ba87c97e9d06449601c088d48b Mon Sep 17 00:00:00 2001 From: VaibhavTalkhande Date: Thu, 21 Dec 2023 11:51:43 +0530 Subject: [PATCH 2/2] added delete button test for deleteOrganisation --- src/components/DeleteOrg/DeleteOrg.test.tsx | 48 +++++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/components/DeleteOrg/DeleteOrg.test.tsx b/src/components/DeleteOrg/DeleteOrg.test.tsx index d5acf51d4c..e0a58351f7 100644 --- a/src/components/DeleteOrg/DeleteOrg.test.tsx +++ b/src/components/DeleteOrg/DeleteOrg.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { MockedProvider } from '@apollo/react-testing'; -import { fireEvent, 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'; @@ -81,8 +81,8 @@ describe('Delete Organization Component', () => { screen.getByTestId(/deleteOrganizationBtn/i).click(); expect(window.location).not.toBeNull(); }); - test('should handle deletion of non-sample organization', async () => { - window.location.assign('/orgsetting/id=123'); + 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( @@ -95,12 +95,12 @@ describe('Delete Organization Component', () => { ); + fireEvent.click(screen.getByTestId('openDeleteModalBtn')); fireEvent.click(screen.getByTestId('deleteOrganizationBtn')); - await expect(screen.queryByTestId('orgDeleteModal')).toBeInTheDocument(); - expect(window.location).not.toBeNull(); + expect(screen.queryByText(/Deletion failed!/i)).toBeNull(); }); - test('should handle deletion of sample organization', async () => { + test('should close the Delete Organization Modal when "Cancel" button is clicked', async () => { window.location.assign('/orgsetting/id=123'); localStorage.setItem('UserType', 'SUPERADMIN'); render( @@ -115,12 +115,15 @@ describe('Delete Organization Component', () => { ); fireEvent.click(screen.getByTestId('openDeleteModalBtn')); - fireEvent.click(screen.getByTestId('deleteOrganizationBtn')); - await expect(screen.queryByTestId('orgDeleteModal')).toBeInTheDocument(); - expect(window.location).not.toBeNull(); + 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 handle deletion failure gracefully', async () => { - window.location.assign('/orgsetting/id=456'); // Using an ID that triggers a failure + test('should open the Delete Organization Modal when "Delete" button is clicked', async () => { + window.location.assign('/orgsetting/id=123'); localStorage.setItem('UserType', 'SUPERADMIN'); render( @@ -133,9 +136,26 @@ describe('Delete Organization Component', () => { ); - fireEvent.click(screen.getByTestId('openDeleteModalBtn')); - fireEvent.click(screen.getByTestId('deleteOrganizationBtn')); - expect(screen.queryByText(/Deletion failed!/i)).toBeNull(); + 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( + + + + + + + + + + ); + fireEvent.click(screen.getByTestId('openDeleteModalBtn')); + expect(screen.getByTestId('orgDeleteModal')).toBeInTheDocument(); + expect(window.location).toBeAt('/orgsetting/id=123'); }); });