Skip to content

Commit

Permalink
test file updated (#3002)
Browse files Browse the repository at this point in the history
  • Loading branch information
raggettii authored Dec 28, 2024
1 parent 3718fbb commit 9dbd7a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 44 deletions.
37 changes: 18 additions & 19 deletions src/App.test.tsx → src/App.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import React, { act } from 'react';
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Provider } from 'react-redux';
import { MockedProvider } from '@apollo/react-testing';
import { BrowserRouter } from 'react-router-dom';
import { I18nextProvider } from 'react-i18next';
import 'jest-location-mock';
import { describe, it, expect, vi } from 'vitest';
import App from './App';
import { store } from 'state/store';
import { CHECK_AUTH } from 'GraphQl/Queries/Queries';
import i18nForTest from './utils/i18nForTest';
import { StaticMockLink } from 'utils/StaticMockLink';
import useLocalStorage from 'utils/useLocalstorage';

const { setItem } = useLocalStorage();
vi.mock('@mui/x-charts/PieChart', () => ({
pieArcLabelClasses: vi.fn(),
PieChart: vi.fn().mockImplementation(() => <>Test</>),
pieArcClasses: vi.fn(),
}));

// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Jest)
// These modules are used by the Feedback components
jest.mock('@mui/x-charts/PieChart', () => ({
pieArcLabelClasses: jest.fn(),
PieChart: jest.fn().mockImplementation(() => <>Test</>),
pieArcClasses: jest.fn(),
vi.mock('/src/assets/svgs/palisadoes.svg?react', () => ({
default: () => <svg>Mocked SVG</svg>,
}));
vi.mock('/src/assets/svgs/talawa.svg?react', () => ({
default: () => <svg>Mocked SVG</svg>,
}));

const MOCKS = [
Expand Down Expand Up @@ -59,16 +61,13 @@ const link = new StaticMockLink(MOCKS, true);
const link2 = new StaticMockLink([], true);

async function wait(ms = 100): Promise<void> {
await act(() => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
await new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

describe('Testing the App Component', () => {
test('Component should be rendered properly and user is loggedin', async () => {
setItem('AdminFor', [{ name: 'adi', _id: '1234', image: '' }]);
it('Component should be rendered properly and user is logged in', async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand All @@ -83,17 +82,17 @@ describe('Testing the App Component', () => {

await wait();

window.location.assign('/orglist');
window.history.pushState({}, '', '/orglist');
await wait();
expect(window.location).toBeAt('/orglist');
expect(window.location.pathname).toBe('/orglist');
expect(
screen.getByText(
'An open source application by Palisadoes Foundation volunteers',
),
).toBeTruthy();
});

test('Component should be rendered properly and user is loggedout', async () => {
it('Component should be rendered properly and user is logged out', async () => {
render(
<MockedProvider addTypename={false} link={link2}>
<BrowserRouter>
Expand Down
40 changes: 15 additions & 25 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import CommunityProfile from 'screens/CommunityProfile/CommunityProfile';
import OrganizationVenues from 'screens/OrganizationVenues/OrganizationVenues';
import Leaderboard from 'screens/Leaderboard/Leaderboard';

import React, { useEffect } from 'react';
import React from 'react';
// User Portal Components
import Donate from 'screens/UserPortal/Donate/Donate';
import Events from 'screens/UserPortal/Events/Events';
Expand All @@ -39,20 +39,15 @@ import Organizations from 'screens/UserPortal/Organizations/Organizations';
import People from 'screens/UserPortal/People/People';
import Settings from 'screens/UserPortal/Settings/Settings';
import Chat from 'screens/UserPortal/Chat/Chat';
import { useQuery } from '@apollo/client';
import { CHECK_AUTH } from 'GraphQl/Queries/Queries';
import Advertisements from 'components/Advertisements/Advertisements';
import SecuredRouteForUser from 'components/UserPortal/SecuredRouteForUser/SecuredRouteForUser';

import useLocalStorage from 'utils/useLocalstorage';
import UserScreen from 'screens/UserPortal/UserScreen/UserScreen';
import EventDashboardScreen from 'components/EventDashboardScreen/EventDashboardScreen';
import Campaigns from 'screens/UserPortal/Campaigns/Campaigns';
import Pledges from 'screens/UserPortal/Pledges/Pledges';
import VolunteerManagement from 'screens/UserPortal/Volunteer/VolunteerManagement';
import LeaveOrganization from 'screens/UserPortal/LeaveOrganization/LeaveOrganization';

const { setItem } = useLocalStorage();
// const { setItem } = useLocalStorage();

/**
* This is the main function for our application. It sets up all the routes and components,
Expand Down Expand Up @@ -97,20 +92,20 @@ function app(): JSX.Element {

// TODO: Fetch Installed plugin extras and store for use within MainContent and Side Panel Components.

const { data, loading } = useQuery(CHECK_AUTH);
// const { data, loading } = useQuery(CHECK_AUTH);

useEffect(() => {
if (data) {
setItem('name', `${data.checkAuth.firstName} ${data.checkAuth.lastName}`);
setItem('id', data.checkAuth._id);
setItem('email', data.checkAuth.email);
setItem('IsLoggedIn', 'TRUE');
setItem('FirstName', data.checkAuth.firstName);
setItem('LastName', data.checkAuth.lastName);
setItem('UserImage', data.checkAuth.image);
setItem('Email', data.checkAuth.email);
}
}, [data, loading]);
// useEffect(() => {
// if (data) {
// setItem('name', `${data.checkAuth.firstName} ${data.checkAuth.lastName}`);
// setItem('id', data.checkAuth._id);
// setItem('email', data.checkAuth.email);
// setItem('IsLoggedIn', 'TRUE');
// setItem('FirstName', data.checkAuth.firstName);
// setItem('LastName', data.checkAuth.lastName);
// setItem('UserImage', data.checkAuth.image);
// setItem('Email', data.checkAuth.email);
// }
// }, [data, loading]);

const extraRoutes = Object.entries(installedPlugins).map(
(
Expand Down Expand Up @@ -199,10 +194,6 @@ function app(): JSX.Element {
<Route path="/user/events/:orgId" element={<Events />} />
<Route path="/user/campaigns/:orgId" element={<Campaigns />} />
<Route path="/user/pledges/:orgId" element={<Pledges />} />
<Route
path="/user/leaveOrg/:orgId"
element={<LeaveOrganization />}
/>
<Route
path="/user/volunteer/:orgId"
element={<VolunteerManagement />}
Expand All @@ -215,7 +206,6 @@ function app(): JSX.Element {
</Route>
</Route>
</Route>
{/* <SecuredRouteForUser path="/user/chat" component={Chat} /> */}
<Route path="*" element={<PageNotFound />} />
</Routes>
</>
Expand Down

0 comments on commit 9dbd7a6

Please sign in to comment.