Skip to content

Commit

Permalink
corrected test code
Browse files Browse the repository at this point in the history
  • Loading branch information
sethdivyansh committed Oct 30, 2024
1 parent 4543884 commit d1dddd0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
44 changes: 42 additions & 2 deletions src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -21,6 +21,10 @@ const { setItem } = useLocalStorage();
const props: InterfaceLeftDrawerProps = {
orgId: '123',
targets: [
{
name: 'Admin Profile',
url: '/member/123',
},
{
name: 'Dashboard',
url: '/orgdash/123',
Expand Down Expand Up @@ -215,6 +219,20 @@ const MOCKS_EMPTY = [
},
];

const MOCKS_EMPTY_ORGID = [
{
request: {
query: ORGANIZATIONS_LIST,
variables: { id: '' },
},
result: {
data: {
organizations: [],
},
},
},
];

const defaultScreens = [
'Dashboard',
'People',
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand All @@ -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(
<MockedProvider addTypename={false} link={linkEmptyOrgId}>
<MemoryRouter initialEntries={['/member/123']}>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LeftDrawerOrg {...props} hideDrawer={null} />
</I18nextProvider>
</Provider>
</MemoryRouter>
</MockedProvider>,
);
await wait();
expect(
screen.queryByText(/Error occured while loading Organization data/i),
).not.toBeInTheDocument();
Expand Down
20 changes: 9 additions & 11 deletions src/components/LeftDrawerOrg/LeftDrawerOrg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,15 @@ const leftDrawerOrg = ({
</>
) : organization == undefined ? (
!isProfilePage && (
<>
<button
className={`${styles.profileContainer} bg-danger text-start text-white`}
disabled
>
<div className="px-3">
<WarningAmberOutlined />
</div>
{tErrors('errorLoading', { entity: 'Organization' })}
</button>
</>
<button
className={`${styles.profileContainer} bg-danger text-start text-white`}
disabled
>
<div className="px-3">
<WarningAmberOutlined />
</div>
{tErrors('errorLoading', { entity: 'Organization' })}
</button>
)
) : (
<button className={styles.profileContainer} data-testid="OrgBtn">
Expand Down

0 comments on commit d1dddd0

Please sign in to comment.