Skip to content
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions web_src/.eslint-budget-baseline.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
{
"maxAllowedTotalIssues": 1274,
"maxAllowedTotalIssues": 1229,
"maxAllowedByRule": {
"@typescript-eslint/no-explicit-any": 360,
"complexity": 273,
"@typescript-eslint/consistent-type-imports": 200,
"max-statements": 103,
"max-lines-per-function": 97,
"@typescript-eslint/no-non-null-asserted-optional-chain": 97,
"@typescript-eslint/no-explicit-any": 344,
"complexity": 271,
"@typescript-eslint/consistent-type-imports": 194,
"max-statements": 102,
"max-lines-per-function": 96,
"@typescript-eslint/no-non-null-asserted-optional-chain": 87,
"react-hooks/exhaustive-deps": 59,
"max-lines": 26,
"react-refresh/only-export-components": 26,
"react-refresh/only-export-components": 25,
"max-depth": 11,
"max-params": 8,
"jsx-a11y/label-has-associated-control": 6,
"react-hooks/rules-of-hooks": 4,
"no-case-declarations": 2,
"max-params": 6,
"no-constant-binary-expression": 2
},
"updatedAt": "2026-03-31T21:52:06.539Z"
"updatedAt": "2026-04-01T18:48:33.433Z"
}
108 changes: 108 additions & 0 deletions web_src/src/pages/workflowv2/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { QueryClient } from "@tanstack/react-query";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { ComponentsComponent, ComponentsNode } from "@/api-client";
import type { CustomFieldRenderer } from "./mappers/types";
import * as mappers from "./mappers";
import { prepareComponentBaseNode } from "./lib/canvas-node-preparation";
import { renderWorkflowNodeCustomField } from "./lib/render-workflow-node-custom-field";

type FallbackComponentData = {
renderFallback?: {
source: string;
message: string;
};
component: {
error?: string;
emptyStateProps?: {
title?: string;
};
};
};

function makeNode(overrides: Partial<ComponentsNode> = {}): ComponentsNode {
return {
id: "node-1",
name: "Broken Component",
type: "TYPE_COMPONENT",
position: { x: 10, y: 20 },
component: {
name: "approval",
},
configuration: {},
...overrides,
} as ComponentsNode;
}

function makeComponent(overrides: Partial<ComponentsComponent> = {}): ComponentsComponent {
return {
name: "approval",
label: "Approval",
icon: "hand",
color: "orange",
outputChannels: [{ name: "default" }],
...overrides,
} as ComponentsComponent;
}

describe("workflow node preparation resilience", () => {
beforeEach(() => {
vi.restoreAllMocks();
});

it("returns a fallback canvas node when component preparation fails", () => {
vi.spyOn(mappers, "getComponentAdditionalDataBuilder").mockReturnValue({
buildAdditionalData: () => {
throw new Error("builder failed");
},
});
vi.spyOn(mappers, "getComponentBaseMapper").mockReturnValue({
props: () => {
throw new Error("mapper failed");
},
subtitle: () => "",
getExecutionDetails: () => ({}),
});

const result = prepareComponentBaseNode({
nodes: [makeNode()],
node: makeNode(),
components: [makeComponent()],
nodeExecutionsMap: {},
nodeQueueItemsMap: {},
workflowId: "canvas-1",
queryClient: new QueryClient(),
organizationId: "org-1",
});

const fallbackData = result.data as unknown as FallbackComponentData;

expect(fallbackData.renderFallback).toEqual({
source: "mapper",
message: "Can't display",
});
expect(fallbackData.component.error).toBeUndefined();
expect(fallbackData.component.emptyStateProps?.title).toBe("Can't display");
});

it("returns null when a custom field renderer throws so sidebar rendering stays alive", () => {
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
const renderer: CustomFieldRenderer = {
render: () => {
throw new Error("custom field failed");
},
};

const result = renderWorkflowNodeCustomField({
renderer,
node: makeNode(),
nodeId: "node-1",
});

expect(result).toBeNull();
expect(consoleSpy).toHaveBeenCalledWith(
expect.stringContaining('Failed to render custom field for node "node-1"'),
expect.any(Error),
);
consoleSpy.mockRestore();
});
});
Loading
Loading