Skip to content

Commit

Permalink
fix: add ToastContainer to render helper function in library (#14159)
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren authored Nov 25, 2024
1 parent 7afbaa4 commit ab1a970
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mockPagesConfig } from '../../mocks/mockPagesConfig';
import { textMock } from '@studio/testing/mocks/i18nMock';
import { RouterContext } from '../contexts/RouterContext';
import type { PageName } from '../types/PageName';
import { renderWithBrowserRouter } from '../../test-utils/renderWithBrowserRouter';
import { renderWithProviders } from '../../test-utils/renderWithProviders';

const navigateMock = jest.fn();

Expand Down Expand Up @@ -52,7 +52,7 @@ describe('ContentLibrary', () => {
});

const renderContentLibrary = (currentPage: PageName = undefined) => {
renderWithBrowserRouter(
renderWithProviders(
<RouterContext.Provider value={{ currentPage, navigate: navigateMock }}>
<ContentLibrary pages={mockPagesConfig} />
</RouterContext.Provider>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PagesRouter } from './PagesRouter';
import { textMock } from '@studio/testing/mocks/i18nMock';
import { RouterContext } from '../../../contexts/RouterContext';
import type { PageName } from '../../../types/PageName';
import { renderWithBrowserRouter } from '../../../../test-utils/renderWithBrowserRouter';
import { renderWithProviders } from '../../../../test-utils/renderWithProviders';

const navigateMock = jest.fn();

Expand Down Expand Up @@ -35,7 +35,7 @@ describe('PagesRouter', () => {
});

const renderPagesRouter = (pageNames: PageName[] = ['codeList', 'images']) => {
renderWithBrowserRouter(
renderWithProviders(
<RouterContext.Provider value={{ currentPage: 'codeList', navigate: navigateMock }}>
<PagesRouter pageNames={pageNames} />
</RouterContext.Provider>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { screen } from '@testing-library/react';
import type { PagesConfig } from '../types/PagesProps';
import { ResourceContentLibraryImpl } from './ContentResourceLibraryImpl';
import { textMock } from '@studio/testing/mocks/i18nMock';
import { renderWithBrowserRouter } from '../../test-utils/renderWithBrowserRouter';
import { renderWithProviders } from '../../test-utils/renderWithProviders';

describe('ContentResourceLibraryImpl', () => {
it('renders ContentResourceLibraryImpl with given pages', () => {
Expand Down Expand Up @@ -53,5 +53,5 @@ describe('ContentResourceLibraryImpl', () => {
const renderContentResourceLibraryImpl = (pages: PagesConfig) => {
const contentResourceLibraryImpl = new ResourceContentLibraryImpl({ pages });
const { getContentResourceLibrary } = contentResourceLibraryImpl;
renderWithBrowserRouter(getContentResourceLibrary());
renderWithProviders(getContentResourceLibrary());
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ReactNode } from 'react';
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import type { RenderResult } from '@testing-library/react';
import { render } from '@testing-library/react';
import { ToastContainer, Slide } from 'react-toastify';

export function renderWithProviders(component: ReactNode): RenderResult {
return render(
<>
<ToastContainer position='top-center' theme='colored' transition={Slide} draggable={false} />
<BrowserRouter>{component}</BrowserRouter>
</>,
);
}

0 comments on commit ab1a970

Please sign in to comment.