frontend-test-utils: review fixes for readonly fields and config constructor
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -584,3 +584,5 @@ zsh
|
||||
resizable
|
||||
enums
|
||||
LLMs
|
||||
Passthrough
|
||||
passthrough
|
||||
|
||||
@@ -31,8 +31,8 @@ import ObservableImpl from 'zen-observable';
|
||||
* ```
|
||||
*/
|
||||
export class MockAlertApi implements AlertApi {
|
||||
private alerts: AlertMessage[] = [];
|
||||
private observers = new Set<(alert: AlertMessage) => void>();
|
||||
private readonly alerts: AlertMessage[] = [];
|
||||
private readonly observers = new Set<(alert: AlertMessage) => void>();
|
||||
|
||||
post(alert: AlertMessage) {
|
||||
this.alerts.push(alert);
|
||||
@@ -62,7 +62,7 @@ export class MockAlertApi implements AlertApi {
|
||||
* Clear all collected alerts.
|
||||
*/
|
||||
clearAlerts(): void {
|
||||
this.alerts = [];
|
||||
this.alerts.length = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,12 +19,14 @@ import { MockConfigApi } from './MockConfigApi';
|
||||
describe('MockConfigApi', () => {
|
||||
it('is able to read some basic config', () => {
|
||||
const mock = new MockConfigApi({
|
||||
app: {
|
||||
title: 'Hello',
|
||||
data: {
|
||||
app: {
|
||||
title: 'Hello',
|
||||
},
|
||||
x: 1,
|
||||
y: false,
|
||||
z: [{ a: 3 }],
|
||||
},
|
||||
x: 1,
|
||||
y: false,
|
||||
z: [{ a: 3 }],
|
||||
});
|
||||
|
||||
expect(mock.getString('app.title')).toEqual('Hello');
|
||||
|
||||
@@ -26,7 +26,7 @@ import { ConfigApi } from '@backstage/core-plugin-api';
|
||||
* @example
|
||||
* ```tsx
|
||||
* const mockConfig = new MockConfigApi({
|
||||
* app: { baseUrl: 'https://example.com' },
|
||||
* data: { app: { baseUrl: 'https://example.com' } },
|
||||
* });
|
||||
*
|
||||
* const rendered = await renderInTestApp(
|
||||
@@ -40,7 +40,7 @@ export class MockConfigApi implements ConfigApi {
|
||||
private readonly config: ConfigReader;
|
||||
|
||||
// NOTE: not extending in order to avoid inheriting the static `.fromConfigs`
|
||||
constructor(data: JsonObject) {
|
||||
constructor({ data }: { data: JsonObject }) {
|
||||
this.config = new ConfigReader(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ export interface MockFeatureFlagsApiOptions {
|
||||
* ```
|
||||
*/
|
||||
export class MockFeatureFlagsApi implements FeatureFlagsApi {
|
||||
private registeredFlags: FeatureFlag[] = [];
|
||||
private states: Map<string, FeatureFlagState>;
|
||||
private readonly registeredFlags: FeatureFlag[] = [];
|
||||
private readonly states: Map<string, FeatureFlagState>;
|
||||
|
||||
constructor(options?: MockFeatureFlagsApiOptions) {
|
||||
this.states = new Map(Object.entries(options?.initialStates ?? {}));
|
||||
@@ -73,7 +73,10 @@ export class MockFeatureFlagsApi implements FeatureFlagsApi {
|
||||
this.states.set(name, state);
|
||||
}
|
||||
} else {
|
||||
this.states = new Map(Object.entries(options.states));
|
||||
this.states.clear();
|
||||
for (const [name, state] of Object.entries(options.states)) {
|
||||
this.states.set(name, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,9 +64,9 @@ export class MockTranslationApi implements TranslationApi {
|
||||
return new MockTranslationApi(i18n, interpolator);
|
||||
}
|
||||
|
||||
#i18n: I18n;
|
||||
#interpolator: JsxInterpolator;
|
||||
#registeredRefs = new Set<string>();
|
||||
readonly #i18n: I18n;
|
||||
readonly #interpolator: JsxInterpolator;
|
||||
readonly #registeredRefs = new Set<string>();
|
||||
|
||||
private constructor(i18n: I18n, interpolator: JsxInterpolator) {
|
||||
this.#i18n = i18n;
|
||||
|
||||
@@ -287,7 +287,7 @@ export namespace mockApis {
|
||||
export function config(options?: {
|
||||
data?: JsonObject;
|
||||
}): MockConfigApi & MockWithApiFactory<ConfigApi> {
|
||||
const instance = new MockConfigApi(options?.data ?? {});
|
||||
const instance = new MockConfigApi({ data: options?.data ?? {} });
|
||||
return mockWithApiFactory(configApiRef, instance) as MockConfigApi &
|
||||
MockWithApiFactory<ConfigApi>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user