frontend-test-utils: add initial routes option and default config for renderInTestApp
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/frontend-test-utils': patch
|
||||
---
|
||||
|
||||
Added a `initialRouteEntries` option to `renderInTestApp`.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/frontend-test-utils': patch
|
||||
---
|
||||
|
||||
The `renderInTestApp` helper now provides a default mock config with mock values for both `app.baseUrl` and `backend.baseUrl`.
|
||||
@@ -36,6 +36,11 @@ import {
|
||||
} from '@backstage/frontend-plugin-api';
|
||||
import appPlugin from '@backstage/plugin-app';
|
||||
|
||||
const DEFAULT_MOCK_CONFIG = {
|
||||
app: { baseUrl: 'http://localhost:3000' },
|
||||
backend: { baseUrl: 'http://localhost:7007' },
|
||||
};
|
||||
|
||||
/**
|
||||
* Options to customize the behavior of the test app.
|
||||
* @public
|
||||
@@ -73,6 +78,11 @@ export type TestAppOptions = {
|
||||
* Additional features to add to the test app.
|
||||
*/
|
||||
features?: FrontendFeature[];
|
||||
|
||||
/**
|
||||
* Initial route entries to use for the router.
|
||||
*/
|
||||
initialRouteEntries?: string[];
|
||||
};
|
||||
|
||||
const NavItem = (props: {
|
||||
@@ -150,7 +160,11 @@ export function renderInTestApp(
|
||||
}),
|
||||
RouterBlueprint.make({
|
||||
params: {
|
||||
Component: ({ children }) => <MemoryRouter>{children}</MemoryRouter>,
|
||||
Component: ({ children }) => (
|
||||
<MemoryRouter initialEntries={options?.initialRouteEntries}>
|
||||
{children}
|
||||
</MemoryRouter>
|
||||
),
|
||||
},
|
||||
}),
|
||||
];
|
||||
@@ -197,7 +211,10 @@ export function renderInTestApp(
|
||||
const app = createSpecializedApp({
|
||||
features,
|
||||
config: ConfigReader.fromConfigs([
|
||||
{ context: 'render-config', data: options?.config ?? {} },
|
||||
{
|
||||
context: 'render-config',
|
||||
data: options?.config ?? DEFAULT_MOCK_CONFIG,
|
||||
},
|
||||
]),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user