diff --git a/packages/core-plugin-api/src/extensions/extensions.test.tsx b/packages/core-plugin-api/src/extensions/extensions.test.tsx index dcc92d9d47..5cb223cc31 100644 --- a/packages/core-plugin-api/src/extensions/extensions.test.tsx +++ b/packages/core-plugin-api/src/extensions/extensions.test.tsx @@ -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 = () =>
; @@ -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 ( + <> +
+ {props.metadata?.pluginLabel} +
+ + ); + }, + }, + }), + ); + + const initialComponent = render(); + 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 ( + <> +
+ {props.metadata?.pluginLabel} +
+ + ); + }, + }, + }), + ); + + const updatedComponent = render(); + expect(updatedComponent.getByTestId('plugin-label')).toHaveTextContent( + 'new label', + ); + }); });