Skip to content

Commit

Permalink
refactored: src/screens/OrgSettings from Jest to Vitest(fixes: Palisa…
Browse files Browse the repository at this point in the history
  • Loading branch information
devender18 committed Dec 10, 2024
1 parent 7255e37 commit bbce0c1
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/screens/OrgSettings/OrgSettings.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ReactElement } from 'react';
import React from 'react';
import { describe, it, expect, vi } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
Expand All @@ -18,16 +19,24 @@ const link1 = new StaticMockLink(MOCKS);

const mockRouterParams = (orgId: string | undefined): void => {
vi.doMock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom');
return {
...actual,
useParams: () => ({ orgId }),
};
try {
const actual = await vi.importActual('react-router-dom');
return {
...actual,
useParams: () => ({ orgId }),
};
} catch (error) {
console.error('Failed to mock router params:', error);
throw error;
}
});
};
const renderOrganisationSettings = (link = link1, orgId = 'orgId'): void => {
const renderOrganisationSettings = (
link = link1,
orgId = 'orgId',
): ReturnType<typeof render> => {
mockRouterParams(orgId);
render(
return render(
<MockedProvider addTypename={false} link={link}>
<MemoryRouter initialEntries={[`/orgsetting/${orgId}`]}>
<Provider store={store}>
Expand Down Expand Up @@ -55,7 +64,7 @@ describe('Organisation Settings Page', () => {
vi.unmock('react-router-dom');
});

it('should redirect to fallback URL if URL params are undefined', async () => {
const SetupRedirectTest = async (): Promise<ReactElement> => {
const useParamsMock = vi.fn(() => ({ orgId: undefined }));
vi.doMock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom');
Expand All @@ -64,16 +73,19 @@ describe('Organisation Settings Page', () => {
useParams: useParamsMock,
};
});
const orgSettingsModule = await import('./OrgSettings');
return <orgSettingsModule.default />;
};

const { default: OrgSettings } = await import('./OrgSettings');

it('should redirect to fallback URL if URL params are undefined', async () => {
const OrgSettings = await SetupRedirectTest();
render(
<MockedProvider addTypename={false}>
<MemoryRouter initialEntries={['/orgsetting/']}>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<Routes>
<Route path="/orgsetting/" element={<OrgSettings />} />
<Route path="/orgsetting/" element={OrgSettings} />
<Route
path="/"
element={
Expand Down

0 comments on commit bbce0c1

Please sign in to comment.