chore: reflect a data container
Signed-off-by: blam <ben@blam.sh> Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
import { AnalyticsApi } from '@backstage/frontend-plugin-api';
|
||||
import { AnalyticsEvent } from '@backstage/frontend-plugin-api';
|
||||
import { AnyExtensionDataRef } from '@backstage/frontend-plugin-api';
|
||||
import { AppNode } from '@backstage/frontend-plugin-api';
|
||||
import { AppNodeInstance } from '@backstage/frontend-plugin-api';
|
||||
import { ErrorWithContext } from '@backstage/test-utils';
|
||||
@@ -30,20 +31,30 @@ import { TestApiRegistry } from '@backstage/test-utils';
|
||||
import { withLogCollector } from '@backstage/test-utils';
|
||||
|
||||
// @public (undocumented)
|
||||
export function createExtensionTester<TConfig>(
|
||||
subject: ExtensionDefinition<TConfig>,
|
||||
export function createExtensionTester<
|
||||
TConfig,
|
||||
TConfigInput,
|
||||
UOutput extends AnyExtensionDataRef,
|
||||
>(
|
||||
subject: ExtensionDefinition<TConfig, TConfigInput, UOutput>,
|
||||
options?: {
|
||||
config?: TConfig;
|
||||
config?: TConfigInput;
|
||||
},
|
||||
): ExtensionTester;
|
||||
): ExtensionTester<UOutput>;
|
||||
|
||||
export { ErrorWithContext };
|
||||
|
||||
// @public (undocumented)
|
||||
export class ExtensionQuery {
|
||||
export class ExtensionQuery<UOutput extends AnyExtensionDataRef> {
|
||||
constructor(node: AppNode);
|
||||
// (undocumented)
|
||||
get<T>(ref: ExtensionDataRef<T>): T | undefined;
|
||||
get<TId extends UOutput['id']>(
|
||||
ref: ExtensionDataRef<any, TId, any>,
|
||||
): UOutput extends ExtensionDataRef<infer IData, TId, infer IConfig>
|
||||
? IConfig['optional'] extends true
|
||||
? IData | undefined
|
||||
: IData
|
||||
: never;
|
||||
// (undocumented)
|
||||
get instance(): AppNodeInstance;
|
||||
// (undocumented)
|
||||
@@ -51,18 +62,26 @@ export class ExtensionQuery {
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export class ExtensionTester {
|
||||
export class ExtensionTester<UOutput extends AnyExtensionDataRef> {
|
||||
// (undocumented)
|
||||
add<TConfig, TConfigInput>(
|
||||
extension: ExtensionDefinition<TConfig, TConfigInput>,
|
||||
options?: {
|
||||
config?: TConfigInput;
|
||||
},
|
||||
): ExtensionTester;
|
||||
): ExtensionTester<UOutput>;
|
||||
// (undocumented)
|
||||
get<T>(ref: ExtensionDataRef<T>): T | undefined;
|
||||
get<TId extends UOutput['id']>(
|
||||
ref: ExtensionDataRef<any, TId, any>,
|
||||
): UOutput extends ExtensionDataRef<infer IData, TId, infer IConfig>
|
||||
? IConfig['optional'] extends true
|
||||
? IData | undefined
|
||||
: IData
|
||||
: never;
|
||||
// (undocumented)
|
||||
query(id: string | ExtensionDefinition<any, any>): ExtensionQuery;
|
||||
query<UQueryExtensionOutput extends AnyExtensionDataRef>(
|
||||
extension: ExtensionDefinition<any, any, UQueryExtensionOutput>,
|
||||
): ExtensionQuery<UQueryExtensionOutput>;
|
||||
// (undocumented)
|
||||
reactElement(): JSX.Element;
|
||||
// @deprecated (undocumented)
|
||||
|
||||
@@ -100,7 +100,7 @@ describe('EntityCardBlueprint', () => {
|
||||
filter: 'test',
|
||||
},
|
||||
}),
|
||||
).data(EntityCardBlueprint.dataRefs.filterExpression),
|
||||
).get(EntityCardBlueprint.dataRefs.filterExpression),
|
||||
).toBe('test');
|
||||
|
||||
expect(
|
||||
@@ -112,7 +112,7 @@ describe('EntityCardBlueprint', () => {
|
||||
},
|
||||
}),
|
||||
{ config: { filter: 'test' } },
|
||||
).data(EntityCardBlueprint.dataRefs.filterExpression),
|
||||
).get(EntityCardBlueprint.dataRefs.filterExpression),
|
||||
).toBe('test');
|
||||
|
||||
expect(
|
||||
@@ -124,7 +124,7 @@ describe('EntityCardBlueprint', () => {
|
||||
loader: async () => <div>Test!</div>,
|
||||
},
|
||||
}),
|
||||
).data(EntityCardBlueprint.dataRefs.filterFunction),
|
||||
).get(EntityCardBlueprint.dataRefs.filterFunction),
|
||||
).toBe(mockFilter);
|
||||
});
|
||||
|
||||
|
||||
@@ -122,10 +122,10 @@ describe('EntityContentBlueprint', () => {
|
||||
const tester = createExtensionTester(extension);
|
||||
|
||||
// todo(blam): route paths are always set to / in the createExtensionTester. This will work eventually.
|
||||
// expect(tester.data(coreExtensionData.routePath)).toBe('/test');
|
||||
// expect(tester.get(coreExtensionData.routePath)).toBe('/test');
|
||||
|
||||
expect(tester.data(coreExtensionData.routeRef)).toBe(mockRouteRef);
|
||||
expect(tester.data(EntityContentBlueprint.dataRefs.title)).toBe('Test');
|
||||
expect(tester.get(coreExtensionData.routeRef)).toBe(mockRouteRef);
|
||||
expect(tester.get(EntityContentBlueprint.dataRefs.title)).toBe('Test');
|
||||
});
|
||||
|
||||
it('should emit the correct filter output', () => {
|
||||
@@ -142,7 +142,7 @@ describe('EntityContentBlueprint', () => {
|
||||
filter: 'test',
|
||||
},
|
||||
}),
|
||||
).data(EntityContentBlueprint.dataRefs.filterExpression),
|
||||
).get(EntityContentBlueprint.dataRefs.filterExpression),
|
||||
).toBe('test');
|
||||
|
||||
expect(
|
||||
@@ -156,7 +156,7 @@ describe('EntityContentBlueprint', () => {
|
||||
},
|
||||
}),
|
||||
{ config: { filter: 'test' } },
|
||||
).data(EntityContentBlueprint.dataRefs.filterExpression),
|
||||
).get(EntityContentBlueprint.dataRefs.filterExpression),
|
||||
).toBe('test');
|
||||
|
||||
expect(
|
||||
@@ -170,7 +170,7 @@ describe('EntityContentBlueprint', () => {
|
||||
loader: async () => <div>Test!</div>,
|
||||
},
|
||||
}),
|
||||
).data(EntityContentBlueprint.dataRefs.filterFunction),
|
||||
).get(EntityContentBlueprint.dataRefs.filterFunction),
|
||||
).toBe(mockFilter);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user