Add tests for user-provided ThemeProvider

Signed-off-by: minkimcello <minkimcello@gmail.com>
This commit is contained in:
minkimcello
2021-09-15 16:55:34 -04:00
parent 89646ee65a
commit d3fbe7a782
2 changed files with 32 additions and 3 deletions
@@ -33,6 +33,7 @@ import {
createRoutableExtension,
} from '@backstage/core-plugin-api';
import { generateBoundRoutes, PrivateAppImpl } from './App';
import { AppThemeProvider } from './AppThemeProvider';
describe('generateBoundRoutes', () => {
it('runs happy path', () => {
@@ -160,6 +161,7 @@ describe('Integration Test', () => {
Progress: () => null,
Router: BrowserRouter,
ErrorBoundaryFallback: () => null,
ThemeProvider: AppThemeProvider,
};
it('runs happy paths', async () => {
@@ -14,10 +14,16 @@
* limitations under the License.
*/
import { render } from '@testing-library/react';
import React from 'react';
import { render, screen } from '@testing-library/react';
import { renderWithEffects } from '@backstage/test-utils';
import React, { PropsWithChildren } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { defaultConfigLoader, OptionallyWrapInRouter } from './createApp';
import {
defaultConfigLoader,
OptionallyWrapInRouter,
createApp,
} from './createApp';
import { AppThemeProvider } from './AppThemeProvider';
(process as any).env = { NODE_ENV: 'test' };
const anyEnv = process.env as any;
@@ -115,3 +121,24 @@ describe('OptionallyWrapInRouter', () => {
expect(getByText('Test')).toBeInTheDocument();
});
});
describe('Optional ThemeProvider', () => {
it('should render app with user-provided ThemeProvider', async () => {
const components = {
NotFoundErrorPage: () => null,
BootErrorPage: () => null,
Progress: () => null,
Router: MemoryRouter,
ErrorBoundaryFallback: () => null,
ThemeProvider: ({ children }: PropsWithChildren<{}>) => (
<main role="main">{children}</main>
),
};
const App = createApp({ components }).getProvider();
await renderWithEffects(<App />);
expect(screen.getByRole('main')).toBeInTheDocument();
});
});