Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update and rename Settings.test.tsx to Settings.spec.tsx fixes #2579 #2718

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { act } from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { describe, expect, beforeAll, vi } from 'vitest';
import { render, screen, fireEvent, act } from '@testing-library/react';
import { MockedProvider } from '@apollo/react-testing';
import { I18nextProvider } from 'react-i18next';
import { UPDATE_USER_MUTATION } from 'GraphQl/Mutations/mutations';
Expand Down Expand Up @@ -119,31 +120,29 @@ const resizeWindow = (width: number): void => {

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

describe('Testing Settings Screen [User Portal]', () => {
// Mock implementation of matchMedia
beforeAll(() => {
vi.useFakeTimers();
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
addListener: vi.fn(), // Deprecated
removeListener: vi.fn(), // Deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
IITI-tushar marked this conversation as resolved.
Show resolved Hide resolved
});
});

test('Screen should be rendered properly', async () => {
it('Screen should be rendered properly', async () => {
await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
Expand All @@ -163,7 +162,7 @@ describe('Testing Settings Screen [User Portal]', () => {
expect(screen.queryAllByText('Settings')).not.toBe([]);
});

test('input works properly', async () => {
it('input works properly', async () => {
await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
Expand Down Expand Up @@ -220,7 +219,7 @@ describe('Testing Settings Screen [User Portal]', () => {
expect(screen.getByTestId('profile-picture')).toBeInTheDocument();
});

test('resetChangesBtn works properly', async () => {
it('resetChangesBtn works properly', async () => {
await act(async () => {
render(
<MockedProvider addTypename={false} link={link1}>
Expand Down Expand Up @@ -253,7 +252,7 @@ describe('Testing Settings Screen [User Portal]', () => {
expect(screen.getByLabelText('Birth Date')).toHaveValue('2024-03-01');
});

test('resetChangesBtn works properly when the details are empty', async () => {
it('resetChangesBtn works properly when the details are empty', async () => {
await act(async () => {
render(
<MockedProvider addTypename={false} link={link2}>
Expand Down Expand Up @@ -286,7 +285,7 @@ describe('Testing Settings Screen [User Portal]', () => {
expect(screen.getByLabelText('Birth Date')).toHaveValue('');
});

test('sidebar', async () => {
it('sidebar', async () => {
await act(async () => {
render(
<MockedProvider addTypename={false} link={link2}>
Expand All @@ -311,7 +310,7 @@ describe('Testing Settings Screen [User Portal]', () => {
act(() => openMenuBtn.click());
});

test('Testing sidebar when the screen size is less than or equal to 820px', async () => {
it('Testing sidebar when the screen size is less than or equal to 820px', async () => {
resizeWindow(800);
await act(async () => {
render(
Expand All @@ -328,7 +327,6 @@ describe('Testing Settings Screen [User Portal]', () => {
});

await wait();

screen.debug();

const openMenuBtn = screen.queryByTestId('openMenu');
Expand All @@ -348,7 +346,7 @@ describe('Testing Settings Screen [User Portal]', () => {
}
});

test('renders events attended card correctly', async () => {
it('renders events attended card correctly', async () => {
render(
<MockedProvider addTypename={false} link={link2}>
<BrowserRouter>
Expand All @@ -368,7 +366,7 @@ describe('Testing Settings Screen [User Portal]', () => {
expect(screen.getByText('No Events Attended')).toBeInTheDocument();
});

test('renders events attended card correctly with events', async () => {
it('renders events attended card correctly with events', async () => {
const mockEventsAttended = [
{ _id: '1', title: 'Event 1' },
{ _id: '2', title: 'Event 2' },
Expand Down
Loading