Key Already Exist Error Notification (#15993)

This commit is contained in:
yuneng-jiang 2025-10-27 18:00:38 -07:00 • committed by GitHub
parent a3d64fb843
commit 43af45ab88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 1 deletions

View file

@ -0,0 +1,41 @@
import { describe, it, expect, beforeEach, vi } from "vitest";
import { notification } from "antd";
import NotificationManager from "./notifications_manager";
// Mock the antd notification module
vi.mock("antd", () => ({
notification: {
error: vi.fn(),
warning: vi.fn(),
info: vi.fn(),
success: vi.fn(),
destroy: vi.fn(),
},
}));
describe("NotificationManager", () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe("Already Exists case", () => {
it("should show error notification for 'already exists' message", () => {
const error = {
message: "Key with alias 'test10' already exists.",
type: "bad_request_error",
code: "400",
};
NotificationManager.fromBackend(error);
expect(notification.error).toHaveBeenCalledWith(
expect.objectContaining({
message: "Already Exists",
description: "Key with alias 'test10' already exists.",
duration: 6,
placement: "topRight",
}),
);
});
});
});

View file

@ -317,7 +317,8 @@ const NotificationManager = {
title === "Authentication Error" ||
title === "Access Denied" ||
title === "Not Found" ||
title === "Error"
title === "Error" ||
title === "Already Exists"
) {
notification.error({ ...payload, duration: extra?.duration ?? 6 });
return;