Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Fix bug with node names with certain characters #8013

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
182 changes: 182 additions & 0 deletions packages/editor-ui/src/composables/__tests__/useNodeHelpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { setActivePinia } from 'pinia';
import { createTestingPinia } from '@pinia/testing';
import { useNodeHelpers } from '@/composables/useNodeHelpers';
import { createTestNode } from '@/__tests__/mocks';
import { useWorkflowsStore } from '@/stores/workflows.store';

vi.mock('@/stores/workflows.store', () => ({
useWorkflowsStore: vi.fn(),
}));

describe('useNodeHelpers()', () => {
beforeAll(() => {
setActivePinia(createTestingPinia());
});

afterEach(() => {
vi.clearAllMocks();
});

describe('getNodeInputData()', () => {
it('should return an empty array when node is null', () => {
const { getNodeInputData } = useNodeHelpers();

const result = getNodeInputData(null);
expect(result).toEqual([]);
});

it('should return an empty array when workflowsStore.getWorkflowExecution() is null', () => {
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: null,
} as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: 'test',
type: 'test',
});

const result = getNodeInputData(node);
expect(result).toEqual([]);
});

it('should return an empty array when workflowsStore.getWorkflowExecution() is null', () => {
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: null,
} as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: 'test',
type: 'test',
});

const result = getNodeInputData(node);
expect(result).toEqual([]);
});

it('should return an empty array when resultData is not available', () => {
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: null,
},
},
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: 'test',
type: 'test',
});

const result = getNodeInputData(node);
expect(result).toEqual([]);
});

it('should return an empty array when taskData is unavailable', () => {
const nodeName = 'Code';
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: {
runData: {
[nodeName]: [],
},
},
},
},
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: nodeName,
type: 'test',
});

const result = getNodeInputData(node);
expect(result).toEqual([]);
});

it('should return an empty array when taskData.data is unavailable', () => {
const nodeName = 'Code';
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: {
runData: {
[nodeName]: [{ data: undefined }],
},
},
},
},
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: nodeName,
type: 'test',
});

const result = getNodeInputData(node);
expect(result).toEqual([]);
});

it('should return input data from inputOverride', () => {
const nodeName = 'Code';
const data = { hello: 'world' };
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: {
runData: {
[nodeName]: [
{
inputOverride: {
main: [data],
},
},
],
},
},
},
},
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: nodeName,
type: 'test',
});

const result = getNodeInputData(node, 0, 0, 'input');
expect(result).toEqual(data);
});

it.each(['example', 'example.withdot', 'example.with.dots', 'example.with.dots and spaces'])(
'should return input data for "%s" node name, with given connection type and output index',
(nodeName) => {
const data = { hello: 'world' };
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: {
runData: {
[nodeName]: [
{
data: {
main: [data],
},
},
],
},
},
},
},
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: nodeName,
type: 'test',
});

const result = getNodeInputData(node);
expect(result).toEqual(data);
},
);
});
});
2 changes: 1 addition & 1 deletion packages/editor-ui/src/composables/useNodeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export function useNodeHelpers() {
}
const runData = executionData.resultData.runData;

const taskData = get(runData, `[${node.name}][${runIndex}]`);
const taskData = get(runData, [node.name, runIndex]);
if (!taskData) {
return [];
}
Expand Down