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

Refactor : Added Vitest to Requests Screen #2653

Closed
Show file tree
Hide file tree
Changes from all commits
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
Empty file modified .github/workflows/compare_translations.py
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { act } from 'react';
import { MockedProvider } from '@apollo/react-testing';
import { render, screen } from '@testing-library/react';
import 'jest-localstorage-mock';
import 'jest-location-mock';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
Expand All @@ -22,6 +20,29 @@ import {
MOCKS4,
} from './RequestsMocks';
import useLocalStorage from 'utils/useLocalstorage';
import { vi } from 'vitest';

/**
* Unit tests for the `Requests` screen.
*
*/
/**
* Set up `localStorage` stubs for testing.
*/

vi.stubGlobal('localStorage', {
getItem: vi.fn(),
setItem: vi.fn(),
clear: vi.fn(),
removeItem: vi.fn(),
});

/**
* Mock `window.location` for testing redirection behavior.
*/
Object.defineProperty(window, 'location', {
value: { href: 'http://localhost/', assign: vi.fn(), reload: vi.fn() },
});

const { setItem, removeItem } = useLocalStorage();

Expand All @@ -33,6 +54,13 @@ const link5 = new StaticMockLink(MOCKS_WITH_ERROR, true);
const link6 = new StaticMockLink(MOCKS3, true);
const link7 = new StaticMockLink(MOCKS4, true);

/**
* Utility function to wait for a specified amount of time.
* Wraps `setTimeout` in an `act` block for testing purposes.
*
* @param ms - The duration to wait in milliseconds. Default is 100ms.
* @returns A promise that resolves after the specified time.
*/
async function wait(ms = 100): Promise<void> {
await act(() => {
return new Promise((resolve) => {
Expand All @@ -53,7 +81,6 @@ afterEach(() => {

describe('Testing Requests screen', () => {
test('Component should be rendered properly', async () => {
const loadMoreRequests = jest.fn();
render(
<MockedProvider addTypename={false} link={link7}>
<BrowserRouter>
Expand Down
Loading