frontend-plugin-api: add test for PluginWrapperApi in ExtensionBoundary
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { useEffect, ReactNode } from 'react';
|
||||
import { act, screen, waitFor } from '@testing-library/react';
|
||||
import { TestApiProvider, withLogCollector } from '@backstage/test-utils';
|
||||
import { ExtensionBoundary } from './ExtensionBoundary';
|
||||
@@ -26,6 +26,10 @@ import {
|
||||
createExtensionTester,
|
||||
renderInTestApp,
|
||||
} from '@backstage/frontend-test-utils';
|
||||
import {
|
||||
pluginWrapperApiRef,
|
||||
PluginWrapperApi,
|
||||
} from '../apis/definitions/PluginWrapperApi';
|
||||
|
||||
const wrapInBoundaryExtension = (element?: JSX.Element) => {
|
||||
const routeRef = createRouteRef();
|
||||
@@ -121,6 +125,44 @@ describe('ExtensionBoundary', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should wrap children with PluginWrapper when provided', async () => {
|
||||
const text = 'Wrapped Content';
|
||||
const TextComponent = () => {
|
||||
return <p>{text}</p>;
|
||||
};
|
||||
|
||||
const WrapperComponent = ({ children }: { children: ReactNode }) => {
|
||||
return (
|
||||
<div data-testid="plugin-wrapper">
|
||||
<span>Wrapper</span>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const pluginWrapperApi: PluginWrapperApi = {
|
||||
getPluginWrapper: jest.fn((pluginId: string) => {
|
||||
if (pluginId === 'app') {
|
||||
return WrapperComponent;
|
||||
}
|
||||
return undefined;
|
||||
}),
|
||||
};
|
||||
|
||||
renderInTestApp(
|
||||
<TestApiProvider apis={[[pluginWrapperApiRef, pluginWrapperApi]]}>
|
||||
{createExtensionTester(
|
||||
wrapInBoundaryExtension(<TextComponent />),
|
||||
).reactElement()}
|
||||
</TestApiProvider>,
|
||||
);
|
||||
|
||||
expect(await screen.findByTestId('plugin-wrapper')).toBeInTheDocument();
|
||||
expect(screen.getByText('Wrapper')).toBeInTheDocument();
|
||||
expect(screen.getByText(text)).toBeInTheDocument();
|
||||
expect(pluginWrapperApi.getPluginWrapper).toHaveBeenCalledWith('app');
|
||||
});
|
||||
|
||||
// TODO(Rugvip): Need a way to be able to override APIs in the app to be able to test this properly
|
||||
// eslint-disable-next-line jest/no-disabled-tests
|
||||
it.skip('should emit analytics events if routable', async () => {
|
||||
|
||||
Reference in New Issue
Block a user