fix(editor): Sort start start nodes for manual execution by Y position (#15254)

This commit is contained in:
oleg
2025-05-12 09:56:42 +02:00
committed by GitHub
parent 3be05556f9
commit ab27f91944
2 changed files with 49 additions and 1 deletions

View File

@@ -822,4 +822,37 @@ describe('useRunWorkflow({ router })', () => {
await waitFor(() => expect(markStoppedSpy).toHaveBeenCalled());
});
});
describe('sortNodesByYPosition()', () => {
const getNodeUi = (name: string, position: [number, number]) => {
return {
name,
position,
type: 'n8n-nodes-base.test',
typeVersion: 1,
id: name,
parameters: {},
};
};
it('should sort nodes by Y position in ascending order', () => {
const { sortNodesByYPosition } = useRunWorkflow({ router });
const topNode = 'topNode';
const middleNode = 'middleNode';
const bottomNode = 'bottomNode';
vi.mocked(workflowsStore.getNodeByName).mockImplementation((name) => {
if (name === topNode) return getNodeUi(topNode, [100, 50]);
if (name === middleNode) return getNodeUi(middleNode, [200, 200]);
if (name === bottomNode) return getNodeUi(bottomNode, [150, 350]);
return null;
});
// Test with different order of input nodes
const result = sortNodesByYPosition([bottomNode, topNode, middleNode]);
// Should be sorted by Y position (top to bottom)
expect(result).toEqual([topNode, middleNode, bottomNode]);
});
});
});