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 type { WebLinkSpec, WebLinkStatus } from "../../../common/catalog-entities";
|
||||||
import { WebLink } from "../../../common/catalog-entities";
|
import { WebLink } from "../../../common/catalog-entities";
|
||||||
import type { CatalogEntityMetadata } from "../../../common/catalog";
|
import type { CatalogEntityMetadata } from "../../../common/catalog";
|
||||||
import { catalogCategoryRegistry, CatalogEntity } from "../../../common/catalog";
|
import { CatalogEntity } from "../../../common/catalog";
|
||||||
import { CatalogEntityRegistry } from "../catalog-entity-registry";
|
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||||
|
import catalogEntityRegistryInjectable from "../entity-registry.injectable";
|
||||||
|
import type { CatalogEntityRegistry } from "../entity-registry";
|
||||||
|
|
||||||
class InvalidEntity extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus, WebLinkSpec> {
|
class InvalidEntity extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus, WebLinkSpec> {
|
||||||
public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
|
public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
|
||||||
@ -32,7 +34,7 @@ class InvalidEntity extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("CatalogEntityRegistry", () => {
|
describe("CatalogEntityRegistry", () => {
|
||||||
let registry: CatalogEntityRegistry;
|
let entityRegistry: CatalogEntityRegistry;
|
||||||
const entity = new WebLink({
|
const entity = new WebLink({
|
||||||
metadata: {
|
metadata: {
|
||||||
uid: "test",
|
uid: "test",
|
||||||
@ -63,26 +65,28 @@ describe("CatalogEntityRegistry", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
registry = new CatalogEntityRegistry(catalogCategoryRegistry);
|
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||||
|
|
||||||
|
entityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("addSource", () => {
|
describe("addSource", () => {
|
||||||
it ("allows to add an observable source", () => {
|
it ("allows to add an observable source", () => {
|
||||||
const source = observable.array<WebLink>([]);
|
const source = observable.array<WebLink>([]);
|
||||||
|
|
||||||
registry.addObservableSource("test", source);
|
entityRegistry.addObservableSource("test", source);
|
||||||
expect(registry.items.length).toEqual(0);
|
expect(entityRegistry.items.length).toEqual(0);
|
||||||
|
|
||||||
source.push(entity);
|
source.push(entity);
|
||||||
|
|
||||||
expect(registry.items.length).toEqual(1);
|
expect(entityRegistry.items.length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it ("added source change triggers reaction", (done) => {
|
it ("added source change triggers reaction", (done) => {
|
||||||
const source = observable.array<WebLink>([]);
|
const source = observable.array<WebLink>([]);
|
||||||
|
|
||||||
registry.addObservableSource("test", source);
|
entityRegistry.addObservableSource("test", source);
|
||||||
reaction(() => registry.items, () => {
|
reaction(() => entityRegistry.items, () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -94,29 +98,29 @@ describe("CatalogEntityRegistry", () => {
|
|||||||
it ("removes source", () => {
|
it ("removes source", () => {
|
||||||
const source = observable.array<WebLink>([]);
|
const source = observable.array<WebLink>([]);
|
||||||
|
|
||||||
registry.addObservableSource("test", source);
|
entityRegistry.addObservableSource("test", source);
|
||||||
source.push(entity);
|
source.push(entity);
|
||||||
registry.removeSource("test");
|
entityRegistry.removeSource("test");
|
||||||
|
|
||||||
expect(registry.items.length).toEqual(0);
|
expect(entityRegistry.items.length).toEqual(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("items", () => {
|
describe("items", () => {
|
||||||
it("returns added items", () => {
|
it("returns added items", () => {
|
||||||
expect(registry.items.length).toBe(0);
|
expect(entityRegistry.items.length).toBe(0);
|
||||||
|
|
||||||
const source = observable.array([entity]);
|
const source = observable.array([entity]);
|
||||||
|
|
||||||
registry.addObservableSource("test", source);
|
entityRegistry.addObservableSource("test", source);
|
||||||
expect(registry.items.length).toBe(1);
|
expect(entityRegistry.items.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not return items without matching category", () => {
|
it("does not return items without matching category", () => {
|
||||||
const source = observable.array([invalidEntity]);
|
const source = observable.array([invalidEntity]);
|
||||||
|
|
||||||
registry.addObservableSource("test", source);
|
entityRegistry.addObservableSource("test", source);
|
||||||
expect(registry.items.length).toBe(0);
|
expect(entityRegistry.items.length).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user