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

Add success notification for activating custom helm repository

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-06-07 07:44:20 +03:00
parent 6342458419
commit 86a333b25a
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
3 changed files with 47 additions and 0 deletions

View File

@ -14,6 +14,8 @@ import getActiveHelmRepositoriesInjectable from "../../main/helm/repositories/ge
import type { HelmRepo } from "../../common/helm-repo"; 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 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 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 // TODO: Make tooltips free of side effects by making it deterministic
jest.mock("../../renderer/components/tooltip/withTooltip", () => ({ jest.mock("../../renderer/components/tooltip/withTooltip", () => ({
@ -22,6 +24,7 @@ jest.mock("../../renderer/components/tooltip/withTooltip", () => ({
describe("activate custom helm repository in preferences", () => { describe("activate custom helm repository in preferences", () => {
let applicationBuilder: ApplicationBuilder; let applicationBuilder: ApplicationBuilder;
let showSuccessNotificationMock: jest.Mock;
let rendered: RenderResult; let rendered: RenderResult;
let execFileMock: AsyncFnMock< let execFileMock: AsyncFnMock<
ReturnType<typeof execFileInjectable["instantiate"]> ReturnType<typeof execFileInjectable["instantiate"]>
@ -39,6 +42,10 @@ describe("activate custom helm repository in preferences", () => {
applicationBuilder.beforeApplicationStart(({ mainDi, rendererDi }) => { applicationBuilder.beforeApplicationStart(({ mainDi, rendererDi }) => {
rendererDi.override(callForPublicHelmRepositoriesInjectable, () => async () => []); rendererDi.override(callForPublicHelmRepositoriesInjectable, () => async () => []);
showSuccessNotificationMock = jest.fn();
rendererDi.override(showSuccessNotificationInjectable, () => showSuccessNotificationMock);
rendererDi.override(isPathInjectable, () => ({ debounce: 0, validate: async () => {} })); rendererDi.override(isPathInjectable, () => ({ debounce: 0, validate: async () => {} }));
mainDi.override( mainDi.override(
@ -168,6 +175,10 @@ describe("activate custom helm repository in preferences", () => {
expect(getActiveHelmRepositoriesMock).not.toHaveBeenCalled(); expect(getActiveHelmRepositoriesMock).not.toHaveBeenCalled();
}); });
it("does not show notification yet", () => {
expect(showSuccessNotificationMock).not.toHaveBeenCalled();
});
describe("when activating resolves", () => { describe("when activating resolves", () => {
beforeEach(async () => { beforeEach(async () => {
await execFileMock.resolveSpecific( await execFileMock.resolveSpecific(
@ -192,6 +203,12 @@ describe("activate custom helm repository in preferences", () => {
expect(getActiveHelmRepositoriesMock).toHaveBeenCalled(); expect(getActiveHelmRepositoriesMock).toHaveBeenCalled();
}); });
it("shows the notification", () => {
expect(showSuccessNotificationMock).toHaveBeenCalledWith(
"Helm repository some-custom-repository has been added.",
);
});
describe("when adding custom repository again", () => { describe("when adding custom repository again", () => {
beforeEach(() => { beforeEach(() => {
const button = rendered.getByTestId("add-custom-helm-repo-button"); const button = rendered.getByTestId("add-custom-helm-repo-button");

View File

@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import type { HelmRepo } from "../../../../../../common/helm-repo"; import type { HelmRepo } from "../../../../../../common/helm-repo";
import activateHelmRepositoryInjectable from "../activation-of-public-helm-repository/select-helm-repository/activate-helm-repository.injectable"; 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 hideDialogForActivatingCustomHelmRepositoryInjectable from "./dialog-visibility/hide-dialog-for-activating-custom-helm-repository.injectable";
import showSuccessNotificationInjectable from "../../../../notifications/show-success-notification.injectable";
const submitCustomHelmRepositoryInjectable = getInjectable({ const submitCustomHelmRepositoryInjectable = getInjectable({
id: "submit-custom-helm-repository", id: "submit-custom-helm-repository",
@ -13,10 +14,13 @@ const submitCustomHelmRepositoryInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const activateHelmRepository = di.inject(activateHelmRepositoryInjectable); const activateHelmRepository = di.inject(activateHelmRepositoryInjectable);
const hideDialog = di.inject(hideDialogForActivatingCustomHelmRepositoryInjectable); const hideDialog = di.inject(hideDialogForActivatingCustomHelmRepositoryInjectable);
const showSuccessNotification = di.inject(showSuccessNotificationInjectable);
return async (repository: HelmRepo) => { return async (repository: HelmRepo) => {
await activateHelmRepository(repository); await activateHelmRepository(repository);
showSuccessNotification(`Helm repository ${repository.name} has been added.`);
hideDialog(); hideDialog();
}; };
}, },

View File

@ -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<Omit<Notification, "message">> = {}) =>
notificationsStore.add({
status: NotificationStatus.OK,
timeout: 5000,
message,
...customOpts,
});
},
});
export default showSuccessNotificationInjectable;