fix(editor): Fix TypeError: Cannot read properties of undefined (reading '0') (#11399)

This commit is contained in:
Raúl Gómez Morales 2024-10-28 10:15:22 +01:00 committed by GitHub
parent 8147038cf8
commit ae37c520a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 1 deletions

View file

@ -0,0 +1,40 @@
import { createTestingPinia } from '@pinia/testing';
import { setActivePinia } from 'pinia';
import { mockedStore } from '@/__tests__/utils';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { useExecutionDebugging } from './useExecutionDebugging';
import type { INodeUi, IExecutionResponse } from '@/Interface';
import type { Workflow } from 'n8n-workflow';
describe('useExecutionDebugging()', () => {
it('should applyExecutionData', async () => {
setActivePinia(createTestingPinia());
const mockExecution = {
data: {
resultData: {
runData: {
testNode: [
{
data: {},
},
],
},
},
},
} as unknown as IExecutionResponse;
const workflowStore = mockedStore(useWorkflowsStore);
workflowStore.getNodes.mockReturnValue([{ name: 'testNode' }] as INodeUi[]);
workflowStore.getExecution.mockResolvedValueOnce(mockExecution);
workflowStore.getCurrentWorkflow.mockReturnValue({
pinData: {},
getParentNodes: vi.fn().mockReturnValue([]),
} as unknown as Workflow);
const { applyExecutionData } = useExecutionDebugging();
await applyExecutionData('1');
expect(workflowStore.setWorkflowExecutionData).toHaveBeenCalledWith(mockExecution);
});
});

View file

@ -105,7 +105,7 @@ export const useExecutionDebugging = () => {
let pinnings = 0;
pinnableNodes.forEach((node: INodeUi) => {
const nodeData = runData[node.name]?.[0].data?.main[0];
const nodeData = runData[node.name]?.[0].data?.main?.[0];
if (nodeData) {
pinnings++;
workflowsStore.pinData({