mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix catalog-entity-registry.test.ts
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
2a1e33670b
commit
d5522996b7
@ -7,8 +7,10 @@ import { observable, reaction } from "mobx";
|
||||
import type { WebLinkSpec, WebLinkStatus } from "../../../common/catalog-entities";
|
||||
import { WebLink } from "../../../common/catalog-entities";
|
||||
import type { CatalogEntityMetadata } from "../../../common/catalog";
|
||||
import { catalogCategoryRegistry, CatalogEntity } from "../../../common/catalog";
|
||||
import { CatalogEntityRegistry } from "../catalog-entity-registry";
|
||||
import { CatalogEntity } from "../../../common/catalog";
|
||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||
import catalogEntityRegistryInjectable from "../entity-registry.injectable";
|
||||
import type { CatalogEntityRegistry } from "../entity-registry";
|
||||
|
||||
class InvalidEntity extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus, WebLinkSpec> {
|
||||
public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
|
||||
@ -32,7 +34,7 @@ class InvalidEntity extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
|
||||
}
|
||||
|
||||
describe("CatalogEntityRegistry", () => {
|
||||
let registry: CatalogEntityRegistry;
|
||||
let entityRegistry: CatalogEntityRegistry;
|
||||
const entity = new WebLink({
|
||||
metadata: {
|
||||
uid: "test",
|
||||
@ -63,26 +65,28 @@ describe("CatalogEntityRegistry", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
entityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||
});
|
||||
|
||||
describe("addSource", () => {
|
||||
it ("allows to add an observable source", () => {
|
||||
const source = observable.array<WebLink>([]);
|
||||
|
||||
registry.addObservableSource("test", source);
|
||||
expect(registry.items.length).toEqual(0);
|
||||
entityRegistry.addObservableSource("test", source);
|
||||
expect(entityRegistry.items.length).toEqual(0);
|
||||
|
||||
source.push(entity);
|
||||
|
||||
expect(registry.items.length).toEqual(1);
|
||||
expect(entityRegistry.items.length).toEqual(1);
|
||||
});
|
||||
|
||||
it ("added source change triggers reaction", (done) => {
|
||||
const source = observable.array<WebLink>([]);
|
||||
|
||||
registry.addObservableSource("test", source);
|
||||
reaction(() => registry.items, () => {
|
||||
entityRegistry.addObservableSource("test", source);
|
||||
reaction(() => entityRegistry.items, () => {
|
||||
done();
|
||||
});
|
||||
|
||||
@ -94,29 +98,29 @@ describe("CatalogEntityRegistry", () => {
|
||||
it ("removes source", () => {
|
||||
const source = observable.array<WebLink>([]);
|
||||
|
||||
registry.addObservableSource("test", source);
|
||||
entityRegistry.addObservableSource("test", source);
|
||||
source.push(entity);
|
||||
registry.removeSource("test");
|
||||
entityRegistry.removeSource("test");
|
||||
|
||||
expect(registry.items.length).toEqual(0);
|
||||
expect(entityRegistry.items.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("items", () => {
|
||||
it("returns added items", () => {
|
||||
expect(registry.items.length).toBe(0);
|
||||
expect(entityRegistry.items.length).toBe(0);
|
||||
|
||||
const source = observable.array([entity]);
|
||||
|
||||
registry.addObservableSource("test", source);
|
||||
expect(registry.items.length).toBe(1);
|
||||
entityRegistry.addObservableSource("test", source);
|
||||
expect(entityRegistry.items.length).toBe(1);
|
||||
});
|
||||
|
||||
it("does not return items without matching category", () => {
|
||||
const source = observable.array([invalidEntity]);
|
||||
|
||||
registry.addObservableSource("test", source);
|
||||
expect(registry.items.length).toBe(0);
|
||||
entityRegistry.addObservableSource("test", source);
|
||||
expect(entityRegistry.items.length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user