fix(editor): Fix nodes and connection debouncing during execution (no-changelog) (#14208)

This commit is contained in:
Alex Grozav
2025-03-27 11:59:04 +02:00
committed by GitHub
parent 5f4e56f75b
commit a4a34a2745
4 changed files with 60 additions and 93 deletions

View File

@@ -14,16 +14,13 @@ import {
defaultNodeDescriptions,
} from '@/__tests__/mocks';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import * as lodash from 'lodash-es';
import * as vueuse from '@vueuse/core';
vi.mock('lodash-es', async () => {
const actual = await vi.importActual('lodash-es');
vi.mock('@vueuse/core', async () => {
const actual = await vi.importActual('@vueuse/core');
return {
...actual,
debounce: vi.fn((fn) => {
// Return a function that immediately calls the provided function
return (...args: unknown[]) => fn(...args);
}),
debouncedRef: vi.fn(actual.debouncedRef as typeof vueuse.debouncedRef),
};
});
@@ -157,34 +154,6 @@ describe('WorkflowCanvas', () => {
});
describe('debouncing behavior', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('should initialize debounced watchers on component mount', async () => {
renderComponent();
expect(lodash.debounce).toHaveBeenCalledTimes(3);
});
it('should configure debouncing with no delay when not executing', async () => {
renderComponent({
props: {
executing: false,
},
});
expect(lodash.debounce).toHaveBeenCalledTimes(3);
// Find calls related to our specific debouncing logic
const calls = vi.mocked(lodash.debounce).mock.calls;
const nonExecutingCalls = calls.filter((call) => call[1] === 0 && call[2]?.maxWait === 0);
expect(nonExecutingCalls.length).toBeGreaterThanOrEqual(2);
expect(nonExecutingCalls[0][1]).toBe(0);
expect(nonExecutingCalls[0][2]).toEqual({ maxWait: 0 });
});
it('should configure debouncing with delay when executing', async () => {
renderComponent({
props: {
@@ -192,10 +161,10 @@ describe('WorkflowCanvas', () => {
},
});
expect(lodash.debounce).toHaveBeenCalledTimes(3);
expect(vueuse.debouncedRef).toHaveBeenCalledTimes(2);
// Find calls related to our specific debouncing logic
const calls = vi.mocked(lodash.debounce).mock.calls;
const calls = vi.mocked(vueuse.debouncedRef).mock.calls;
const executingCalls = calls.filter((call) => call[1] === 200 && call[2]?.maxWait === 50);
expect(executingCalls.length).toBeGreaterThanOrEqual(2);