chore: added failing test for callback form

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2024-08-05 09:20:02 +02:00
parent 0f8f6f9832
commit 765d91aa0b
2 changed files with 60 additions and 3 deletions
@@ -326,4 +326,60 @@ describe('createExtensionBlueprint', () => {
expect(true).toBe(true);
});
it('should allow providing callback for properties to set with params', () => {
const Blueprint = createExtensionBlueprint({
kind: 'test-extension',
attachTo: { id: 'test', input: 'default' },
output: [coreExtensionData.reactElement],
namespace: props => props.test,
name: props => `${props.test}-name`,
config: {
schema: props => ({
test: z => z.string().default(props.test),
}),
},
factory(params: { test: string }) {
return [coreExtensionData.reactElement(<div>{params.test}</div>)];
},
});
expect(Blueprint.make({ params: { test: 'hello' } }))
.toMatchInlineSnapshot(`
{
"$$type": "@backstage/ExtensionDefinition",
"attachTo": {
"id": "test",
"input": "default",
},
"configSchema": {
"parse": [Function],
"schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"test": {
"default": "test",
"type": "string",
},
},
"type": "object",
},
},
"disabled": false,
"factory": [Function],
"inputs": {},
"kind": "test-extension",
"name": "hello-name",
"namespace": "hello",
"output": [
[Function],
],
"toString": [Function],
"version": "v2",
}
`);
expect(true).toBe(true);
});
});
@@ -47,14 +47,14 @@ export type CreateExtensionBlueprintOptions<
UFactoryOutput extends ExtensionDataValue<any, any>,
TDataRefs extends { [name in string]: AnyExtensionDataRef },
> = {
kind: string;
namespace?: string;
kind: string | ((params: TParams) => string);
namespace?: string | ((params: TParams) => string);
attachTo: { id: string; input: string };
disabled?: boolean;
inputs?: TInputs;
output: Array<UOutput>;
config?: {
schema: TConfigSchema;
schema: TConfigSchema | ((params: TParams) => TConfigSchema);
};
factory(
params: TParams,
@@ -254,6 +254,7 @@ class ExtensionBlueprintImpl<
...this.options.config?.schema,
...args.config?.schema,
} as TConfigSchema & TExtensionConfigSchema;
return createExtension({
kind: this.options.kind,
namespace: args.namespace ?? this.options.namespace,