Skip to content

Commit

Permalink
Merge branch 'issue-2505-fixed' of https://github.com/gurramkarthikne…
Browse files Browse the repository at this point in the history
…tha/talawa-admin into issue-2505-fixed
  • Loading branch information
gurramkarthiknetha committed Dec 21, 2024
2 parents e272d33 + 1bf3ae2 commit f2d44b6
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 124 deletions.
2 changes: 0 additions & 2 deletions src/components/OrganizationScreen/OrganizationScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ describe('Testing OrganizationScreen', () => {

test('handles window resize', () => {
renderComponent();

window.innerWidth = 800;
fireEvent(window, new Event('resize'));

expect(screen.getByTestId('mainpageright')).toHaveClass(styles.expand);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,33 @@ import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import { MemoryRouter, Route, Routes, useParams } from 'react-router-dom';
import { store } from 'state/store';
import { StaticMockLink } from 'utils/StaticMockLink';
import i18n from 'utils/i18nForTest';
import OrganizationDashboard from './OrganizationDashboard';
import type { ApolloLink } from '@apollo/client';
import { MOCKS, EMPTY_MOCKS, ERROR_MOCKS } from './OrganizationDashboardMocks';
import { toast } from 'react-toastify';

jest.mock('react-toastify', () => ({
import { vi } from 'vitest';

/**
* This file contains unit tests for the OrganizationDashboard component.
*
* The tests cover:
* - Behavior when URL parameters are undefined, including redirection to fallback URLs.
* - Rendering of key sections, such as dashboard cards, upcoming events, latest posts, membership requests, and volunteer rankings.
* - Functionality of user interactions with dashboard elements (e.g., navigation via clicks on cards and buttons).
* - Handling of scenarios with empty data or errors in GraphQL responses.
* - Integration with mocked GraphQL queries and toast notifications.
*
* These tests are implemented using Vitest for test execution and MockedProvider for mocking GraphQL queries.
*/

vi.mock('react-toastify', () => ({
toast: {
success: jest.fn(),
error: jest.fn(),
success: vi.fn(),
error: vi.fn(),
},
}));

Expand Down Expand Up @@ -89,40 +103,48 @@ const renderOrganizationDashboard = (link: ApolloLink): RenderResult => {

describe('Testing Organization Dashboard Screen', () => {
beforeAll(() => {
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({ orgId: 'orgId' }),
}));
vi.mock('react-router-dom', async () => {
const originalModule = await vi.importActual('react-router-dom');
return {
...originalModule,
useParams: vi.fn(),
};
});
});

afterAll(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

it('should redirect to fallback URL if URL params are undefined', async () => {
vi.mocked(useParams).mockReturnValue({});
render(
<MockedProvider addTypename={false} link={link1}>
<MemoryRouter initialEntries={['/orgdash/']}>
<Provider store={store}>
<I18nextProvider i18n={i18n}>
<Routes>
<Route path="/orgdash/" element={<OrganizationDashboard />} />
<Route
path="/"
element={<div data-testid="paramsError"></div>}
/>
<Route path="/orgdash/" element={<OrganizationDashboard />} />
</Routes>
</I18nextProvider>
</Provider>
</MemoryRouter>
</MockedProvider>,
);
await waitFor(() => {
expect(window.location.pathname).toBe('/');
});
await waitFor(() => {
expect(screen.getByTestId('paramsError')).toBeInTheDocument();
});
});

it('should render Organization Dashboard screen', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);

// Dashboard cards
Expand Down Expand Up @@ -151,6 +173,7 @@ describe('Testing Organization Dashboard Screen', () => {
});

it('Click People Card', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);
const membersBtn = await screen.findByText(t.members);
expect(membersBtn).toBeInTheDocument();
Expand All @@ -162,13 +185,15 @@ describe('Testing Organization Dashboard Screen', () => {
});

it('Click Admin Card', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);
const adminsBtn = await screen.findByText(t.admins);
expect(adminsBtn).toBeInTheDocument();
});
});

it('Click Post Card', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);
const postsBtn = await screen.findByText(t.posts);
expect(postsBtn).toBeInTheDocument();
Expand All @@ -180,6 +205,7 @@ it('Click Post Card', async () => {
});

it('Click Events Card', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);
const eventsBtn = await screen.findByText(t.events);
expect(eventsBtn).toBeInTheDocument();
Expand All @@ -191,6 +217,7 @@ it('Click Events Card', async () => {
});

it('Click Blocked Users Card', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);
const blockedUsersBtn = await screen.findByText(t.blockedUsers);
expect(blockedUsersBtn).toBeInTheDocument();
Expand All @@ -202,6 +229,7 @@ it('Click Blocked Users Card', async () => {
});

it('Click Requests Card', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);
const requestsBtn = await screen.findByText(t.requests);
expect(requestsBtn).toBeInTheDocument();
Expand All @@ -213,6 +241,7 @@ it('Click Requests Card', async () => {
});

it('Click View All Events', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);
const viewAllBtn = await screen.findAllByText(t.viewAll);
expect(viewAllBtn[0]).toBeInTheDocument();
Expand All @@ -224,6 +253,7 @@ it('Click View All Events', async () => {
});

it('Click View All Posts', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);
const viewAllBtn = await screen.findAllByText(t.viewAll);
expect(viewAllBtn[1]).toBeInTheDocument();
Expand All @@ -235,6 +265,7 @@ it('Click View All Posts', async () => {
});

it('Click View All Requests', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);
const viewAllBtn = await screen.findAllByText(t.viewAll);
expect(viewAllBtn[2]).toBeInTheDocument();
Expand All @@ -246,6 +277,7 @@ it('Click View All Requests', async () => {
});

it('Click View All Leaderboard', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link1);
const viewAllBtn = await screen.findAllByText(t.viewAll);
expect(viewAllBtn[3]).toBeInTheDocument();
Expand All @@ -257,6 +289,7 @@ it('Click View All Leaderboard', async () => {
});

it('should render Organization Dashboard screen with empty data', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link3);

await waitFor(() => {
Expand All @@ -268,6 +301,7 @@ it('should render Organization Dashboard screen with empty data', async () => {
});

it('should redirectt to / if error occurs', async () => {
vi.mocked(useParams).mockReturnValue({ orgId: 'orgId' });
renderOrganizationDashboard(link2);

await waitFor(() => {
Expand Down
109 changes: 0 additions & 109 deletions src/screens/PageNotFound/PageNotFound.module.css

This file was deleted.

4 changes: 2 additions & 2 deletions src/screens/PageNotFound/PageNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import useLocalStorage from 'utils/useLocalstorage';

import styles from './PageNotFound.module.css';
import styles from '../../style/app.module.css';
import Logo from 'assets/images/talawa-logo-600x600.png';

/**
Expand All @@ -28,7 +28,7 @@ const PageNotFound = (): JSX.Element => {
const adminFor = getItem('AdminFor');

return (
<section className={styles.notfound}>
<section className={styles.pageNotFound}>
<div className="container text-center">
<div className="brand">
<img src={Logo} alt="Logo" className="img-fluid" />
Expand Down
Loading

0 comments on commit f2d44b6

Please sign in to comment.