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:
parent
6342458419
commit
86a333b25a
@ -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<typeof execFileInjectable["instantiate"]>
|
||||
@ -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");
|
||||
|
||||
@ -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();
|
||||
};
|
||||
},
|
||||
|
||||
@ -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;
|
||||
Loading…
Reference in New Issue
Block a user