Incorporated the feedback.
Signed-off-by: bnechyporenko <bnechyporenko@bol.com>
This commit is contained in:
@@ -17,13 +17,15 @@
|
||||
import React from 'react';
|
||||
import { renderHook } from '@testing-library/react-hooks';
|
||||
import { usePluginOptions, PluginProvider } from './usePluginOptions';
|
||||
import { createPlugin, PluginOptions } from '../plugin';
|
||||
import { createPlugin, PluginInputOptions, PluginOptions } from '../plugin';
|
||||
|
||||
describe('usePluginOptions', () => {
|
||||
it('should provide a versioned value to hook', () => {
|
||||
const plugin = createPlugin({
|
||||
id: 'my-plugin',
|
||||
options: { 'key-1': 'value-1', 'key-2': 'value-2' },
|
||||
__experimentalConfigure(_: PluginInputOptions): PluginOptions {
|
||||
return { 'key-1': 'value-1', 'key-2': 'value-2' };
|
||||
},
|
||||
});
|
||||
|
||||
const rendered = renderHook(() => usePluginOptions(), {
|
||||
@@ -32,11 +34,9 @@ describe('usePluginOptions', () => {
|
||||
),
|
||||
});
|
||||
|
||||
const config = rendered.result.current.config as unknown as {
|
||||
options: PluginOptions;
|
||||
};
|
||||
const config = rendered.result.current;
|
||||
|
||||
expect(config.options).toEqual({
|
||||
expect(config).toEqual({
|
||||
'key-1': 'value-1',
|
||||
'key-2': 'value-2',
|
||||
});
|
||||
|
||||
@@ -36,6 +36,8 @@ export class PluginImpl<
|
||||
{
|
||||
constructor(private readonly config: PluginConfig<Routes, ExternalRoutes>) {}
|
||||
|
||||
options: PluginOptions | undefined = undefined;
|
||||
|
||||
getId(): string {
|
||||
return this.config.id;
|
||||
}
|
||||
@@ -62,15 +64,15 @@ export class PluginImpl<
|
||||
|
||||
__experimentalReconfigure(options: PluginInputOptions): void {
|
||||
if (this.config.__experimentalConfigure) {
|
||||
this.config.options = this.config.__experimentalConfigure(options);
|
||||
this.options = this.config.__experimentalConfigure(options);
|
||||
}
|
||||
}
|
||||
|
||||
getPluginOptions(): PluginOptions {
|
||||
if (this.config.__experimentalConfigure && !this.config.options) {
|
||||
this.config.options = this.config.__experimentalConfigure();
|
||||
if (this.config.__experimentalConfigure && !this.options) {
|
||||
this.options = this.config.__experimentalConfigure();
|
||||
}
|
||||
return this.config.options ?? ({} as PluginOptions);
|
||||
return this.options ?? ({} as PluginOptions);
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
||||
@@ -97,7 +97,6 @@ export type PluginConfig<
|
||||
routes?: Routes;
|
||||
externalRoutes?: ExternalRoutes;
|
||||
featureFlags?: PluginFeatureFlagConfig[];
|
||||
options?: PluginOptions;
|
||||
__experimentalConfigure?(options?: PluginInputOptions): PluginOptions;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user