Implement a lot of technical requirements for behavioural unit tests

Note: the crux of this was to make routing env-agnostic, and not based on URLs as magic strings, but instead something type-enforced.

Note: extension-based routes comply to same exact interface by "late-registering" their routes when installed. Routes are just injectables.

Note: another chunk of global shared state is no more.

Note: a lot of explicit side effects have been cornered to injectables.

Note: a lot of stuff has become reactive as part if this.

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne SavolainenandMikko Aspiala committed 2022-03-31 15:13:26 +03:00
1 parent 086604630a
commit 5c8ca2c038
523 files changed
+11727 -5541

No files matched your search

@@ -0,0 +1,21 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { StatefulSets } from "./statefulsets";
import statefulsetsRouteInjectable from "../../../common/front-end-routing/routes/cluster/workloads/statefulsets/statefulsets-route.injectable";
import { routeSpecificComponentInjectionToken } from "../../routes/route-specific-component-injection-token";
const statefulsetsRouteComponentInjectable = getInjectable({
id: "statefulsets-route-component",
instantiate: (di) => ({
route: di.inject(statefulsetsRouteInjectable),
Component: StatefulSets,
}),
injectionToken: routeSpecificComponentInjectionToken,
});
export default statefulsetsRouteComponentInjectable;
@@ -0,0 +1,38 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import statefulsetsRouteInjectable from "../../../common/front-end-routing/routes/cluster/workloads/statefulsets/statefulsets-route.injectable";
import { workloadsSidebarItemId } from "../+workloads/workloads-sidebar-items.injectable";
import { sidebarItemsInjectionToken } from "../layout/sidebar-items.injectable";
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
import navigateToStatefulsetsInjectable from "../../../common/front-end-routing/routes/cluster/workloads/statefulsets/navigate-to-statefulsets.injectable";
const statefulsetsSidebarItemsInjectable = getInjectable({
id: "statefulsets-sidebar-items",
instantiate: (di) => {
const route = di.inject(statefulsetsRouteInjectable);
const navigateToStatefulsets = di.inject(navigateToStatefulsetsInjectable);
const routeIsActive = di.inject(routeIsActiveInjectable, route);
return computed(() => [
{
id: "stateful-sets",
parentId: workloadsSidebarItemId,
title: "StatefulSets",
onClick: navigateToStatefulsets,
isActive: routeIsActive,
isVisible: route.isEnabled,
orderNumber: 50,
},
]);
},
injectionToken: sidebarItemsInjectionToken,
});
export default statefulsetsSidebarItemsInjectable;
@@ -0,0 +1,14 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { statefulSetStore } from "./statefulset.store";
const statefulsetsStoreInjectable = getInjectable({
id: "statefulset-store",
instantiate: () => statefulSetStore,
causesSideEffects: true,
});
export default statefulsetsStoreInjectable;
@@ -7,14 +7,13 @@ import "./statefulsets.scss";
import React from "react";
import { observer } from "mobx-react";
import type { RouteComponentProps } from "react-router";
import type { StatefulSet } from "../../../common/k8s-api/endpoints";
import { podsStore } from "../+workloads-pods/pods.store";
import { statefulSetStore } from "./statefulset.store";
import { eventStore } from "../+events/event.store";
import { KubeObjectListLayout } from "../kube-object-list-layout";
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
import type { StatefulSetsRouteParams } from "../../../common/routes";
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
import { KubeObjectAge } from "../kube-object/age";
enum columnId {
@@ -25,11 +24,8 @@ enum columnId {
replicas = "replicas",
}
export interface StatefulSetsProps extends RouteComponentProps<StatefulSetsRouteParams> {
}
@observer
export class StatefulSets extends React.Component<StatefulSetsProps> {
export class StatefulSets extends React.Component {
renderPods(statefulSet: StatefulSet) {
const { readyReplicas, currentReplicas } = statefulSet.status;
@@ -38,38 +34,40 @@ export class StatefulSets extends React.Component<StatefulSetsProps> {
render() {
return (
<KubeObjectListLayout
isConfigurable
tableId="workload_statefulsets"
className="StatefulSets" store={statefulSetStore}
dependentStores={[podsStore, eventStore]} // status icon component uses event store, details component uses podStore
sortingCallbacks={{
[columnId.name]: statefulSet => statefulSet.getName(),
[columnId.namespace]: statefulSet => statefulSet.getNs(),
[columnId.age]: statefulSet => -statefulSet.getCreationTimestamp(),
[columnId.replicas]: statefulSet => statefulSet.getReplicas(),
}}
searchFilters={[
statefulSet => statefulSet.getSearchFields(),
]}
renderHeaderTitle="Stateful Sets"
renderTableHeader={[
{ title: "Name", className: "name", sortBy: columnId.name, id: columnId.name },
{ title: "Namespace", className: "namespace", sortBy: columnId.namespace, id: columnId.namespace },
{ title: "Pods", className: "pods", id: columnId.pods },
{ title: "Replicas", className: "replicas", sortBy: columnId.replicas, id: columnId.replicas },
{ className: "warning", showWithColumn: columnId.replicas },
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
]}
renderTableContents={statefulSet => [
statefulSet.getName(),
statefulSet.getNs(),
this.renderPods(statefulSet),
statefulSet.getReplicas(),
<KubeObjectStatusIcon key="icon" object={statefulSet}/>,
<KubeObjectAge key="age" object={statefulSet} />,
]}
/>
<SiblingsInTabLayout>
<KubeObjectListLayout
isConfigurable
tableId="workload_statefulsets"
className="StatefulSets" store={statefulSetStore}
dependentStores={[podsStore, eventStore]} // status icon component uses event store, details component uses podStore
sortingCallbacks={{
[columnId.name]: statefulSet => statefulSet.getName(),
[columnId.namespace]: statefulSet => statefulSet.getNs(),
[columnId.age]: statefulSet => -statefulSet.getCreationTimestamp(),
[columnId.replicas]: statefulSet => statefulSet.getReplicas(),
}}
searchFilters={[
statefulSet => statefulSet.getSearchFields(),
]}
renderHeaderTitle="Stateful Sets"
renderTableHeader={[
{ title: "Name", className: "name", sortBy: columnId.name, id: columnId.name },
{ title: "Namespace", className: "namespace", sortBy: columnId.namespace, id: columnId.namespace },
{ title: "Pods", className: "pods", id: columnId.pods },
{ title: "Replicas", className: "replicas", sortBy: columnId.replicas, id: columnId.replicas },
{ className: "warning", showWithColumn: columnId.replicas },
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
]}
renderTableContents={statefulSet => [
statefulSet.getName(),
statefulSet.getNs(),
this.renderPods(statefulSet),
statefulSet.getReplicas(),
<KubeObjectStatusIcon key="icon" object={statefulSet}/>,
<KubeObjectAge key="age" object={statefulSet} />,
]}
/>
</SiblingsInTabLayout>
);
}
}