From dba4f59644055254b11cfe2536fd00a6cf9d6e98 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 14 Oct 2022 11:20:07 -0400 Subject: [PATCH] Add enough code to get first couple terminal tests to pass Signed-off-by: Sebastian Malton --- package.json | 9 +- src/common/app-paths/app-paths-channel.ts | 2 +- .../helm/add-helm-repository-channel.ts | 2 +- .../get-active-helm-repositories-channel.ts | 2 +- .../helm/remove-helm-repository-channel.ts | 2 +- src/common/logger.ts | 10 +- src/common/utils/channel/channel.test.ts | 10 +- ...-injection-token.ts => request-channel.ts} | 8 + .../request-from-channel-injection-token.ts | 15 - .../resolve-system-proxy-channel.ts | 2 +- src/common/utils/sync-box/channels.ts | 2 +- .../common/clear-as-deleting-channel.ts | 2 +- .../delete-dialog/common/delete-channel.ts | 2 +- .../common/set-as-deleting-channel.ts | 2 +- .../active-helm-repositories.injectable.ts | 4 +- .../add-helm-repository.injectable.ts | 4 +- .../remove-helm-repository.injectable.ts | 4 +- ...opened-shows-connecting-message-1-snap.png | Bin 0 -> 593 bytes .../opening-terminal-tab.test.tsx.snap | 584 ++++++++++++++++++ .../terminal/common/shell-api-auth-channel.ts | 2 +- .../terminal/opening-terminal-tab.test.tsx | 63 ++ .../request-shell-api-token.injectable.ts | 30 + src/jest-after-env.setup.ts | 3 + src/jest.setup.ts | 20 + .../get-cluster-for-request.injectable.ts | 48 ++ src/main/cluster/manager.injectable.ts | 2 + src/main/cluster/manager.ts | 4 +- ...or-popup.global-override-for-injectable.ts | 11 + .../features/show-error-popup.injectable.ts | 8 +- src/main/getDiForUnitTesting.ts | 2 - src/main/lens-proxy/lens-proxy.ts | 4 +- .../runnables/setup-lens-proxy.injectable.ts | 2 +- ...ist-request-channel-listener.injectable.ts | 2 +- .../enlist-request-channel-listener.test.ts | 2 +- .../channel-listeners/listener-tokens.ts | 2 +- ...istening-on-request-channels.injectable.ts | 2 +- .../get-active-cluster-entity.injectable.ts | 14 +- .../api/create-terminal-api.injectable.ts | 22 +- .../api/current-location.injectable.ts | 23 + src/renderer/api/terminal-api.ts | 22 +- src/renderer/api/websocket-api.ts | 14 +- .../hosted-cluster.injectable.ts | 10 +- .../terminal/create-renderer.injectable.ts | 16 + .../terminal/create-terminal.injectable.ts | 6 +- .../components/dock/terminal/store.ts | 74 +-- .../terminal-spawning-pool.injectable.ts | 1 - .../components/dock/terminal/terminal.ts | 40 +- .../components/dock/terminal/view.tsx | 73 +-- .../test-utils/get-application-builder.tsx | 75 ++- src/renderer/getDiForUnitTesting.tsx | 2 - .../request-from-channel.injectable.ts | 10 +- ...nitial-values-for-sync-boxes.injectable.ts | 6 +- ...override-requesting-from-window-to-main.ts | 4 +- yarn.lock | 431 ++++++++----- 54 files changed, 1338 insertions(+), 378 deletions(-) rename src/common/utils/channel/{request-channel-listener-injection-token.ts => request-channel.ts} (61%) delete mode 100644 src/common/utils/channel/request-from-channel-injection-token.ts create mode 100644 src/features/terminal/__image_snapshots__/opening-terminal-tab-test-tsx-test-for-opening-terminal-tab-within-cluster-frame-when-new-terminal-tab-is-opened-shows-connecting-message-1-snap.png create mode 100644 src/features/terminal/__snapshots__/opening-terminal-tab.test.tsx.snap create mode 100644 src/features/terminal/opening-terminal-tab.test.tsx create mode 100644 src/features/terminal/renderer/request-shell-api-token.injectable.ts create mode 100644 src/main/cluster/get-cluster-for-request.injectable.ts create mode 100644 src/main/electron-app/features/show-error-popup.global-override-for-injectable.ts create mode 100644 src/renderer/api/current-location.injectable.ts create mode 100644 src/renderer/components/dock/terminal/create-renderer.injectable.ts diff --git a/package.json b/package.json index 8a4d81867f..ae9cba1f1c 100644 --- a/package.json +++ b/package.json @@ -118,8 +118,7 @@ "/packages" ], "setupFiles": [ - "/src/jest.setup.ts", - "jest-canvas-mock" + "/src/jest.setup.ts" ], "globalSetup": "/src/jest.timezone.ts", "setupFilesAfterEnv": [ @@ -265,7 +264,7 @@ "immer": "^9.0.17", "joi": "^17.7.0", "js-yaml": "^4.1.0", - "jsdom": "^16.7.0", + "jsdom": "^20.0.1", "lodash": "^4.17.15", "marked": "^4.2.5", "md5-file": "^5.0.0", @@ -335,6 +334,7 @@ "@types/html-webpack-plugin": "^3.2.6", "@types/http-proxy": "^1.17.9", "@types/jest": "^28.1.6", + "@types/jest-image-snapshot": "^5.1.0", "@types/js-yaml": "^4.0.5", "@types/jsdom": "^16.2.14", "@types/lodash": "^4.14.191", @@ -375,6 +375,7 @@ "adr": "^1.4.3", "ansi_up": "^5.1.0", "chalk": "^4.1.2", + "canvas": "^2.10.1", "chart.js": "^2.9.4", "circular-dependency-plugin": "^5.2.2", "cli-progress": "^3.11.2", @@ -403,8 +404,8 @@ "ignore-loader": "^0.1.2", "include-media": "^1.4.9", "jest": "^28.1.3", - "jest-canvas-mock": "^2.3.1", "jest-environment-jsdom": "^28.1.3", + "jest-image-snapshot": "^5.2.0", "jest-mock-extended": "^2.0.9", "make-plural": "^6.2.2", "memfs": "^3.4.12", diff --git a/src/common/app-paths/app-paths-channel.ts b/src/common/app-paths/app-paths-channel.ts index 4502569d3b..6dda5d6f4f 100644 --- a/src/common/app-paths/app-paths-channel.ts +++ b/src/common/app-paths/app-paths-channel.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { AppPaths } from "./app-path-injection-token"; -import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "../utils/channel/request-channel"; export type AppPathsChannel = RequestChannel; diff --git a/src/common/helm/add-helm-repository-channel.ts b/src/common/helm/add-helm-repository-channel.ts index bf5aa19367..48ad22b22b 100644 --- a/src/common/helm/add-helm-repository-channel.ts +++ b/src/common/helm/add-helm-repository-channel.ts @@ -4,7 +4,7 @@ */ import type { HelmRepo } from "./helm-repo"; import type { AsyncResult } from "../utils/async-result"; -import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "../utils/channel/request-channel"; export type AddHelmRepositoryChannel = RequestChannel>; diff --git a/src/common/helm/get-active-helm-repositories-channel.ts b/src/common/helm/get-active-helm-repositories-channel.ts index 26720e9a5f..a0ce7c7b06 100644 --- a/src/common/helm/get-active-helm-repositories-channel.ts +++ b/src/common/helm/get-active-helm-repositories-channel.ts @@ -4,7 +4,7 @@ */ import type { HelmRepo } from "./helm-repo"; import type { AsyncResult } from "../utils/async-result"; -import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "../utils/channel/request-channel"; export type GetActiveHelmRepositoriesChannel = RequestChannel>; diff --git a/src/common/helm/remove-helm-repository-channel.ts b/src/common/helm/remove-helm-repository-channel.ts index 4d479d088c..1b9c670371 100644 --- a/src/common/helm/remove-helm-repository-channel.ts +++ b/src/common/helm/remove-helm-repository-channel.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { AsyncResult } from "../utils/async-result"; -import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "../utils/channel/request-channel"; import type { HelmRepo } from "./helm-repo"; export type RemoveHelmRepositoryChannel = RequestChannel>; diff --git a/src/common/logger.ts b/src/common/logger.ts index ad81271bfa..f18fb4c025 100644 --- a/src/common/logger.ts +++ b/src/common/logger.ts @@ -5,9 +5,9 @@ export interface Logger { - info: (message: string, ...args: any) => void; - error: (message: string, ...args: any) => void; - debug: (message: string, ...args: any) => void; - warn: (message: string, ...args: any) => void; - silly: (message: string, ...args: any) => void; + info: (message: string, ...args: any[]) => void; + error: (message: string, ...args: any[]) => void; + debug: (message: string, ...args: any[]) => void; + warn: (message: string, ...args: any[]) => void; + silly: (message: string, ...args: any[]) => void; } diff --git a/src/common/utils/channel/channel.test.ts b/src/common/utils/channel/channel.test.ts index 9a361b6770..7f2eb69787 100644 --- a/src/common/utils/channel/channel.test.ts +++ b/src/common/utils/channel/channel.test.ts @@ -11,15 +11,15 @@ import { getApplicationBuilder } from "../../../renderer/components/test-utils/g import type { LensWindow } from "../../../main/start-main-application/lens-window/application-window/create-lens-window.injectable"; import type { MessageChannel } from "./message-channel-listener-injection-token"; import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token"; -import type { RequestFromChannel } from "./request-from-channel-injection-token"; -import { requestFromChannelInjectionToken } from "./request-from-channel-injection-token"; -import type { RequestChannel } from "./request-channel-listener-injection-token"; +import type { RequestChannel } from "./request-channel"; import type { AsyncFnMock } from "@async-fn/jest"; import asyncFn from "@async-fn/jest"; import { getPromiseStatus } from "../../test-utils/get-promise-status"; import { runInAction } from "mobx"; import type { RequestChannelHandler } from "../../../main/utils/channel/channel-listeners/listener-tokens"; import { getRequestChannelListenerInjectable } from "../../../main/utils/channel/channel-listeners/listener-tokens"; +import type { RequestFromChannel } from "../../../renderer/utils/channel/request-from-channel.injectable"; +import requestFromChannelInjectable from "../../../renderer/utils/channel/request-from-channel.injectable"; type TestMessageChannel = MessageChannel; type TestRequestChannel = RequestChannel; @@ -164,9 +164,7 @@ describe("channel", () => { const windowDi = applicationBuilder.applicationWindow.only.di; - requestFromChannel = windowDi.inject( - requestFromChannelInjectionToken, - ); + requestFromChannel = windowDi.inject(requestFromChannelInjectable); }); describe("when requesting from channel", () => { diff --git a/src/common/utils/channel/request-channel-listener-injection-token.ts b/src/common/utils/channel/request-channel.ts similarity index 61% rename from src/common/utils/channel/request-channel-listener-injection-token.ts rename to src/common/utils/channel/request-channel.ts index 2f0b84a3cc..ec78f046eb 100644 --- a/src/common/utils/channel/request-channel-listener-injection-token.ts +++ b/src/common/utils/channel/request-channel.ts @@ -8,3 +8,11 @@ export interface RequestChannel { _requestSignature?: Request; // used only to mark `Request` as "used" _responseSignature?: Response; // used only to mark `Response` as "used" } + +export type ChannelRequest = Channel extends RequestChannel + ? Request + : never; + +export type ChannelResponse = Channel extends RequestChannel + ? Response + : never; diff --git a/src/common/utils/channel/request-from-channel-injection-token.ts b/src/common/utils/channel/request-from-channel-injection-token.ts deleted file mode 100644 index 14e925f190..0000000000 --- a/src/common/utils/channel/request-from-channel-injection-token.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ -import { getInjectionToken } from "@ogre-tools/injectable"; -import type { RequestChannel } from "./request-channel-listener-injection-token"; - -export interface RequestFromChannel { - (channel: RequestChannel, request: Request): Promise; - (channel: RequestChannel): Promise; -} - -export const requestFromChannelInjectionToken = getInjectionToken({ - id: "request-from-request-channel", -}); diff --git a/src/common/utils/resolve-system-proxy/resolve-system-proxy-channel.ts b/src/common/utils/resolve-system-proxy/resolve-system-proxy-channel.ts index c823a8a8f9..08e1ab1be7 100644 --- a/src/common/utils/resolve-system-proxy/resolve-system-proxy-channel.ts +++ b/src/common/utils/resolve-system-proxy/resolve-system-proxy-channel.ts @@ -2,7 +2,7 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { RequestChannel } from "../channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "../channel/request-channel"; export type ResolveSystemProxyChannel = RequestChannel; diff --git a/src/common/utils/sync-box/channels.ts b/src/common/utils/sync-box/channels.ts index 4df0462dc3..2bf1c3a7f9 100644 --- a/src/common/utils/sync-box/channels.ts +++ b/src/common/utils/sync-box/channels.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { MessageChannel } from "../channel/message-channel-listener-injection-token"; -import type { RequestChannel } from "../channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "../channel/request-channel"; export type SyncBoxChannel = MessageChannel<{ id: string; value: any }>; diff --git a/src/features/cluster/delete-dialog/common/clear-as-deleting-channel.ts b/src/features/cluster/delete-dialog/common/clear-as-deleting-channel.ts index bf33a23165..f5ebe63606 100644 --- a/src/features/cluster/delete-dialog/common/clear-as-deleting-channel.ts +++ b/src/features/cluster/delete-dialog/common/clear-as-deleting-channel.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { ClusterId } from "../../../../common/cluster-types"; -import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "../../../../common/utils/channel/request-channel"; export type ClearClusterAsDeletingChannel = RequestChannel; diff --git a/src/features/cluster/delete-dialog/common/delete-channel.ts b/src/features/cluster/delete-dialog/common/delete-channel.ts index 0e9142fcd3..ed5faa77a4 100644 --- a/src/features/cluster/delete-dialog/common/delete-channel.ts +++ b/src/features/cluster/delete-dialog/common/delete-channel.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { ClusterId } from "../../../../common/cluster-types"; -import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "../../../../common/utils/channel/request-channel"; export type DeleteClusterChannel = RequestChannel; diff --git a/src/features/cluster/delete-dialog/common/set-as-deleting-channel.ts b/src/features/cluster/delete-dialog/common/set-as-deleting-channel.ts index 57ef2e3a8d..906c1155d1 100644 --- a/src/features/cluster/delete-dialog/common/set-as-deleting-channel.ts +++ b/src/features/cluster/delete-dialog/common/set-as-deleting-channel.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { ClusterId } from "../../../../common/cluster-types"; -import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; +import type { RequestChannel } from "../../../../common/utils/channel/request-channel"; export type SetClusterAsDeletingChannel = RequestChannel; diff --git a/src/features/helm-charts/child-features/preferences/renderer/active-helm-repositories.injectable.ts b/src/features/helm-charts/child-features/preferences/renderer/active-helm-repositories.injectable.ts index 7a0d5e6b47..ca87c49bd7 100644 --- a/src/features/helm-charts/child-features/preferences/renderer/active-helm-repositories.injectable.ts +++ b/src/features/helm-charts/child-features/preferences/renderer/active-helm-repositories.injectable.ts @@ -5,16 +5,16 @@ import { getInjectable } from "@ogre-tools/injectable"; import { asyncComputed } from "@ogre-tools/injectable-react"; import { getActiveHelmRepositoriesChannel } from "../../../../../common/helm/get-active-helm-repositories-channel"; -import { requestFromChannelInjectionToken } from "../../../../../common/utils/channel/request-from-channel-injection-token"; import showErrorNotificationInjectable from "../../../../../renderer/components/notifications/show-error-notification.injectable"; import helmRepositoriesErrorStateInjectable from "./helm-repositories-error-state.injectable"; import { runInAction } from "mobx"; +import requestFromChannelInjectable from "../../../../../renderer/utils/channel/request-from-channel.injectable"; const activeHelmRepositoriesInjectable = getInjectable({ id: "active-helm-repositories", instantiate: (di) => { - const requestFromChannel = di.inject(requestFromChannelInjectionToken); + const requestFromChannel = di.inject(requestFromChannelInjectable); const showErrorNotification = di.inject(showErrorNotificationInjectable); const helmRepositoriesErrorState = di.inject( helmRepositoriesErrorStateInjectable, diff --git a/src/features/helm-charts/child-features/preferences/renderer/adding-of-public-helm-repository/select-helm-repository/add-helm-repository.injectable.ts b/src/features/helm-charts/child-features/preferences/renderer/adding-of-public-helm-repository/select-helm-repository/add-helm-repository.injectable.ts index 6b39d8dddf..b2cb8ab52f 100644 --- a/src/features/helm-charts/child-features/preferences/renderer/adding-of-public-helm-repository/select-helm-repository/add-helm-repository.injectable.ts +++ b/src/features/helm-charts/child-features/preferences/renderer/adding-of-public-helm-repository/select-helm-repository/add-helm-repository.injectable.ts @@ -4,17 +4,17 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { HelmRepo } from "../../../../../../../common/helm/helm-repo"; -import { requestFromChannelInjectionToken } from "../../../../../../../common/utils/channel/request-from-channel-injection-token"; import activeHelmRepositoriesInjectable from "../../active-helm-repositories.injectable"; import showErrorNotificationInjectable from "../../../../../../../renderer/components/notifications/show-error-notification.injectable"; import showSuccessNotificationInjectable from "../../../../../../../renderer/components/notifications/show-success-notification.injectable"; import { addHelmRepositoryChannel } from "../../../../../../../common/helm/add-helm-repository-channel"; +import requestFromChannelInjectable from "../../../../../../utils/channel/request-from-channel.injectable"; const addHelmRepositoryInjectable = getInjectable({ id: "add-public-helm-repository", instantiate: (di) => { - const requestFromChannel = di.inject(requestFromChannelInjectionToken); + const requestFromChannel = di.inject(requestFromChannelInjectable); const activeHelmRepositories = di.inject(activeHelmRepositoriesInjectable); const showErrorNotification = di.inject(showErrorNotificationInjectable); const showSuccessNotification = di.inject(showSuccessNotificationInjectable); diff --git a/src/features/helm-charts/child-features/preferences/renderer/remove-helm-repository.injectable.ts b/src/features/helm-charts/child-features/preferences/renderer/remove-helm-repository.injectable.ts index 3aa56a4b04..823ef1495e 100644 --- a/src/features/helm-charts/child-features/preferences/renderer/remove-helm-repository.injectable.ts +++ b/src/features/helm-charts/child-features/preferences/renderer/remove-helm-repository.injectable.ts @@ -4,15 +4,15 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { HelmRepo } from "../../../../../common/helm/helm-repo"; -import { requestFromChannelInjectionToken } from "../../../../../common/utils/channel/request-from-channel-injection-token"; import activeHelmRepositoriesInjectable from "./active-helm-repositories.injectable"; import { removeHelmRepositoryChannel } from "../../../../../common/helm/remove-helm-repository-channel"; +import requestFromChannelInjectable from "../../../../utils/channel/request-from-channel.injectable"; const removePublicHelmRepositoryInjectable = getInjectable({ id: "remove-public-helm-repository", instantiate: (di) => { - const requestFromChannel = di.inject(requestFromChannelInjectionToken); + const requestFromChannel = di.inject(requestFromChannelInjectable); const activeHelmRepositories = di.inject(activeHelmRepositoriesInjectable); return async (repository: HelmRepo) => { diff --git a/src/features/terminal/__image_snapshots__/opening-terminal-tab-test-tsx-test-for-opening-terminal-tab-within-cluster-frame-when-new-terminal-tab-is-opened-shows-connecting-message-1-snap.png b/src/features/terminal/__image_snapshots__/opening-terminal-tab-test-tsx-test-for-opening-terminal-tab-within-cluster-frame-when-new-terminal-tab-is-opened-shows-connecting-message-1-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..9d263a76b6c17658a103dc24eaa44e4e425bc7e7 GIT binary patch literal 593 zcmeAS@N?(olHy`uVBq!ia0y~yVAKJ!r*W_W$&~1=mw*&olDE4H!+#K5uy^@n1_mZJ zPZ!6KiaBquIPx+m2prhJ{D0m-Ci_iGLN{E$c4iJE$Bq5W3~`cT6A~jF+7cNh+gMX1 eMmfVS3}QTZn6&wB?yv@?5e83JKbLh*2~7YNGpUpS literal 0 HcmV?d00001 diff --git a/src/features/terminal/__snapshots__/opening-terminal-tab.test.tsx.snap b/src/features/terminal/__snapshots__/opening-terminal-tab.test.tsx.snap new file mode 100644 index 0000000000..99b888bc11 --- /dev/null +++ b/src/features/terminal/__snapshots__/opening-terminal-tab.test.tsx.snap @@ -0,0 +1,584 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test for opening terminal tab within cluster frame when new terminal tab is opened renders 1`] = ` + +
+
+
+
+