From a99c6f65b58dbd87f9c9a6e100c4d55e808bc0ba Mon Sep 17 00:00:00 2001 From: Akshat Date: Mon, 23 Dec 2024 00:32:27 +0530 Subject: [PATCH 1/3] Converted from Jest to Vitest --- .../OrgContribution/OrgContribution.spec.tsx | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/screens/OrgContribution/OrgContribution.spec.tsx diff --git a/src/screens/OrgContribution/OrgContribution.spec.tsx b/src/screens/OrgContribution/OrgContribution.spec.tsx new file mode 100644 index 0000000000..decac5d432 --- /dev/null +++ b/src/screens/OrgContribution/OrgContribution.spec.tsx @@ -0,0 +1,45 @@ +import React from 'react'; +import { MockedProvider } from '@apollo/react-testing'; +import { render } from '@testing-library/react'; +import { Provider } from 'react-redux'; +import { BrowserRouter } from 'react-router-dom'; +import { vi, describe, test, expect } from 'vitest'; +import { I18nextProvider } from 'react-i18next'; + +import OrgContribution from './OrgContribution'; +import { store } from 'state/store'; +import i18nForTest from 'utils/i18nForTest'; +import { StaticMockLink } from 'utils/StaticMockLink'; +const link = new StaticMockLink([], true); +async function wait(ms = 100): Promise { + await new Promise((resolve) => { + setTimeout(resolve, ms); + }); +} + +describe('Organisation Contribution Page', () => { + test('should render props and text elements test for the screen', async () => { + window.location.assign = vi.fn(); + window.location.assign('/orglist'); + + const { container } = render( + + + + + + + + + , + ); + + expect(container.textContent).not.toBe('Loading data...'); + await wait(); + expect(container.textContent).toMatch('Filter by Name'); + expect(container.textContent).toMatch('Filter by Trans. ID'); + expect(container.textContent).toMatch('Recent Stats'); + expect(container.textContent).toMatch('Contribution'); + expect(window.location).toBeAt('/orglist'); + }); +}); From a62896d706210a66ff0cb8d31be341d59207f8f7 Mon Sep 17 00:00:00 2001 From: Akshat Date: Mon, 23 Dec 2024 00:41:01 +0530 Subject: [PATCH 2/3] Converted the code from Jest to Vitest --- .../OrgContribution/OrgContribution.spec.tsx | 2 +- .../OrgContribution/OrgContribution.test.tsx | 47 ------------------- 2 files changed, 1 insertion(+), 48 deletions(-) delete mode 100644 src/screens/OrgContribution/OrgContribution.test.tsx diff --git a/src/screens/OrgContribution/OrgContribution.spec.tsx b/src/screens/OrgContribution/OrgContribution.spec.tsx index decac5d432..fbbec9ef6b 100644 --- a/src/screens/OrgContribution/OrgContribution.spec.tsx +++ b/src/screens/OrgContribution/OrgContribution.spec.tsx @@ -9,7 +9,7 @@ import { I18nextProvider } from 'react-i18next'; import OrgContribution from './OrgContribution'; import { store } from 'state/store'; import i18nForTest from 'utils/i18nForTest'; -import { StaticMockLink } from 'utils/StaticMockLink'; +import { StaticMockLink } from 'utils/StaticMockLink'; const link = new StaticMockLink([], true); async function wait(ms = 100): Promise { await new Promise((resolve) => { diff --git a/src/screens/OrgContribution/OrgContribution.test.tsx b/src/screens/OrgContribution/OrgContribution.test.tsx deleted file mode 100644 index f9f63c6807..0000000000 --- a/src/screens/OrgContribution/OrgContribution.test.tsx +++ /dev/null @@ -1,47 +0,0 @@ -import React, { act } from 'react'; -import { MockedProvider } from '@apollo/react-testing'; -import { render } from '@testing-library/react'; -import { Provider } from 'react-redux'; -import { BrowserRouter } from 'react-router-dom'; -import 'jest-location-mock'; -import { I18nextProvider } from 'react-i18next'; - -import OrgContribution from './OrgContribution'; -import { store } from 'state/store'; -import i18nForTest from 'utils/i18nForTest'; -import { StaticMockLink } from 'utils/StaticMockLink'; -const link = new StaticMockLink([], true); -async function wait(ms = 100): Promise { - await act(() => { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); - }); -} - -describe('Organisation Contribution Page', () => { - test('should render props and text elements test for the screen', async () => { - window.location.assign('/orglist'); - - const { container } = render( - - - - - - - - - , - ); - - expect(container.textContent).not.toBe('Loading data...'); - await wait(); - - expect(container.textContent).toMatch('Filter by Name'); - expect(container.textContent).toMatch('Filter by Trans. ID'); - expect(container.textContent).toMatch('Recent Stats'); - expect(container.textContent).toMatch('Contribution'); - expect(window.location).toBeAt('/orglist'); - }); -}); From 462690ccff7eebbdd6d3082438198294566b8bc0 Mon Sep 17 00:00:00 2001 From: Akshat Date: Mon, 23 Dec 2024 01:26:57 +0530 Subject: [PATCH 3/3] Converted from Jest to Vitest --- ...tion.test.tsx => OrgContribution.spec.tsx} | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) rename src/screens/OrgContribution/{OrgContribution.test.tsx => OrgContribution.spec.tsx} (80%) diff --git a/src/screens/OrgContribution/OrgContribution.test.tsx b/src/screens/OrgContribution/OrgContribution.spec.tsx similarity index 80% rename from src/screens/OrgContribution/OrgContribution.test.tsx rename to src/screens/OrgContribution/OrgContribution.spec.tsx index f9f63c6807..7087f8476a 100644 --- a/src/screens/OrgContribution/OrgContribution.test.tsx +++ b/src/screens/OrgContribution/OrgContribution.spec.tsx @@ -1,9 +1,9 @@ -import React, { act } from 'react'; +import React from 'react'; import { MockedProvider } from '@apollo/react-testing'; import { render } from '@testing-library/react'; import { Provider } from 'react-redux'; import { BrowserRouter } from 'react-router-dom'; -import 'jest-location-mock'; +import { vi, describe, test, expect } from 'vitest'; import { I18nextProvider } from 'react-i18next'; import OrgContribution from './OrgContribution'; @@ -12,15 +12,19 @@ import i18nForTest from 'utils/i18nForTest'; import { StaticMockLink } from 'utils/StaticMockLink'; const link = new StaticMockLink([], true); async function wait(ms = 100): Promise { - await act(() => { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); + await new Promise((resolve) => { + setTimeout(resolve, ms); }); } describe('Organisation Contribution Page', () => { test('should render props and text elements test for the screen', async () => { + Object.defineProperty(window, 'location', { + value: { + assign: vi.fn(), + }, + writable: true, + }); window.location.assign('/orglist'); const { container } = render( @@ -37,11 +41,10 @@ describe('Organisation Contribution Page', () => { expect(container.textContent).not.toBe('Loading data...'); await wait(); - expect(container.textContent).toMatch('Filter by Name'); expect(container.textContent).toMatch('Filter by Trans. ID'); expect(container.textContent).toMatch('Recent Stats'); expect(container.textContent).toMatch('Contribution'); - expect(window.location).toBeAt('/orglist'); + expect(window.location.assign).toHaveBeenCalledWith('/orglist'); }); });