diff --git a/src/behaviours/helm-charts/activate-custom-helm-repository-preferences.test.ts b/src/behaviours/helm-charts/activate-custom-helm-repository-preferences.test.ts index bbac3e8ca3..35226f1e47 100644 --- a/src/behaviours/helm-charts/activate-custom-helm-repository-preferences.test.ts +++ b/src/behaviours/helm-charts/activate-custom-helm-repository-preferences.test.ts @@ -14,6 +14,8 @@ import getActiveHelmRepositoriesInjectable from "../../main/helm/repositories/ge import type { HelmRepo } from "../../common/helm-repo"; import callForPublicHelmRepositoriesInjectable from "../../renderer/components/+preferences/kubernetes/helm-charts/activation-of-public-helm-repository/public-helm-repositories/call-for-public-helm-repositories.injectable"; import isPathInjectable from "../../renderer/components/input/validators/is-path.injectable"; +import showSuccessNotificationInjectable + from "../../renderer/components/notifications/show-success-notification.injectable"; // TODO: Make tooltips free of side effects by making it deterministic jest.mock("../../renderer/components/tooltip/withTooltip", () => ({ @@ -22,6 +24,7 @@ jest.mock("../../renderer/components/tooltip/withTooltip", () => ({ describe("activate custom helm repository in preferences", () => { let applicationBuilder: ApplicationBuilder; + let showSuccessNotificationMock: jest.Mock; let rendered: RenderResult; let execFileMock: AsyncFnMock< ReturnType @@ -39,6 +42,10 @@ describe("activate custom helm repository in preferences", () => { applicationBuilder.beforeApplicationStart(({ mainDi, rendererDi }) => { rendererDi.override(callForPublicHelmRepositoriesInjectable, () => async () => []); + showSuccessNotificationMock = jest.fn(); + + rendererDi.override(showSuccessNotificationInjectable, () => showSuccessNotificationMock); + rendererDi.override(isPathInjectable, () => ({ debounce: 0, validate: async () => {} })); mainDi.override( @@ -168,6 +175,10 @@ describe("activate custom helm repository in preferences", () => { expect(getActiveHelmRepositoriesMock).not.toHaveBeenCalled(); }); + it("does not show notification yet", () => { + expect(showSuccessNotificationMock).not.toHaveBeenCalled(); + }); + describe("when activating resolves", () => { beforeEach(async () => { await execFileMock.resolveSpecific( @@ -192,6 +203,12 @@ describe("activate custom helm repository in preferences", () => { expect(getActiveHelmRepositoriesMock).toHaveBeenCalled(); }); + it("shows the notification", () => { + expect(showSuccessNotificationMock).toHaveBeenCalledWith( + "Helm repository some-custom-repository has been added.", + ); + }); + describe("when adding custom repository again", () => { beforeEach(() => { const button = rendered.getByTestId("add-custom-helm-repo-button"); diff --git a/src/renderer/components/+preferences/kubernetes/helm-charts/activation-of-custom-helm-repository/submit-custom-helm-repository.injectable.ts b/src/renderer/components/+preferences/kubernetes/helm-charts/activation-of-custom-helm-repository/submit-custom-helm-repository.injectable.ts index 0575faa010..4793cd5973 100644 --- a/src/renderer/components/+preferences/kubernetes/helm-charts/activation-of-custom-helm-repository/submit-custom-helm-repository.injectable.ts +++ b/src/renderer/components/+preferences/kubernetes/helm-charts/activation-of-custom-helm-repository/submit-custom-helm-repository.injectable.ts @@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import type { HelmRepo } from "../../../../../../common/helm-repo"; import activateHelmRepositoryInjectable from "../activation-of-public-helm-repository/select-helm-repository/activate-helm-repository.injectable"; import hideDialogForActivatingCustomHelmRepositoryInjectable from "./dialog-visibility/hide-dialog-for-activating-custom-helm-repository.injectable"; +import showSuccessNotificationInjectable from "../../../../notifications/show-success-notification.injectable"; const submitCustomHelmRepositoryInjectable = getInjectable({ id: "submit-custom-helm-repository", @@ -13,10 +14,13 @@ const submitCustomHelmRepositoryInjectable = getInjectable({ instantiate: (di) => { const activateHelmRepository = di.inject(activateHelmRepositoryInjectable); const hideDialog = di.inject(hideDialogForActivatingCustomHelmRepositoryInjectable); + const showSuccessNotification = di.inject(showSuccessNotificationInjectable); return async (repository: HelmRepo) => { await activateHelmRepository(repository); + showSuccessNotification(`Helm repository ${repository.name} has been added.`); + hideDialog(); }; }, diff --git a/src/renderer/components/notifications/show-success-notification.injectable.ts b/src/renderer/components/notifications/show-success-notification.injectable.ts new file mode 100644 index 0000000000..875af209e2 --- /dev/null +++ b/src/renderer/components/notifications/show-success-notification.injectable.ts @@ -0,0 +1,26 @@ +/** + * 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 type { NotificationMessage, Notification } from "./notifications.store"; +import { NotificationStatus } from "./notifications.store"; +import notificationsStoreInjectable from "./notifications-store.injectable"; + +const showSuccessNotificationInjectable = getInjectable({ + id: "show-success-notification", + + instantiate: (di) => { + const notificationsStore = di.inject(notificationsStoreInjectable); + + return (message: NotificationMessage, customOpts: Partial> = {}) => + notificationsStore.add({ + status: NotificationStatus.OK, + timeout: 5000, + message, + ...customOpts, + }); + }, +}); + +export default showSuccessNotificationInjectable;