Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…dmin into setup
  • Loading branch information
VanshikaSabharwal committed Dec 25, 2024
2 parents 876b032 + 7270b0c commit dde6967
Show file tree
Hide file tree
Showing 61 changed files with 4,335 additions and 2,808 deletions.
3 changes: 3 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,9 @@
"userPledges": {
"title": "My Pledges"
},
"leaveOrganization": {
"title": "Leave Organization"
},
"eventVolunteers": {
"volunteers": "Volunteers",
"volunteer": "Volunteer",
Expand Down
3 changes: 3 additions & 0 deletions public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,9 @@
"userPledges": {
"title": "Mes Promesses"
},
"leaveOrganization": {
"title": "Quitter l'organisation"
},
"eventVolunteers": {
"volunteers": "Bénévoles",
"volunteer": "Bénévole",
Expand Down
3 changes: 3 additions & 0 deletions public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,9 @@
"userPledges": {
"title": "मेरी प्रतिज्ञाएँ"
},
"leaveOrganization": {
"title": "संगठन छोड़ें"
},
"eventVolunteers": {
"volunteers": "स्वयंसेवक",
"volunteer": "स्वयंसेवक",
Expand Down
3 changes: 3 additions & 0 deletions public/locales/sp/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,9 @@
"userPledges": {
"title": "Mis Promesas"
},
"leaveOrganization": {
"title": "Dejar la organización"
},
"eventVolunteers": {
"volunteers": "Voluntarios",
"volunteer": "Voluntario",
Expand Down
3 changes: 3 additions & 0 deletions public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,9 @@
"userPledges": {
"title": "我的承诺"
},
"leaveOrganization": {
"title": "离开组织"
},
"eventVolunteers": {
"volunteers": "志愿者",
"volunteer": "志愿者",
Expand Down
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import EventDashboardScreen from 'components/EventDashboardScreen/EventDashboard
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();

Expand Down Expand Up @@ -198,6 +199,10 @@ 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 Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { render } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';

Expand All @@ -11,7 +12,7 @@ describe('Testing MainContent component', () => {
children: 'This is a dummy text',
};

test('should render props and children for the Main Content', () => {
it('should render props and children for the Main Content', () => {
const { getByTestId, getByText } = render(
<BrowserRouter>
<Provider store={store}>
Expand All @@ -20,7 +21,7 @@ describe('Testing MainContent component', () => {
</BrowserRouter>,
);

expect(getByTestId('mainContentCheck')).toBeInTheDocument();
expect(getByText(props.children)).toBeInTheDocument();
expect(getByTestId('mainContentCheck')).not.toBeNull();
expect(getByText(props.children)).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import PluginHelper from './Plugin.helper';
import { vi } from 'vitest';

/**
* This file contains unit tests for the PluginHelper component.
*
* The tests cover:
* - Verification that the class contains the required method definitions.
* - Correct functionality of the `generateLinks` method, including returning proper objects.
* - Proper behavior of the `fetchStore` method, including handling of mocked JSON responses.
* - Functionality of the `fetchInstalled` method, verifying it returns the expected JSON data.
*
* These tests use Vitest for test execution and mock the global `fetch` function for asynchronous tests.
*/

describe('Testing src/components/AddOn/support/services/Plugin.helper.ts', () => {
test('Class should contain the required method definitions', () => {
it('Class should contain the required method definitions', () => {
const pluginHelper = new PluginHelper();
expect(pluginHelper).toHaveProperty('fetchStore');
expect(pluginHelper).toHaveProperty('fetchInstalled');
expect(pluginHelper).toHaveProperty('generateLinks');
expect(pluginHelper).toHaveProperty('generateLinks');
});
test('generateLinks should return proper objects', () => {
it('generateLinks should return proper objects', () => {
const obj = {
enabled: true,
name: 'demo',
Expand All @@ -28,9 +41,9 @@ describe('Testing src/components/AddOn/support/services/Plugin.helper.ts', () =>
});
it('fetchStore should return expected JSON', async () => {
const helper = new PluginHelper();
const spy = jest.spyOn(global, 'fetch').mockImplementation(() => {
const spy = vi.spyOn(global, 'fetch').mockImplementation(() => {
const response = new Response();
response.json = jest
response.json = vi
.fn()
.mockReturnValue(Promise.resolve({ data: 'mock data' }));
return Promise.resolve(response);
Expand All @@ -46,11 +59,11 @@ describe('Testing src/components/AddOn/support/services/Plugin.helper.ts', () =>
{ name: 'plugin1', component: 'Component1', enabled: true },
{ name: 'plugin2', component: 'Component2', enabled: false },
];
jest.spyOn(global, 'fetch').mockImplementation(() => {
vi.spyOn(global, 'fetch').mockImplementation(() => {
const response = new Response();
response.json = jest.fn().mockReturnValue(Promise.resolve(mockResponse));
response.json = vi.fn().mockReturnValue(Promise.resolve(mockResponse));
return Promise.resolve(response);
}) as jest.Mock;
});
const result = await pluginHelper.fetchInstalled();
expect(result).toEqual(mockResponse);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { act } from 'react';
import { describe, test, expect, vi } from 'vitest';

import {
ApolloClient,
ApolloLink,
Expand All @@ -7,25 +9,28 @@ import {
InMemoryCache,
} from '@apollo/client';
import { MockedProvider } from '@apollo/client/testing';

import { fireEvent, render, screen } from '@testing-library/react';
import 'jest-location-mock';

import type { DocumentNode, NormalizedCacheObject } from '@apollo/client';
import userEvent from '@testing-library/user-event';
import { BACKEND_URL } from 'Constant/constant';
import { ADD_ADVERTISEMENT_MUTATION } from 'GraphQl/Mutations/mutations';

import { ADD_ADVERTISEMENT_MUTATION } from '../../GraphQl/Mutations/mutations';
import {
ORGANIZATIONS_LIST,
ORGANIZATION_ADVERTISEMENT_LIST,
PLUGIN_GET,
} from 'GraphQl/Queries/Queries';
} from '../../GraphQl/Queries/Queries';

import { I18nextProvider } from 'react-i18next';

import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import { ToastContainer } from 'react-toastify';
import { store } from 'state/store';
import i18nForTest from 'utils/i18nForTest';
import useLocalStorage from 'utils/useLocalstorage';
import { store } from '../../state/store';
import i18nForTest from '../../utils/i18nForTest';
import useLocalStorage from '../../utils/useLocalstorage';
import Advertisement from './Advertisements';

const { getItem } = useLocalStorage();
Expand All @@ -50,18 +55,22 @@ const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({
link: ApolloLink.from([httpLink]),
});

jest.mock('components/AddOn/support/services/Plugin.helper', () => ({
vi.mock('components/AddOn/support/services/Plugin.helper', () => ({
__esModule: true,
default: jest.fn().mockImplementation(() => ({
fetchInstalled: jest.fn().mockResolvedValue([]),
fetchStore: jest.fn().mockResolvedValue([]),
default: vi.fn().mockImplementation(() => ({
fetchInstalled: vi.fn().mockResolvedValue([]),
fetchStore: vi.fn().mockResolvedValue([]),
})),
}));
let mockID: string | undefined = '1';
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({ orgId: mockID }),
}));

vi.mock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom');
return {
...actual,
useParams: () => ({ orgId: mockID }),
};
});

const today = new Date();
const tomorrow = today;
Expand Down Expand Up @@ -466,18 +475,16 @@ describe('Testing Advertisement Component', () => {
/\b(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d{1,2})\s+(\d{4})\b/,
);
let dateObject = new Date();

if (dateMatch) {
const monthName = dateMatch[1];
const day = parseInt(dateMatch[2], 10);
const year = parseInt(dateMatch[3], 10);

const monthIndex =
'JanFebMarAprMayJunJulAugSepOctNovDec'.indexOf(monthName) / 3;

dateObject = new Date(year, monthIndex, day);
}

console.log(dateObject);
expect(dateObject.getTime()).toBeLessThan(new Date().getTime());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import AgendaItemsCreateModal from './AgendaItemsCreateModal';
import { toast } from 'react-toastify';
import convertToBase64 from 'utils/convertToBase64';
import type { MockedFunction } from 'vitest';
import { describe, test, expect, vi } from 'vitest';

const mockFormState = {
title: 'Test Title',
Expand All @@ -28,9 +30,9 @@ const mockFormState = {
urls: ['https://example.com'],
agendaItemCategoryIds: ['category'],
};
const mockHideCreateModal = jest.fn();
const mockSetFormState = jest.fn();
const mockCreateAgendaItemHandler = jest.fn();
const mockHideCreateModal = vi.fn();
const mockSetFormState = vi.fn();
const mockCreateAgendaItemHandler = vi.fn();
const mockT = (key: string): string => key;
const mockAgendaItemCategories = [
{
Expand Down Expand Up @@ -64,14 +66,14 @@ const mockAgendaItemCategories = [
},
},
];
jest.mock('react-toastify', () => ({
vi.mock('react-toastify', () => ({
toast: {
success: jest.fn(),
error: jest.fn(),
success: vi.fn(),
error: vi.fn(),
},
}));
jest.mock('utils/convertToBase64');
const mockedConvertToBase64 = convertToBase64 as jest.MockedFunction<
vi.mock('utils/convertToBase64');
const mockedConvertToBase64 = convertToBase64 as MockedFunction<
typeof convertToBase64
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import { LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { MockedProvider } from '@apollo/react-testing';
import { checkInMutationSuccess, checkInMutationUnsuccess } from './mocks';
import { vi } from 'vitest';

/**
* Test suite for the `TableRow` component, focusing on the CheckIn table functionality.
*/

describe('Testing Table Row for CheckIn Table', () => {
beforeEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

test('If the user is not checked in, button to check in should be displayed, and the user should be able to check in successfully', async () => {
Expand All @@ -26,7 +31,7 @@ describe('Testing Table Row for CheckIn Table', () => {
checkIn: null,
eventId: `event123`,
},
refetch: jest.fn(),
refetch: vi.fn(),
};

const { findByText } = render(
Expand Down Expand Up @@ -63,7 +68,7 @@ describe('Testing Table Row for CheckIn Table', () => {
},
eventId: 'event123',
},
refetch: jest.fn(),
refetch: vi.fn(),
};

const { findByText } = render(
Expand All @@ -81,8 +86,8 @@ describe('Testing Table Row for CheckIn Table', () => {
</BrowserRouter>,
);

global.URL.createObjectURL = jest.fn(() => 'mockURL');
global.window.open = jest.fn();
global.URL.createObjectURL = vi.fn(() => 'mockURL');
global.window.open = vi.fn();

expect(await findByText('Checked In')).toBeInTheDocument();
expect(await findByText('Download Tag')).toBeInTheDocument();
Expand All @@ -93,7 +98,7 @@ describe('Testing Table Row for CheckIn Table', () => {
expect(await findByText('PDF generated successfully!')).toBeInTheDocument();

// Cleanup mocks
jest.clearAllMocks();
vi.clearAllMocks();
});

test('Upon failing of check in mutation, the appropriate error message should be shown', async () => {
Expand All @@ -105,7 +110,7 @@ describe('Testing Table Row for CheckIn Table', () => {
checkIn: null,
eventId: `event123`,
},
refetch: jest.fn(),
refetch: vi.fn(),
};

const { findByText } = render(
Expand Down Expand Up @@ -143,7 +148,7 @@ describe('Testing Table Row for CheckIn Table', () => {
},
eventId: `event123`,
},
refetch: jest.fn(),
refetch: vi.fn(),
};

const { findByText } = render(
Expand All @@ -162,8 +167,8 @@ describe('Testing Table Row for CheckIn Table', () => {
);

// Mocking the PDF generation function to throw an error
global.URL.createObjectURL = jest.fn(() => 'mockURL');
global.window.open = jest.fn();
global.URL.createObjectURL = vi.fn(() => 'mockURL');
global.window.open = vi.fn();

fireEvent.click(await findByText('Download Tag'));

Expand Down
Loading

0 comments on commit dde6967

Please sign in to comment.