Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { shallowRef } from 'vue';
import { setActivePinia } from 'pinia';
import { createTestingPinia } from '@pinia/testing';
import { usePostMessageHandler } from './usePostMessageHandler';
import { useWorkflowsStore } from '@/app/stores/workflows.store';
import type { WorkflowState } from '@/app/composables/useWorkflowState';
import type { IExecutionResponse } from '@/features/execution/executions/executions.types';

Expand Down Expand Up @@ -220,6 +221,44 @@ describe('usePostMessageHandler', () => {
cleanup();
});

it('should set currentWorkflowDocumentStore after opening execution', async () => {
const workflowsStore = useWorkflowsStore();

mockOpenExecution.mockImplementation(async () => {
// Simulate what openExecution does: sets workflowId on the store
workflowsStore.workflow.id = 'test-wf-id';
return {
workflowData: { id: 'test-wf-id', name: 'Test' },
mode: 'trigger',
finished: true,
};
});

const storeRef = shallowRef(null);
const { setup, cleanup } = usePostMessageHandler({
workflowState,
currentWorkflowDocumentStore: storeRef,
});
setup();

const messageEvent = new MessageEvent('message', {
data: JSON.stringify({
command: 'openExecution',
executionId: 'exec-1',
executionMode: 'trigger',
}),
});
window.dispatchEvent(messageEvent);

await vi.waitFor(() => {
expect(mockOpenExecution).toHaveBeenCalled();
});

expect(storeRef.value).not.toBeNull();

cleanup();
});

it('should not set isProductionExecutionPreview for manual executions', async () => {
mockOpenExecution.mockResolvedValue({
workflowData: { id: 'w1', name: 'Test' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ import type { ExecutionPreviewNodeSchema } from '@/features/execution/executions
import type { IWorkflowDb } from '@/Interface';
import type { WorkflowDataUpdate } from '@n8n/rest-api-client/api/workflows';
import type { WorkflowState } from '@/app/composables/useWorkflowState';
import type { useWorkflowDocumentStore } from '@/app/stores/workflowDocument.store';
import {
type useWorkflowDocumentStore,
useWorkflowDocumentStore as createWorkflowDocumentStore,
createWorkflowDocumentId,
} from '@/app/stores/workflowDocument.store';
import { useWorkflowImport } from '@/app/composables/useWorkflowImport';
import { useWorkflowsStore } from '@/app/stores/workflows.store';

interface PostMessageHandlerDeps {
workflowState: WorkflowState;
Expand All @@ -38,6 +43,7 @@ export function usePostMessageHandler({
const telemetry = useTelemetry();
const nodeHelpers = useNodeHelpers();

const workflowsStore = useWorkflowsStore();
const { resetWorkspace, openExecution, fitView } = useCanvasOperations();
const { importWorkflowExact } = useWorkflowImport(currentWorkflowDocumentStore);

Expand Down Expand Up @@ -92,6 +98,13 @@ export function usePostMessageHandler({
return;
}

const wfId = workflowsStore.workflowId;
if (wfId) {
Comment thread
r00gm marked this conversation as resolved.
Resolved
currentWorkflowDocumentStore.value = createWorkflowDocumentStore(
createWorkflowDocumentId(wfId),
);
}

void nextTick(() => {
nodeHelpers.updateNodesInputIssues();
nodeHelpers.updateNodesCredentialsIssues();
Expand Down
Loading