frontend-test-utils: review fixes

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2026-02-10 10:29:28 +01:00
parent 67959bf42a
commit 8fa6ef3452
6 changed files with 10 additions and 23 deletions
@@ -139,7 +139,7 @@ import {
import { myApiRef, type MyApi } from '@internal/plugin-example-react';
// Fake instance with real behavior
export function myApiMock(options?: { greeting?: string }): MyApi {
export function myApiMock(options?: { greeting?: string }) {
return attachMockApiFactory(myApiRef, {
greet: async () => options?.greeting ?? 'Hello!',
});
+2 -7
View File
@@ -234,7 +234,7 @@ export namespace mockApis {
email?: string;
displayName?: string;
picture?: string;
}): IdentityApi & MockWithApiFactory<IdentityApi>;
}): MockWithApiFactory<IdentityApi>;
export namespace identity {
const // (undocumented)
mock: (
@@ -376,7 +376,7 @@ export class MockPermissionApi implements PermissionApi {
// @public
export class MockStorageApi implements StorageApi {
// (undocumented)
static create(data?: MockStorageBucket): MockStorageApi;
static create(data?: JsonObject): MockStorageApi;
// (undocumented)
forBucket(name: string): StorageApi;
// (undocumented)
@@ -391,11 +391,6 @@ export class MockStorageApi implements StorageApi {
snapshot<T extends JsonValue>(key: string): StorageValueSnapshot<T>;
}
// @public
export type MockStorageBucket = {
[key: string]: any;
};
// @public
export class MockTranslationApi implements TranslationApi {
// (undocumented)
@@ -15,16 +15,9 @@
*/
import { StorageApi, StorageValueSnapshot } from '@backstage/core-plugin-api';
import { JsonValue, Observable } from '@backstage/types';
import { JsonObject, JsonValue, Observable } from '@backstage/types';
import ObservableImpl from 'zen-observable';
/**
* Type for map holding data in {@link MockStorageApi}
*
* @public
*/
export type MockStorageBucket = { [key: string]: any };
/**
* Mock implementation of the {@link core-plugin-api#StorageApi} to be used in tests
*
@@ -32,20 +25,20 @@ export type MockStorageBucket = { [key: string]: any };
*/
export class MockStorageApi implements StorageApi {
private readonly namespace: string;
private readonly data: MockStorageBucket;
private readonly data: JsonObject;
private readonly bucketStorageApis: Map<string, MockStorageApi>;
private constructor(
namespace: string,
bucketStorageApis: Map<string, MockStorageApi>,
data?: MockStorageBucket,
data?: JsonObject,
) {
this.namespace = namespace;
this.bucketStorageApis = bucketStorageApis;
this.data = { ...data };
}
static create(data?: MockStorageBucket) {
static create(data?: JsonObject) {
// Translate a nested data object structure into a flat object with keys
// like `/a/b` with their corresponding leaf values
const keyValues: { [key: string]: any } = {};
@@ -83,7 +76,7 @@ export class MockStorageApi implements StorageApi {
return {
key,
presence: 'present',
value: data,
value: data as T,
};
}
return {
@@ -15,4 +15,3 @@
*/
export { MockStorageApi } from './MockStorageApi';
export type { MockStorageBucket } from './MockStorageApi';
@@ -78,7 +78,7 @@ export type { MockPermissionApi } from './PermissionApi';
/**
* @public
*/
export type { MockStorageApi, MockStorageBucket } from './StorageApi';
export type { MockStorageApi } from './StorageApi';
/**
* @public
@@ -313,7 +313,7 @@ export namespace mockApis {
email?: string;
displayName?: string;
picture?: string;
}): IdentityApi & MockWithApiFactory<IdentityApi> {
}): MockWithApiFactory<IdentityApi> {
const {
userEntityRef = 'user:default/test',
ownershipEntityRefs = ['user:default/test'],