From d1dddd0aacc62c19668bd9f72ca74510dc51cb3d Mon Sep 17 00:00:00 2001 From: Divyansh Seth Date: Wed, 30 Oct 2024 18:21:19 +0530 Subject: [PATCH] corrected test code --- .../LeftDrawerOrg/LeftDrawerOrg.test.tsx | 44 ++++++++++++++++++- .../LeftDrawerOrg/LeftDrawerOrg.tsx | 20 ++++----- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx b/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx index c73d3c36f2..71f3593499 100644 --- a/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx +++ b/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx @@ -3,7 +3,7 @@ import { fireEvent, render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import 'jest-localstorage-mock'; import { I18nextProvider } from 'react-i18next'; -import { BrowserRouter } from 'react-router-dom'; +import { BrowserRouter, MemoryRouter } from 'react-router-dom'; import i18nForTest from 'utils/i18nForTest'; import type { InterfaceLeftDrawerProps } from './LeftDrawerOrg'; @@ -21,6 +21,10 @@ const { setItem } = useLocalStorage(); const props: InterfaceLeftDrawerProps = { orgId: '123', targets: [ + { + name: 'Admin Profile', + url: '/member/123', + }, { name: 'Dashboard', url: '/orgdash/123', @@ -215,6 +219,20 @@ const MOCKS_EMPTY = [ }, ]; +const MOCKS_EMPTY_ORGID = [ + { + request: { + query: ORGANIZATIONS_LIST, + variables: { id: '' }, + }, + result: { + data: { + organizations: [], + }, + }, + }, +]; + const defaultScreens = [ 'Dashboard', 'People', @@ -264,6 +282,7 @@ afterEach(() => { const link = new StaticMockLink(MOCKS, true); const linkImage = new StaticMockLink(MOCKS_WITH_IMAGE, true); const linkEmpty = new StaticMockLink(MOCKS_EMPTY, true); +const linkEmptyOrgId = new StaticMockLink(MOCKS_EMPTY_ORGID, true); describe('Testing LeftDrawerOrg component for SUPERADMIN', () => { test('Component should be rendered properly', async () => { @@ -291,7 +310,8 @@ describe('Testing LeftDrawerOrg component for SUPERADMIN', () => { test('Testing Profile Page & Organization Detail Modal', async () => { setItem('UserImage', ''); setItem('SuperAdmin', true); - setItem('id', '1234'); + setItem('FirstName', 'John'); + setItem('LastName', 'Doe'); render( @@ -305,6 +325,26 @@ describe('Testing LeftDrawerOrg component for SUPERADMIN', () => { ); await wait(); expect(screen.getByTestId(/orgBtn/i)).toBeInTheDocument(); + }); + + test('Should not show org not found error when viewing admin profile', async () => { + setItem('UserImage', ''); + setItem('SuperAdmin', true); + setItem('FirstName', 'John'); + setItem('LastName', 'Doe'); + setItem('id', '123'); + render( + + + + + + + + + , + ); + await wait(); expect( screen.queryByText(/Error occured while loading Organization data/i), ).not.toBeInTheDocument(); diff --git a/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx b/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx index 3d67408168..741a83f50c 100644 --- a/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx +++ b/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx @@ -125,17 +125,15 @@ const leftDrawerOrg = ({ ) : organization == undefined ? ( !isProfilePage && ( - <> - - + ) ) : (