mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
simplify tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
2f9b14d97e
commit
4ae7eae81c
@ -19,7 +19,7 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CatalogEntityRegistry, rawItems } from "../catalog-entity-registry";
|
import { CatalogEntityRegistry } from "../catalog-entity-registry";
|
||||||
import "../../../common/catalog-entities";
|
import "../../../common/catalog-entities";
|
||||||
import { catalogCategoryRegistry } from "../../../common/catalog/catalog-category-registry";
|
import { catalogCategoryRegistry } from "../../../common/catalog/catalog-category-registry";
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ describe("CatalogEntityRegistry", () => {
|
|||||||
spec: {}
|
spec: {}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
catalog[rawItems].replace(items);
|
(catalog as any).rawItems.replace(items);
|
||||||
expect(catalog.items.length).toEqual(1);
|
expect(catalog.items.length).toEqual(1);
|
||||||
|
|
||||||
items.push({
|
items.push({
|
||||||
@ -60,7 +60,7 @@ describe("CatalogEntityRegistry", () => {
|
|||||||
spec: {}
|
spec: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
catalog[rawItems].replace(items);
|
(catalog as any).rawItems.replace(items);
|
||||||
expect(catalog.items.length).toEqual(2);
|
expect(catalog.items.length).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -81,13 +81,13 @@ describe("CatalogEntityRegistry", () => {
|
|||||||
spec: {}
|
spec: {}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
catalog[rawItems].replace(items);
|
(catalog as any).rawItems.replace(items);
|
||||||
expect(catalog.items.length).toEqual(1);
|
expect(catalog.items.length).toEqual(1);
|
||||||
expect(catalog.items[0].status.phase).toEqual("disconnected");
|
expect(catalog.items[0].status.phase).toEqual("disconnected");
|
||||||
|
|
||||||
items[0].status.phase = "connected";
|
items[0].status.phase = "connected";
|
||||||
|
|
||||||
catalog[rawItems].replace(items);
|
(catalog as any).rawItems.replace(items);
|
||||||
expect(catalog.items.length).toEqual(1);
|
expect(catalog.items.length).toEqual(1);
|
||||||
expect(catalog.items[0].status.phase).toEqual("connected");
|
expect(catalog.items[0].status.phase).toEqual("connected");
|
||||||
});
|
});
|
||||||
@ -125,9 +125,9 @@ describe("CatalogEntityRegistry", () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
catalog[rawItems].replace(items);
|
(catalog as any).rawItems.replace(items);
|
||||||
items.splice(0, 1);
|
items.splice(0, 1);
|
||||||
catalog[rawItems].replace(items);
|
(catalog as any).rawItems.replace(items);
|
||||||
expect(catalog.items.length).toEqual(1);
|
expect(catalog.items.length).toEqual(1);
|
||||||
expect(catalog.items[0].metadata.uid).toEqual("456");
|
expect(catalog.items[0].metadata.uid).toEqual("456");
|
||||||
});
|
});
|
||||||
|
|||||||
@ -25,17 +25,15 @@ import { CatalogCategory, CatalogEntity, CatalogEntityData, catalogCategoryRegis
|
|||||||
import "../../common/catalog-entities";
|
import "../../common/catalog-entities";
|
||||||
import { iter } from "../utils";
|
import { iter } from "../utils";
|
||||||
|
|
||||||
export const rawItems = Symbol();
|
|
||||||
|
|
||||||
export class CatalogEntityRegistry {
|
export class CatalogEntityRegistry {
|
||||||
protected [rawItems] = observable.array<CatalogEntityData & CatalogEntityKindData>([], { deep: true });
|
protected rawItems = observable.array<CatalogEntityData & CatalogEntityKindData>([], { deep: true });
|
||||||
@observable protected _activeEntity: CatalogEntity;
|
@observable protected _activeEntity: CatalogEntity;
|
||||||
|
|
||||||
constructor(private categoryRegistry: CatalogCategoryRegistry) {}
|
constructor(private categoryRegistry: CatalogCategoryRegistry) {}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
subscribeToBroadcast("catalog:items", (ev, items: (CatalogEntityData & CatalogEntityKindData)[]) => {
|
subscribeToBroadcast("catalog:items", (ev, items: (CatalogEntityData & CatalogEntityKindData)[]) => {
|
||||||
this[rawItems].replace(items);
|
this.rawItems.replace(items);
|
||||||
});
|
});
|
||||||
broadcastMessage("catalog:broadcast");
|
broadcastMessage("catalog:broadcast");
|
||||||
}
|
}
|
||||||
@ -49,7 +47,7 @@ export class CatalogEntityRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@computed get items() {
|
@computed get items() {
|
||||||
return Array.from(iter.filterMap(this[rawItems], rawItem => this.categoryRegistry.getEntityForData(rawItem)));
|
return Array.from(iter.filterMap(this.rawItems, rawItem => this.categoryRegistry.getEntityForData(rawItem)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get entities(): Map<string, CatalogEntity> {
|
@computed get entities(): Map<string, CatalogEntity> {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user