1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

chore: Rename injectables to remove redundancy

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-04-20 16:08:55 -04:00
parent 6c3e8e83c0
commit 4716dcc434
7 changed files with 61 additions and 61 deletions

View File

@ -12,8 +12,8 @@ import createEditResourceTabInjectable from "../../../renderer/components/dock/e
import getRandomIdForEditResourceTabInjectable from "../../../renderer/components/dock/edit-resource/get-random-id-for-edit-resource-tab.injectable"; import getRandomIdForEditResourceTabInjectable from "../../../renderer/components/dock/edit-resource/get-random-id-for-edit-resource-tab.injectable";
import type { AsyncFnMock } from "@async-fn/jest"; import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest"; import asyncFn from "@async-fn/jest";
import type { CallForPatchResource } from "../../../renderer/components/dock/edit-resource/edit-resource-model/call-for-patch-resource.injectable"; import type { RequestPatchKubeResource } from "../../../renderer/components/dock/edit-resource/edit-resource-model/request-patch-kube-resource.injectable";
import callForPatchResourceInjectable from "../../../renderer/components/dock/edit-resource/edit-resource-model/call-for-patch-resource.injectable"; import requestPatchKubeResourceInjectable from "../../../renderer/components/dock/edit-resource/edit-resource-model/request-patch-kube-resource.injectable";
import dockStoreInjectable from "../../../renderer/components/dock/dock/store.injectable"; import dockStoreInjectable from "../../../renderer/components/dock/dock/store.injectable";
import { Namespace } from "../../../common/k8s-api/endpoints"; import { Namespace } from "../../../common/k8s-api/endpoints";
import showSuccessNotificationInjectable from "../../../renderer/components/notifications/show-success-notification.injectable"; import showSuccessNotificationInjectable from "../../../renderer/components/notifications/show-success-notification.injectable";
@ -21,13 +21,13 @@ import showErrorNotificationInjectable from "../../../renderer/components/notifi
import readJsonFileInjectable from "../../../common/fs/read-json-file.injectable"; import readJsonFileInjectable from "../../../common/fs/read-json-file.injectable";
import directoryForLensLocalStorageInjectable from "../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable"; import directoryForLensLocalStorageInjectable from "../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable";
import hostedClusterIdInjectable from "../../../renderer/cluster-frame-context/hosted-cluster-id.injectable"; import hostedClusterIdInjectable from "../../../renderer/cluster-frame-context/hosted-cluster-id.injectable";
import type { CallForResource } from "../../../renderer/components/dock/edit-resource/edit-resource-model/call-for-resource.injectable"; import type { RequestKubeResource } from "../../../renderer/components/dock/edit-resource/edit-resource-model/request-kube-resource.injectable";
import callForResourceInjectable from "../../../renderer/components/dock/edit-resource/edit-resource-model/call-for-resource.injectable"; import requestKubeResourceInjectable from "../../../renderer/components/dock/edit-resource/edit-resource-model/request-kube-resource.injectable";
describe("cluster/namespaces - edit namespace from new tab", () => { describe("cluster/namespaces - edit namespace from new tab", () => {
let builder: ApplicationBuilder; let builder: ApplicationBuilder;
let callForResourceMock: AsyncFnMock<CallForResource>; let requestKubeResourceMock: AsyncFnMock<RequestKubeResource>;
let callForPatchResourceMock: AsyncFnMock<CallForPatchResource>; let requestPatchKubeResourceMock: AsyncFnMock<RequestPatchKubeResource>;
let showSuccessNotificationMock: jest.Mock; let showSuccessNotificationMock: jest.Mock;
let showErrorNotificationMock: jest.Mock; let showErrorNotificationMock: jest.Mock;
@ -57,11 +57,11 @@ describe("cluster/namespaces - edit namespace from new tab", () => {
.mockReturnValueOnce("some-second-tab-id"), .mockReturnValueOnce("some-second-tab-id"),
); );
callForResourceMock = asyncFn(); requestKubeResourceMock = asyncFn();
windowDi.override(callForResourceInjectable, () => callForResourceMock); windowDi.override(requestKubeResourceInjectable, () => requestKubeResourceMock);
callForPatchResourceMock = asyncFn(); requestPatchKubeResourceMock = asyncFn();
windowDi.override(callForPatchResourceInjectable, () => callForPatchResourceMock); windowDi.override(requestPatchKubeResourceInjectable, () => requestPatchKubeResourceMock);
}); });
builder.afterWindowStart(() => { builder.afterWindowStart(() => {
@ -156,7 +156,7 @@ describe("cluster/namespaces - edit namespace from new tab", () => {
}); });
it("calls for namespace", () => { it("calls for namespace", () => {
expect(callForResourceMock).toHaveBeenCalledWith( expect(requestKubeResourceMock).toHaveBeenCalledWith(
"/apis/some-api-version/namespaces/some-uid", "/apis/some-api-version/namespaces/some-uid",
); );
}); });
@ -179,7 +179,7 @@ describe("cluster/namespaces - edit namespace from new tab", () => {
}, },
}); });
await callForResourceMock.resolve({ await requestKubeResourceMock.resolve({
callWasSuccessful: true, callWasSuccessful: true,
response: someNamespace, response: someNamespace,
}); });
@ -226,7 +226,7 @@ metadata:
}); });
it("calls for save with just the adding version label", () => { it("calls for save with just the adding version label", () => {
expect(callForPatchResourceMock).toHaveBeenCalledWith( expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
someNamespace, someNamespace,
[{ [{
op: "add", op: "add",
@ -262,7 +262,7 @@ metadata:
describe("when saving resolves with success", () => { describe("when saving resolves with success", () => {
beforeEach(async () => { beforeEach(async () => {
await callForPatchResourceMock.resolve({ await requestPatchKubeResourceMock.resolve({
callWasSuccessful: true, callWasSuccessful: true,
response: { name: "some-name", kind: "Namespace" }, response: { name: "some-name", kind: "Namespace" },
}); });
@ -311,7 +311,7 @@ metadata:
describe("when saving resolves with failure", () => { describe("when saving resolves with failure", () => {
beforeEach(async () => { beforeEach(async () => {
await callForPatchResourceMock.resolve({ await requestPatchKubeResourceMock.resolve({
callWasSuccessful: false, callWasSuccessful: false,
error: "some-error", error: "some-error",
}); });
@ -380,7 +380,7 @@ metadata:
describe("when saving resolves with success", () => { describe("when saving resolves with success", () => {
beforeEach(async () => { beforeEach(async () => {
await callForPatchResourceMock.resolve({ await requestPatchKubeResourceMock.resolve({
callWasSuccessful: true, callWasSuccessful: true,
response: { name: "some-name", kind: "Namespace" }, response: { name: "some-name", kind: "Namespace" },
}); });
@ -399,7 +399,7 @@ metadata:
describe("when saving resolves with failure", () => { describe("when saving resolves with failure", () => {
beforeEach(async () => { beforeEach(async () => {
await callForPatchResourceMock.resolve({ await requestPatchKubeResourceMock.resolve({
callWasSuccessful: false, callWasSuccessful: false,
error: "Some error", error: "Some error",
}); });
@ -526,7 +526,7 @@ metadata:
}); });
it("calls for save with changed configuration", () => { it("calls for save with changed configuration", () => {
expect(callForPatchResourceMock).toHaveBeenCalledWith( expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
someNamespace, someNamespace,
[ [
{ {
@ -555,7 +555,7 @@ metadata:
}); });
it("given save resolves and another change in configuration, when saving, calls for save with changed configuration", async () => { it("given save resolves and another change in configuration, when saving, calls for save with changed configuration", async () => {
await callForPatchResourceMock.resolve({ await requestPatchKubeResourceMock.resolve({
callWasSuccessful: true, callWasSuccessful: true,
response: { response: {
@ -585,7 +585,7 @@ metadata:
}); });
callForPatchResourceMock.mockClear(); requestPatchKubeResourceMock.mockClear();
const saveButton = rendered.getByTestId( const saveButton = rendered.getByTestId(
"save-edit-resource-from-tab-for-some-first-tab-id", "save-edit-resource-from-tab-for-some-first-tab-id",
@ -593,7 +593,7 @@ metadata:
fireEvent.click(saveButton); fireEvent.click(saveButton);
expect(callForPatchResourceMock).toHaveBeenCalledWith( expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
someNamespace, someNamespace,
[ [
{ {
@ -692,7 +692,7 @@ metadata:
describe("given clicking the context menu for second namespace, when clicking to edit namespace", () => { describe("given clicking the context menu for second namespace, when clicking to edit namespace", () => {
beforeEach(() => { beforeEach(() => {
callForResourceMock.mockClear(); requestKubeResourceMock.mockClear();
// TODO: Make implementation match the description // TODO: Make implementation match the description
const namespaceStub = new Namespace(someOtherNamespaceDataStub); const namespaceStub = new Namespace(someOtherNamespaceDataStub);
@ -725,7 +725,7 @@ metadata:
}); });
it("calls for second namespace", () => { it("calls for second namespace", () => {
expect(callForResourceMock).toHaveBeenCalledWith( expect(requestKubeResourceMock).toHaveBeenCalledWith(
"/apis/some-api-version/namespaces/some-other-uid", "/apis/some-api-version/namespaces/some-other-uid",
); );
}); });
@ -747,7 +747,7 @@ metadata:
}, },
}); });
await callForResourceMock.resolve({ await requestKubeResourceMock.resolve({
callWasSuccessful: true, callWasSuccessful: true,
response: someOtherNamespace, response: someOtherNamespace,
}); });
@ -773,7 +773,7 @@ metadata:
}); });
it("when selecting to save, calls for save of second namespace with just the add edit version label", () => { it("when selecting to save, calls for save of second namespace with just the add edit version label", () => {
callForPatchResourceMock.mockClear(); requestPatchKubeResourceMock.mockClear();
const saveButton = rendered.getByTestId( const saveButton = rendered.getByTestId(
"save-edit-resource-from-tab-for-some-second-tab-id", "save-edit-resource-from-tab-for-some-second-tab-id",
@ -781,7 +781,7 @@ metadata:
fireEvent.click(saveButton); fireEvent.click(saveButton);
expect(callForPatchResourceMock).toHaveBeenCalledWith( expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
someOtherNamespace, someOtherNamespace,
[{ [{
op: "add", op: "add",
@ -795,7 +795,7 @@ metadata:
describe("when clicking dock tab for the first namespace", () => { describe("when clicking dock tab for the first namespace", () => {
beforeEach(() => { beforeEach(() => {
callForResourceMock.mockClear(); requestKubeResourceMock.mockClear();
const tab = rendered.getByTestId("dock-tab-for-some-first-tab-id"); const tab = rendered.getByTestId("dock-tab-for-some-first-tab-id");
@ -825,7 +825,7 @@ metadata:
}); });
it("does not call for namespace", () => { it("does not call for namespace", () => {
expect(callForResourceMock).not.toHaveBeenCalledWith("/apis/some-api-version/namespaces/some-uid"); expect(requestKubeResourceMock).not.toHaveBeenCalledWith("/apis/some-api-version/namespaces/some-uid");
}); });
it("has configuration in the editor", () => { it("has configuration in the editor", () => {
@ -846,7 +846,7 @@ metadata:
}); });
it("when selecting to save, calls for save of first namespace with just the new edit version label", () => { it("when selecting to save, calls for save of first namespace with just the new edit version label", () => {
callForPatchResourceMock.mockClear(); requestPatchKubeResourceMock.mockClear();
const saveButton = rendered.getByTestId( const saveButton = rendered.getByTestId(
"save-edit-resource-from-tab-for-some-first-tab-id", "save-edit-resource-from-tab-for-some-first-tab-id",
@ -854,7 +854,7 @@ metadata:
fireEvent.click(saveButton); fireEvent.click(saveButton);
expect(callForPatchResourceMock).toHaveBeenCalledWith( expect(requestPatchKubeResourceMock).toHaveBeenCalledWith(
someNamespace, someNamespace,
[ { [ {
op: "add", op: "add",
@ -872,7 +872,7 @@ metadata:
describe("when call for namespace resolves without namespace", () => { describe("when call for namespace resolves without namespace", () => {
beforeEach(async () => { beforeEach(async () => {
await callForResourceMock.resolve({ await requestKubeResourceMock.resolve({
callWasSuccessful: true, callWasSuccessful: true,
response: undefined, response: undefined,
}); });
@ -901,7 +901,7 @@ metadata:
describe("when call for namespace resolves with failure", () => { describe("when call for namespace resolves with failure", () => {
beforeEach(async () => { beforeEach(async () => {
await callForResourceMock.resolve({ await requestKubeResourceMock.resolve({
callWasSuccessful: false, callWasSuccessful: false,
error: "some-error", error: "some-error",
}); });

View File

@ -8,8 +8,8 @@ import type { ApplicationBuilder } from "../../../renderer/components/test-utils
import { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import type { AsyncFnMock } from "@async-fn/jest"; import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest"; import asyncFn from "@async-fn/jest";
import type { CallForResource } from "../../../renderer/components/dock/edit-resource/edit-resource-model/call-for-resource.injectable"; import type { RequestKubeResource } from "../../../renderer/components/dock/edit-resource/edit-resource-model/request-kube-resource.injectable";
import callForResourceInjectable from "../../../renderer/components/dock/edit-resource/edit-resource-model/call-for-resource.injectable"; import requestKubeResourceInjectable from "../../../renderer/components/dock/edit-resource/edit-resource-model/request-kube-resource.injectable";
import directoryForLensLocalStorageInjectable from "../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable"; import directoryForLensLocalStorageInjectable from "../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable";
import writeJsonFileInjectable from "../../../common/fs/write-json-file.injectable"; import writeJsonFileInjectable from "../../../common/fs/write-json-file.injectable";
import { TabKind } from "../../../renderer/components/dock/dock/store"; import { TabKind } from "../../../renderer/components/dock/dock/store";
@ -17,14 +17,14 @@ import { Namespace } from "../../../common/k8s-api/endpoints";
describe("cluster/namespaces - edit namespaces from previously opened tab", () => { describe("cluster/namespaces - edit namespaces from previously opened tab", () => {
let builder: ApplicationBuilder; let builder: ApplicationBuilder;
let callForNamespaceMock: AsyncFnMock<CallForResource>; let requestKubeResourceMock: AsyncFnMock<RequestKubeResource>;
beforeEach(() => { beforeEach(() => {
builder = getApplicationBuilder(); builder = getApplicationBuilder();
builder.setEnvironmentToClusterFrame(); builder.setEnvironmentToClusterFrame();
callForNamespaceMock = asyncFn(); requestKubeResourceMock = asyncFn();
builder.beforeWindowStart(({ windowDi }) => { builder.beforeWindowStart(({ windowDi }) => {
windowDi.override( windowDi.override(
@ -32,7 +32,7 @@ describe("cluster/namespaces - edit namespaces from previously opened tab", () =
() => "/some-directory-for-lens-local-storage", () => "/some-directory-for-lens-local-storage",
); );
windowDi.override(callForResourceInjectable, () => callForNamespaceMock); windowDi.override(requestKubeResourceInjectable, () => requestKubeResourceMock);
}); });
builder.afterWindowStart(() => { builder.afterWindowStart(() => {
@ -97,7 +97,7 @@ describe("cluster/namespaces - edit namespaces from previously opened tab", () =
}); });
it("calls for namespace", () => { it("calls for namespace", () => {
expect(callForNamespaceMock).toHaveBeenCalledWith( expect(requestKubeResourceMock).toHaveBeenCalledWith(
"/apis/some-api-version/namespaces/some-uid", "/apis/some-api-version/namespaces/some-uid",
); );
}); });
@ -122,7 +122,7 @@ describe("cluster/namespaces - edit namespaces from previously opened tab", () =
// TODO: Figure out why act is needed here. In CI it works without it. // TODO: Figure out why act is needed here. In CI it works without it.
await act(async () => { await act(async () => {
await callForNamespaceMock.resolve({ await requestKubeResourceMock.resolve({
callWasSuccessful: true, callWasSuccessful: true,
response: someNamespace, response: someNamespace,
}); });

View File

@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import type { CallForResource } from "./call-for-resource.injectable"; import type { RequestKubeResource } from "./request-kube-resource.injectable";
import callForResourceInjectable from "./call-for-resource.injectable"; import requestKubeResourceInjectable from "./request-kube-resource.injectable";
import { waitUntilDefined } from "@k8slens/utilities"; import { waitUntilDefined } from "@k8slens/utilities";
import editResourceTabStoreInjectable from "../store.injectable"; import editResourceTabStoreInjectable from "../store.injectable";
import type { EditingResource, EditResourceTabStore } from "../store"; import type { EditingResource, EditResourceTabStore } from "../store";
@ -12,8 +12,8 @@ import { action, computed, observable, runInAction } from "mobx";
import type { KubeObject, RawKubeObject } from "../../../../../common/k8s-api/kube-object"; import type { KubeObject, RawKubeObject } from "../../../../../common/k8s-api/kube-object";
import yaml from "js-yaml"; import yaml from "js-yaml";
import assert from "assert"; import assert from "assert";
import type { CallForPatchResource } from "./call-for-patch-resource.injectable"; import type { RequestPatchKubeResource } from "./request-patch-kube-resource.injectable";
import callForPatchResourceInjectable from "./call-for-patch-resource.injectable"; import requestPatchKubeResourceInjectable from "./request-patch-kube-resource.injectable";
import { createPatch } from "rfc6902"; import { createPatch } from "rfc6902";
import type { ShowNotification } from "../../../notifications"; import type { ShowNotification } from "../../../notifications";
import showSuccessNotificationInjectable from "../../../notifications/show-success-notification.injectable"; import showSuccessNotificationInjectable from "../../../notifications/show-success-notification.injectable";
@ -28,8 +28,8 @@ const editResourceModelInjectable = getInjectable({
const store = di.inject(editResourceTabStoreInjectable); const store = di.inject(editResourceTabStoreInjectable);
const model = new EditResourceModel({ const model = new EditResourceModel({
callForResource: di.inject(callForResourceInjectable), callForResource: di.inject(requestKubeResourceInjectable),
callForPatchResource: di.inject(callForPatchResourceInjectable), callForPatchResource: di.inject(requestPatchKubeResourceInjectable),
showSuccessNotification: di.inject(showSuccessNotificationInjectable), showSuccessNotification: di.inject(showSuccessNotificationInjectable),
showErrorNotification: di.inject(showErrorNotificationInjectable), showErrorNotification: di.inject(showErrorNotificationInjectable),
store, store,
@ -50,8 +50,8 @@ const editResourceModelInjectable = getInjectable({
export default editResourceModelInjectable; export default editResourceModelInjectable;
interface Dependencies { interface Dependencies {
callForResource: CallForResource; callForResource: RequestKubeResource;
callForPatchResource: CallForPatchResource; callForPatchResource: RequestPatchKubeResource;
waitForEditingResource: () => Promise<EditingResource>; waitForEditingResource: () => Promise<EditingResource>;
showSuccessNotification: ShowNotification; showSuccessNotification: ShowNotification;
showErrorNotification: ShowNotification; showErrorNotification: ShowNotification;

View File

@ -3,9 +3,9 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getGlobalOverride } from "@k8slens/test-utils"; import { getGlobalOverride } from "@k8slens/test-utils";
import callForResourceInjectable from "./call-for-resource.injectable"; import requestKubeResourceInjectable from "./request-kube-resource.injectable";
export default getGlobalOverride(callForResourceInjectable, () => () => { export default getGlobalOverride(requestKubeResourceInjectable, () => () => {
throw new Error( throw new Error(
"Tried to call for kube resource without explicit override.", "Tried to call for kube resource without explicit override.",
); );

View File

@ -9,12 +9,12 @@ import type { AsyncResult } from "@k8slens/utilities";
import { getErrorMessage } from "../../../../../common/utils/get-error-message"; import { getErrorMessage } from "../../../../../common/utils/get-error-message";
import apiKubeInjectable from "../../../../k8s/api-kube.injectable"; import apiKubeInjectable from "../../../../k8s/api-kube.injectable";
export type CallForResource = (selfLink: string) => AsyncResult<KubeObject | undefined>; export type RequestKubeResource = (selfLink: string) => AsyncResult<KubeObject | undefined>;
const callForResourceInjectable = getInjectable({ const requestKubeResourceInjectable = getInjectable({
id: "call-for-resource", id: "request-kube-resource",
instantiate: (di): CallForResource => { instantiate: (di): RequestKubeResource => {
const apiKube = di.inject(apiKubeInjectable); const apiKube = di.inject(apiKubeInjectable);
return async (apiPath: string) => { return async (apiPath: string) => {
@ -38,4 +38,4 @@ const callForResourceInjectable = getInjectable({
causesSideEffects: true, causesSideEffects: true,
}); });
export default callForResourceInjectable; export default requestKubeResourceInjectable;

View File

@ -3,9 +3,9 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getGlobalOverride } from "@k8slens/test-utils"; import { getGlobalOverride } from "@k8slens/test-utils";
import callForPatchResourceInjectable from "./call-for-patch-resource.injectable"; import requestPatchKubeResourceInjectable from "./request-patch-kube-resource.injectable";
export default getGlobalOverride(callForPatchResourceInjectable, () => () => { export default getGlobalOverride(requestPatchKubeResourceInjectable, () => () => {
throw new Error( throw new Error(
"Tried to call patching of kube resource without explicit override.", "Tried to call patching of kube resource without explicit override.",
); );

View File

@ -10,14 +10,14 @@ import type { KubeObject } from "../../../../../common/k8s-api/kube-object";
import assert from "assert"; import assert from "assert";
import { getErrorMessage } from "../../../../../common/utils/get-error-message"; import { getErrorMessage } from "../../../../../common/utils/get-error-message";
export type CallForPatchResource = ( export type RequestPatchKubeResource = (
item: KubeObject, item: KubeObject,
patch: JsonPatch patch: JsonPatch
) => AsyncResult<{ name: string; kind: string }>; ) => AsyncResult<{ name: string; kind: string }>;
const callForPatchResourceInjectable = getInjectable({ const requestPatchKubeResourceInjectable = getInjectable({
id: "call-for-patch-resource", id: "request-patch-kube-resource",
instantiate: (di): CallForPatchResource => { instantiate: (di): RequestPatchKubeResource => {
const apiManager = di.inject(apiManagerInjectable); const apiManager = di.inject(apiManagerInjectable);
return async (item, patch) => { return async (item, patch) => {
@ -46,4 +46,4 @@ const callForPatchResourceInjectable = getInjectable({
causesSideEffects: true, causesSideEffects: true,
}); });
export default callForPatchResourceInjectable; export default requestPatchKubeResourceInjectable;