Skip to content

Commit

Permalink
test: add queryclientprovider to fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed May 2, 2024
1 parent 22084d4 commit c0404ae
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
11 changes: 8 additions & 3 deletions src/CourseAuthoringPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MockAdapter from 'axios-mock-adapter';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { AppProvider } from '@edx/frontend-platform/react';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
import initializeStore from './store';
import CourseAuthoringPage from './CourseAuthoringPage';
import PagesAndResources from './pages-and-resources/PagesAndResources';
Expand Down Expand Up @@ -38,6 +39,8 @@ beforeEach(() => {
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
});

const queryClient = new QueryClient();

describe('Editor Pages Load no header', () => {
const mockStoreSuccess = async () => {
const apiBaseUrl = getConfig().STUDIO_BASE_URL;
Expand All @@ -53,9 +56,11 @@ describe('Editor Pages Load no header', () => {
const wrapper = render(
<AppProvider store={store}>
<IntlProvider locale="en">
<CourseAuthoringPage courseId={courseId}>
<PagesAndResources courseId={courseId} />
</CourseAuthoringPage>
<QueryClientProvider client={queryClient}>
<CourseAuthoringPage courseId={courseId}>
<PagesAndResources courseId={courseId} />
</CourseAuthoringPage>
</QueryClientProvider>
</IntlProvider>
</AppProvider>
,
Expand Down
15 changes: 12 additions & 3 deletions src/CourseAuthoringRoutes.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { AppProvider } from '@edx/frontend-platform/react';
import { initializeMockApp } from '@edx/frontend-platform';
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import CourseAuthoringRoutes from './CourseAuthoringRoutes';
Expand Down Expand Up @@ -48,6 +49,8 @@ jest.mock('./custom-pages/CustomPages', () => (props) => {
return customPagesMockText;
});

const queryClient = new QueryClient();

describe('<CourseAuthoringRoutes>', () => {
beforeEach(() => {
initializeMockApp({
Expand All @@ -65,7 +68,9 @@ describe('<CourseAuthoringRoutes>', () => {
render(
<AppProvider store={store} wrapWithRouter={false}>
<MemoryRouter initialEntries={['/pages-and-resources']}>
<CourseAuthoringRoutes />
<QueryClientProvider client={queryClient}>
<CourseAuthoringRoutes />
</QueryClientProvider>
</MemoryRouter>
</AppProvider>,
);
Expand All @@ -82,7 +87,9 @@ describe('<CourseAuthoringRoutes>', () => {
render(
<AppProvider store={store} wrapWithRouter={false}>
<MemoryRouter initialEntries={['/editor/video/block-id']}>
<CourseAuthoringRoutes />
<QueryClientProvider client={queryClient}>
<CourseAuthoringRoutes />
</QueryClientProvider>
</MemoryRouter>
</AppProvider>,
);
Expand All @@ -100,7 +107,9 @@ describe('<CourseAuthoringRoutes>', () => {
render(
<AppProvider store={store} wrapWithRouter={false}>
<MemoryRouter initialEntries={['/editor/course-videos/block-id']}>
<CourseAuthoringRoutes />
<QueryClientProvider client={queryClient}>
<CourseAuthoringRoutes />
</QueryClientProvider>
</MemoryRouter>
</AppProvider>,
);
Expand Down
7 changes: 6 additions & 1 deletion src/accessibility-page/AccessibilityPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import { AppProvider } from '@edx/frontend-platform/react';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { initializeMockApp } from '@edx/frontend-platform';
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
import initializeStore from '../store';
import AccessibilityPage from './index';

Expand All @@ -15,11 +16,15 @@ const initialState = {
};
let store;

const queryClient = new QueryClient();

const renderComponent = () => {
render(
<IntlProvider locale="en">
<AppProvider store={store}>
<AccessibilityPage />
<QueryClientProvider client={queryClient}>
<AccessibilityPage />
</QueryClientProvider>
</AppProvider>
</IntlProvider>,
);
Expand Down
11 changes: 8 additions & 3 deletions src/course-rerun/CourseRerun.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSelector } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { initializeMockApp } from '@edx/frontend-platform';
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n';
import { AppProvider } from '@edx/frontend-platform/react';
import {
Expand Down Expand Up @@ -33,12 +34,16 @@ jest.mock('react-router-dom', () => ({
}),
}));

const queryClient = new QueryClient();

const RootWrapper = () => (
<MemoryRouter>
<AppProvider store={store} wrapWithRouter={false}>
<IntlProvider locale="en">
<CourseRerun intl={injectIntl} />
</IntlProvider>
<QueryClientProvider client={queryClient}>
<IntlProvider locale="en">
<CourseRerun intl={injectIntl} />
</IntlProvider>
</QueryClientProvider>
</AppProvider>
</MemoryRouter>
);
Expand Down
11 changes: 8 additions & 3 deletions src/studio-home/StudioHome.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSelector } from 'react-redux';
import { initializeMockApp } from '@edx/frontend-platform';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n';
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
import { AppProvider } from '@edx/frontend-platform/react';
import {
act, fireEvent, render, waitFor,
Expand Down Expand Up @@ -41,11 +42,15 @@ jest.mock('react-router-dom', () => ({
}),
}));

const queryClient = new QueryClient();

const RootWrapper = () => (
<AppProvider store={store}>
<IntlProvider locale="en" messages={{}}>
<StudioHome intl={injectIntl} />
</IntlProvider>
<QueryClientProvider client={queryClient}>
<IntlProvider locale="en" messages={{}}>
<StudioHome intl={injectIntl} />
</IntlProvider>
</QueryClientProvider>
</AppProvider>
);

Expand Down

0 comments on commit c0404ae

Please sign in to comment.