|
| 1 | +import { describe, expect, test } from "@jest/globals"; |
| 2 | +import { createErrorToast } from "./ChatInputToasts"; |
| 3 | +import type { SendMessageError } from "@/types/errors"; |
| 4 | + |
| 5 | +describe("ChatInputToasts", () => { |
| 6 | + describe("createErrorToast", () => { |
| 7 | + test("should create toast for api_key_not_found error", () => { |
| 8 | + const error: SendMessageError = { |
| 9 | + type: "api_key_not_found", |
| 10 | + provider: "openai", |
| 11 | + }; |
| 12 | + |
| 13 | + const toast = createErrorToast(error); |
| 14 | + |
| 15 | + expect(toast.type).toBe("error"); |
| 16 | + expect(toast.title).toBe("API Key Not Found"); |
| 17 | + expect(toast.message).toContain("openai"); |
| 18 | + expect(toast.message).toContain("API key"); |
| 19 | + }); |
| 20 | + |
| 21 | + test("should create toast for provider_not_supported error", () => { |
| 22 | + const error: SendMessageError = { |
| 23 | + type: "provider_not_supported", |
| 24 | + provider: "custom-provider", |
| 25 | + }; |
| 26 | + |
| 27 | + const toast = createErrorToast(error); |
| 28 | + |
| 29 | + expect(toast.type).toBe("error"); |
| 30 | + expect(toast.title).toBe("Provider Not Supported"); |
| 31 | + expect(toast.message).toContain("custom-provider"); |
| 32 | + }); |
| 33 | + |
| 34 | + test("should create toast for invalid_model_string error", () => { |
| 35 | + const error: SendMessageError = { |
| 36 | + type: "invalid_model_string", |
| 37 | + message: "Invalid format: expected provider:model", |
| 38 | + }; |
| 39 | + |
| 40 | + const toast = createErrorToast(error); |
| 41 | + |
| 42 | + expect(toast.type).toBe("error"); |
| 43 | + expect(toast.title).toBe("Invalid Model Format"); |
| 44 | + expect(toast.message).toBe("Invalid format: expected provider:model"); |
| 45 | + }); |
| 46 | + |
| 47 | + test("should create toast for unknown error with message", () => { |
| 48 | + const error: SendMessageError = { |
| 49 | + type: "unknown", |
| 50 | + raw: "Network connection failed", |
| 51 | + }; |
| 52 | + |
| 53 | + const toast = createErrorToast(error); |
| 54 | + |
| 55 | + expect(toast.type).toBe("error"); |
| 56 | + expect(toast.title).toBe("Message Send Failed"); |
| 57 | + expect(toast.message).toBe("Network connection failed"); |
| 58 | + }); |
| 59 | + |
| 60 | + test("should create toast for unknown error without message", () => { |
| 61 | + const error: SendMessageError = { |
| 62 | + type: "unknown", |
| 63 | + raw: "", |
| 64 | + }; |
| 65 | + |
| 66 | + const toast = createErrorToast(error); |
| 67 | + |
| 68 | + expect(toast.type).toBe("error"); |
| 69 | + expect(toast.title).toBe("Message Send Failed"); |
| 70 | + expect(toast.message).toContain("unexpected error"); |
| 71 | + }); |
| 72 | + }); |
| 73 | +}); |
0 commit comments