114 lines
3.0 KiB
JavaScript
114 lines
3.0 KiB
JavaScript
const React = require("react");
|
|
const ErrorDisplay = require("../../../../src/tui/components/common/ErrorDisplay.jsx");
|
|
|
|
describe("ErrorDisplay Component", () => {
|
|
it("should create ErrorDisplay component without crashing", () => {
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: "Test error message",
|
|
});
|
|
|
|
expect(component).toBeDefined();
|
|
expect(component.type).toBe(ErrorDisplay);
|
|
expect(component.props.error).toBe("Test error message");
|
|
});
|
|
|
|
it("should accept custom title prop", () => {
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: "Test error",
|
|
title: "Custom Error Title",
|
|
});
|
|
|
|
expect(component.props.title).toBe("Custom Error Title");
|
|
});
|
|
|
|
it("should handle error objects with message property", () => {
|
|
const error = new Error("Object error message");
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: error,
|
|
});
|
|
|
|
expect(component.props.error).toBe(error);
|
|
expect(component.props.error.message).toBe("Object error message");
|
|
});
|
|
|
|
it("should handle error objects with name and code", () => {
|
|
const error = {
|
|
name: "ValidationError",
|
|
code: "INVALID_INPUT",
|
|
message: "Invalid input provided",
|
|
};
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: error,
|
|
});
|
|
|
|
expect(component.props.error.name).toBe("ValidationError");
|
|
expect(component.props.error.message).toBe("Invalid input provided");
|
|
});
|
|
|
|
it("should accept compact mode prop", () => {
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: "Test error",
|
|
compact: true,
|
|
});
|
|
|
|
expect(component.props.compact).toBe(true);
|
|
});
|
|
|
|
it("should accept onRetry callback", () => {
|
|
const mockRetry = jest.fn();
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: "Test error",
|
|
onRetry: mockRetry,
|
|
});
|
|
|
|
expect(component.props.onRetry).toBe(mockRetry);
|
|
});
|
|
|
|
it("should accept onDismiss callback", () => {
|
|
const mockDismiss = jest.fn();
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: "Test error",
|
|
onDismiss: mockDismiss,
|
|
});
|
|
|
|
expect(component.props.onDismiss).toBe(mockDismiss);
|
|
});
|
|
|
|
it("should accept showRetry prop", () => {
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: "Test error",
|
|
showRetry: false,
|
|
});
|
|
|
|
expect(component.props.showRetry).toBe(false);
|
|
});
|
|
|
|
it("should accept showDismiss prop", () => {
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: "Test error",
|
|
showDismiss: false,
|
|
});
|
|
|
|
expect(component.props.showDismiss).toBe(false);
|
|
});
|
|
|
|
it("should accept custom retry and dismiss text", () => {
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: "Test error",
|
|
retryText: "Custom retry text",
|
|
dismissText: "Custom dismiss text",
|
|
});
|
|
|
|
expect(component.props.retryText).toBe("Custom retry text");
|
|
expect(component.props.dismissText).toBe("Custom dismiss text");
|
|
});
|
|
|
|
it("should handle null error gracefully", () => {
|
|
const component = React.createElement(ErrorDisplay, {
|
|
error: null,
|
|
});
|
|
|
|
expect(component.props.error).toBe(null);
|
|
});
|
|
});
|