Skip to content

Commit

Permalink
Merge branch 'develop-postgres' into eventregistrant-1750
Browse files Browse the repository at this point in the history
  • Loading branch information
syedali237 authored Dec 25, 2024
2 parents 72b290c + 22436b5 commit 63bffa7
Show file tree
Hide file tree
Showing 55 changed files with 2,351 additions and 1,668 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import i18nForTest from 'utils/i18nForTest';
import { I18nextProvider } from 'react-i18next';
import { toast } from 'react-toastify';
import useLocalStorage from 'utils/useLocalstorage';
import { vi } from 'vitest';

const { getItem } = useLocalStorage();

Expand Down Expand Up @@ -74,26 +75,30 @@ const pluginData = {
pluginDesc: 'Test Description',
};

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

const mockNavigate = jest.fn();
const mockNavigate = vi.fn();
let mockId: string | undefined = 'id';
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({ orgId: mockId }),
useNavigate: () => mockNavigate,
}));

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

describe('Testing AddOnRegister', () => {
const props = {
id: '6234d8bf6ud937ddk70ecc5c9',
};

test('should render modal and take info to add plugin for registered organization', async () => {
it('should render modal and take info to add plugin for registered organization', async () => {
await act(async () => {
render(
<ApolloProvider client={client}>
Expand Down Expand Up @@ -127,7 +132,7 @@ describe('Testing AddOnRegister', () => {
);
});

test('Expect toast.success to be called on successful plugin addition', async () => {
it('Expect toast.success to be called on successful plugin addition', async () => {
await act(async () => {
render(
<MockedProvider addTypename={false} mocks={mocks}>
Expand Down Expand Up @@ -158,7 +163,7 @@ describe('Testing AddOnRegister', () => {
expect(toast.success).toHaveBeenCalledWith('Plugin added Successfully');
});

test('Expect the window to reload after successful plugin addition', async () => {
it('Expect the window to reload after successful plugin addition', async () => {
await act(async () => {
render(
<MockedProvider addTypename={false} mocks={mocks}>
Expand Down Expand Up @@ -189,7 +194,7 @@ describe('Testing AddOnRegister', () => {
expect(mockNavigate).toHaveBeenCalledWith(0);
});

test('should be redirected to /orglist if orgId is undefined', async () => {
it('should be redirected to /orglist if orgId is undefined', async () => {
mockId = undefined;
render(
<ApolloProvider client={client}>
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
Expand Up @@ -7,9 +7,7 @@ import {
fireEvent,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import 'jest-localstorage-mock';
import { MockedProvider } from '@apollo/client/testing';
import 'jest-location-mock';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
Expand All @@ -24,20 +22,20 @@ import { StaticMockLink } from 'utils/StaticMockLink';
import { props, props2 } from './AgendaItemsContainerProps';
import { MOCKS, MOCKS_ERROR } from './AgendaItemsContainerMocks';
import AgendaItemsContainer from './AgendaItemsContainer';

import { describe, test, expect, vi } from 'vitest';
const link = new StaticMockLink(MOCKS, true);
const link2 = new StaticMockLink(MOCKS_ERROR, true);

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

//temporarily fixes react-beautiful-dnd droppable method's depreciation error
//needs to be fixed in React 19
jest.spyOn(console, 'error').mockImplementation((message) => {
vi.spyOn(console, 'error').mockImplementation((message) => {
if (message.includes('Support for defaultProps will be removed')) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/AgendaItems/AgendaItemsContainerProps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type AgendaItemConnectionType = 'Event';
import { vi } from 'vitest';

export const props = {
agendaItemConnection: 'Event' as AgendaItemConnectionType,
Expand Down Expand Up @@ -68,7 +69,7 @@ export const props = {
},
},
],
agendaItemRefetch: jest.fn(),
agendaItemRefetch: vi.fn(),
agendaItemCategories: [
{
_id: 'agendaCategory1',
Expand Down Expand Up @@ -96,6 +97,6 @@ export const props = {
export const props2 = {
agendaItemConnection: 'Event' as AgendaItemConnectionType,
agendaItemData: [],
agendaItemRefetch: jest.fn(),
agendaItemRefetch: vi.fn(),
agendaItemCategories: [],
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';

import AgendaItemsPreviewModal from './AgendaItemsPreviewModal';
import { describe, test, expect, vi } from 'vitest';

const mockFormState = {
title: 'Test Title',
Expand Down Expand Up @@ -44,10 +45,10 @@ describe('AgendaItemsPreviewModal', () => {
<LocalizationProvider dateAdapter={AdapterDayjs}>
<AgendaItemsPreviewModal
agendaItemPreviewModalIsOpen
hidePreviewModal={jest.fn()}
hidePreviewModal={vi.fn()}
formState={mockFormState}
showUpdateModal={jest.fn()}
toggleDeleteModal={jest.fn()}
showUpdateModal={vi.fn()}
toggleDeleteModal={vi.fn()}
t={mockT}
/>
</LocalizationProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import { store } from 'state/store';
import i18nForTest from 'utils/i18nForTest';

import { LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';

import AgendaItemsUpdateModal from './AgendaItemsUpdateModal';
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 Down Expand Up @@ -67,19 +68,19 @@ const mockAgendaItemCategories = [
},
];

const mockHideUpdateModal = jest.fn();
const mockSetFormState = jest.fn();
const mockUpdateAgendaItemHandler = jest.fn();
const mockHideUpdateModal = vi.fn();
const mockSetFormState = vi.fn();
const mockUpdateAgendaItemHandler = vi.fn();
const mockT = (key: string): string => key;

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 @@ -8,21 +8,33 @@ import { store } from 'state/store';
import { Provider } from 'react-redux';
import { I18nextProvider } from 'react-i18next';
import i18nForTest from 'utils/i18nForTest';
import { describe, expect, test, vi, afterEach } from 'vitest';
import type { Location } from '@remix-run/router';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useLocation: () => ({
pathname: '/orgstore',
state: {},
key: '',
search: '',
hash: '',
}),
}));
afterEach(() => {
vi.resetModules();
});

const currentLocation: Location = {
pathname: '/orgstore',
state: {},
key: '',
search: '',
hash: '',
};

vi.mock('react-router-dom', async (importOriginal) => {
const mod = (await importOriginal()) as object;

return {
...mod,
useLocation: () => currentLocation,
};
});

const props: InterfaceCollapsibleDropdown = {
showDropdown: true,
setShowDropdown: jest.fn(),
setShowDropdown: vi.fn(),
target: {
name: 'DropDown Category',
url: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client';
import type { NormalizedCacheObject } from '@apollo/client';
import i18nForTest from 'utils/i18nForTest';
import { BACKEND_URL } from 'Constant/constant';
import { describe, test, expect } from 'vitest';

const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({
cache: new InMemoryCache(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { BrowserRouter } from 'react-router-dom';
import { I18nextProvider } from 'react-i18next';
import i18nForTest from 'utils/i18nForTest';
import userEvent from '@testing-library/user-event';
import { vi, expect, it } from 'vitest';

describe('DynamicDropDown component', () => {
test('renders and handles selection correctly', async () => {
it('renders and handles selection correctly', async () => {
const formData = { fieldName: 'value2' };
const setFormData = jest.fn();
const setFormData = vi.fn();

render(
<BrowserRouter>
Expand Down Expand Up @@ -60,10 +61,10 @@ describe('DynamicDropDown component', () => {
expect(dropdownButton).toHaveTextContent('Label 2');
});
});
test('calls custom handleChange function when provided', async () => {
it('calls custom handleChange function when provided', async () => {
const formData = { fieldName: 'value1' };
const setFormData = jest.fn();
const customHandleChange = jest.fn();
const setFormData = vi.fn();
const customHandleChange = vi.fn();

render(
<BrowserRouter>
Expand Down Expand Up @@ -103,9 +104,9 @@ describe('DynamicDropDown component', () => {
);
expect(setFormData).not.toHaveBeenCalled();
});
test('handles keyboard navigation correctly', async () => {
it('handles keyboard navigation correctly', async () => {
const formData = { fieldName: 'value1' };
const setFormData = jest.fn();
const setFormData = vi.fn();

render(
<BrowserRouter>
Expand Down
Loading

0 comments on commit 63bffa7

Please sign in to comment.