Added a unit test

Signed-off-by: bnechyporenko <bnechyporenko@bol.com>
This commit is contained in:
bnechyporenko
2022-05-10 10:39:13 +02:00
parent d2d41c6f13
commit 44f422e209
@@ -19,7 +19,7 @@ import { render, screen } from '@testing-library/react';
import React from 'react';
import { useAnalyticsContext } from '../analytics/AnalyticsContext';
import { useApp, ErrorBoundaryFallbackProps } from '../app';
import { createPlugin } from '../plugin';
import { AnyMetadata, createPlugin } from '../plugin';
import { createRouteRef } from '../routing';
import { getComponentData } from './componentData';
import {
@@ -36,6 +36,17 @@ const plugin = createPlugin({
id: 'my-plugin',
});
type Props = {
metadata?: AnyMetadata;
};
const customPlugin = createPlugin({
id: 'custom-plugin',
metadata: {
pluginLabel: 'initial label',
},
});
describe('extensions', () => {
it('should create a react extension with component data', () => {
const Component = () => <div />;
@@ -139,4 +150,56 @@ describe('extensions', () => {
expect(result.getByTestId('route-ref')).toHaveTextContent('some-ref');
expect(result.getByTestId('extension')).toHaveTextContent('AnalyticsSpy');
});
it('should allow for the plugin to define default labels via metadata', async () => {
const CustomPluginExtension = customPlugin.provide(
createReactExtension({
name: 'CustomPlugin',
component: {
sync: (props: Props) => {
return (
<>
<div data-testid="plugin-label">
{props.metadata?.pluginLabel}
</div>
</>
);
},
},
}),
);
const initialComponent = render(<CustomPluginExtension />);
expect(initialComponent.getByTestId('plugin-label')).toHaveTextContent(
'initial label',
);
});
it('should allow for the plugin to redefine default labels', async () => {
customPlugin.reconfigure({
pluginLabel: 'new label',
});
const CustomPluginExtension = customPlugin.provide(
createReactExtension({
name: 'CustomPlugin',
component: {
sync: (props: Props) => {
return (
<>
<div data-testid="plugin-label">
{props.metadata?.pluginLabel}
</div>
</>
);
},
},
}),
);
const updatedComponent = render(<CustomPluginExtension />);
expect(updatedComponent.getByTestId('plugin-label')).toHaveTextContent(
'new label',
);
});
});