mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Technical requirements for behavioural unit tests (#5084)
* 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> * Make a directory commonly available Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Require id for <Select /> to prevent non-deterministic renders This was caused by global state in a 3rd party lib: "react-select". Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Specify id for all <Select /> to satisfy previous commit Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Prevent explicit side effect in component by using existing dependency instead Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Extract instantiation of "conf" as injectables for causing side effects Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Introduce a legacy-helper to make gradual refactoring of inheritors of Singleton easier Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Make legacy unit tests for hotbar green and more simple by using the new legacy helper Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Temporarily kludge all unit tests green with a disclaimer about allowing side-effects Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Remove kludge in previous commit by explicitly permitting specific side effects where old unit tests require it Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Prevent old unit test with side effects from accessing file system Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Migrate to actual typing for di.permitSideEffects Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Prevent unit tests from failing because of non-standard method of HTML-element not present in js-dom Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Adapt integration tests to recent changes Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Fix code style Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Fix artifact from bad rebase Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Add a deprecation from a review comment Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Remove change that is not required Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove redundant comment Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix code style Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove redundant file Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix bad merge Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Improve variable name Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Tweak logger interface to be more descriptive Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make injecting legacy singleton always provide new instance Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove conditional typing when not needed Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Improve naming of variable Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove unnecessary code style changes Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove flag for causing side effects from too broad scope Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Override side-effects in unit test using injectable instead of monkey patching Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Flag some side-effects and add general overrides Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Fix unit tests in CI by removing explicit side-effect Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Remove explicit side-effect from getting default shell Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce abstraction for getting absolute paths Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to using abstraction for getting absolute path to control explicit side effect Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce abstraction for joining paths Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to using abstraction for joining paths to control explicit side effect Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix fake implementation for join paths Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix test after removing explicit side effect Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove explicit side effects from kubeconfig-syncs Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix arguments after removing explicit side effect Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make registrators not async for not being needed anymore Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make generalCatalogEntities non-observable, as there is no requirement Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Remove redundant code Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Simplify logic for registering general catalog entity sources Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add TODO Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Replace function for getting application menu items with reactive solution Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix typo in interface name Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove global shared state usages of hot bar store Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove redundant enum Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
ab2cd27a27
commit
a277cfcf02
583 files changed
+13073
-6556
No files matched your search
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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 { aboutPortForwarding } from "./port-forward-notify";
|
||||
import navigateToPortForwardsInjectable from "../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable";
|
||||
|
||||
const aboutPortForwardingInjectable = getInjectable({
|
||||
id: "about-port-forwarding",
|
||||
|
||||
instantiate: (di) =>
|
||||
aboutPortForwarding({
|
||||
navigateToPortForwards: di.inject(navigateToPortForwardsInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
export default aboutPortForwardingInjectable;
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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 { notifyErrorPortForwarding } from "./port-forward-notify";
|
||||
import navigateToPortForwardsInjectable from "../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable";
|
||||
|
||||
const notifyErrorPortForwardingInjectable = getInjectable({
|
||||
id: "notify-error-port-forwarding",
|
||||
|
||||
instantiate: (di) =>
|
||||
notifyErrorPortForwarding({
|
||||
navigateToPortForwards: di.inject(navigateToPortForwardsInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
export default notifyErrorPortForwardingInjectable;
|
||||
@@ -14,19 +14,22 @@ import { Input } from "../components/input";
|
||||
import { cssNames } from "../utils";
|
||||
import type { PortForwardStore } from "./port-forward-store/port-forward-store";
|
||||
import { openPortForward } from "./port-forward-utils";
|
||||
import { aboutPortForwarding, notifyErrorPortForwarding } from "./port-forward-notify";
|
||||
import { Checkbox } from "../components/checkbox";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { PortForwardDialogModel } from "./port-forward-dialog-model/port-forward-dialog-model";
|
||||
import portForwardDialogModelInjectable from "./port-forward-dialog-model/port-forward-dialog-model.injectable";
|
||||
import logger from "../../common/logger";
|
||||
import portForwardStoreInjectable from "./port-forward-store/port-forward-store.injectable";
|
||||
import aboutPortForwardingInjectable from "./about-port-forwarding.injectable";
|
||||
import notifyErrorPortForwardingInjectable from "./notify-error-port-forwarding.injectable";
|
||||
|
||||
export interface PortForwardDialogProps extends Partial<DialogProps> {}
|
||||
|
||||
interface Dependencies {
|
||||
portForwardStore: PortForwardStore;
|
||||
model: PortForwardDialogModel;
|
||||
aboutPortForwarding: () => void;
|
||||
notifyErrorPortForwarding: (message: string) => void;
|
||||
}
|
||||
|
||||
@observer
|
||||
@@ -68,18 +71,18 @@ class NonInjectedPortForwardDialog extends Component<PortForwardDialogProps & De
|
||||
portForward = await this.portForwardStore.modify(portForward, desiredPort);
|
||||
|
||||
if (wasRunning && portForward.status === "Disabled") {
|
||||
notifyErrorPortForwarding(`Error occurred starting port-forward, the local port ${portForward.forwardPort} may not be available or the ${portForward.kind} ${portForward.name} may not be reachable`);
|
||||
this.props.notifyErrorPortForwarding(`Error occurred starting port-forward, the local port ${portForward.forwardPort} may not be available or the ${portForward.kind} ${portForward.name} may not be reachable`);
|
||||
}
|
||||
} else {
|
||||
portForward.forwardPort = desiredPort;
|
||||
portForward = await this.portForwardStore.add(portForward);
|
||||
|
||||
if (portForward.status === "Disabled") {
|
||||
notifyErrorPortForwarding(`Error occurred starting port-forward, the local port ${portForward.forwardPort} may not be available or the ${portForward.kind} ${portForward.name} may not be reachable`);
|
||||
this.props.notifyErrorPortForwarding(`Error occurred starting port-forward, the local port ${portForward.forwardPort} may not be available or the ${portForward.kind} ${portForward.name} may not be reachable`);
|
||||
} else {
|
||||
// if this is the first port-forward show the about notification
|
||||
if (!length) {
|
||||
aboutPortForwarding();
|
||||
this.props.aboutPortForwarding();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,6 +170,8 @@ export const PortForwardDialog = withInjectables<Dependencies, PortForwardDialog
|
||||
getProps: (di, props) => ({
|
||||
portForwardStore: di.inject(portForwardStoreInjectable),
|
||||
model: di.inject(portForwardDialogModelInjectable),
|
||||
aboutPortForwarding: di.inject(aboutPortForwardingInjectable),
|
||||
notifyErrorPortForwarding: di.inject(notifyErrorPortForwardingInjectable),
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { portForwardsURL } from "../../common/routes/port-forwards";
|
||||
import { Button } from "../components/button";
|
||||
import { Notifications, notificationsStore } from "../components/notifications";
|
||||
import { navigate } from "../navigation";
|
||||
import { getHostedClusterId } from "../utils";
|
||||
import type { NavigateToPortForwards } from "../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable";
|
||||
|
||||
interface AboutPortForwardingDependencies {
|
||||
navigateToPortForwards: NavigateToPortForwards;
|
||||
}
|
||||
|
||||
export function aboutPortForwarding() {
|
||||
export const aboutPortForwarding = ({ navigateToPortForwards }: AboutPortForwardingDependencies) => () => {
|
||||
const notificationId = `port-forward-notification-${getHostedClusterId()}`;
|
||||
|
||||
Notifications.info(
|
||||
@@ -27,7 +29,7 @@ export function aboutPortForwarding() {
|
||||
outlined
|
||||
label="Go to Port Forwarding"
|
||||
onClick={() => {
|
||||
navigate(portForwardsURL());
|
||||
navigateToPortForwards();
|
||||
notificationsStore.remove(notificationId);
|
||||
}}
|
||||
/>
|
||||
@@ -39,9 +41,14 @@ export function aboutPortForwarding() {
|
||||
timeout: 10_000,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
interface NotifyErrorPortForwardingDependencies {
|
||||
navigateToPortForwards: NavigateToPortForwards;
|
||||
}
|
||||
|
||||
export function notifyErrorPortForwarding(msg: string) {
|
||||
|
||||
export const notifyErrorPortForwarding = ({ navigateToPortForwards }: NotifyErrorPortForwardingDependencies) => (msg: string) => {
|
||||
const notificationId = `port-forward-error-notification-${getHostedClusterId()}`;
|
||||
|
||||
Notifications.error(
|
||||
@@ -57,7 +64,7 @@ export function notifyErrorPortForwarding(msg: string) {
|
||||
outlined
|
||||
label="Check Port Forwarding"
|
||||
onClick={() => {
|
||||
navigate(portForwardsURL());
|
||||
navigateToPortForwards();
|
||||
notificationsStore.remove(notificationId);
|
||||
}}
|
||||
/>
|
||||
@@ -69,5 +76,5 @@ export function notifyErrorPortForwarding(msg: string) {
|
||||
timeout: 10_000,
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { PortForwardStore } from "./port-forward-store";
|
||||
import type { ForwardedPort } from "../port-forward-item";
|
||||
import createStorageInjectable from "../../utils/create-storage/create-storage.injectable";
|
||||
import notifyErrorPortForwardingInjectable from "../notify-error-port-forwarding.injectable";
|
||||
|
||||
const portForwardStoreInjectable = getInjectable({
|
||||
id: "port-forward-store",
|
||||
@@ -18,7 +19,10 @@ const portForwardStoreInjectable = getInjectable({
|
||||
undefined,
|
||||
);
|
||||
|
||||
return new PortForwardStore({ storage });
|
||||
return new PortForwardStore({
|
||||
storage,
|
||||
notifyErrorPortForwarding: di.inject(notifyErrorPortForwardingInjectable),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@ import { action, makeObservable, observable, reaction } from "mobx";
|
||||
import { ItemStore } from "../../../common/item.store";
|
||||
import { autoBind, disposer, StorageHelper } from "../../utils";
|
||||
import { ForwardedPort, PortForwardItem } from "../port-forward-item";
|
||||
import { notifyErrorPortForwarding } from "../port-forward-notify";
|
||||
import { apiBase } from "../../api";
|
||||
import { waitUntilFree } from "tcp-port-used";
|
||||
import logger from "../../../common/logger";
|
||||
|
||||
interface Dependencies {
|
||||
storage: StorageHelper<ForwardedPort[] | undefined>;
|
||||
notifyErrorPortForwarding: (message: string) => void;
|
||||
}
|
||||
|
||||
export class PortForwardStore extends ItemStore<PortForwardItem> {
|
||||
@@ -43,7 +43,7 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
|
||||
|
||||
for (const result of results) {
|
||||
if (result.status === "rejected" || result.value.status === "Disabled") {
|
||||
notifyErrorPortForwarding("One or more port-forwards could not be started");
|
||||
this.dependencies.notifyErrorPortForwarding("One or more port-forwards could not be started");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user