From c7c804843029937cc42f0ef658158ee904c85d7c Mon Sep 17 00:00:00 2001 From: Csaba Tuncsik Date: Thu, 19 Oct 2023 14:38:00 +0200 Subject: [PATCH] feat(editor): Workflow history [WIP] - Remove pinned data from workflow history version preview (no-changelog) (#7406) --- .../WorkflowHistoryContent.vue | 3 +- .../__tests__/WorkflowHistoryContent.test.ts | 37 +- .../src/components/WorkflowPreview.vue | 354 +++++++++--------- .../__tests__/WorkflowPreview.test.ts | 230 ++++++++++++ .../src/stores/workflowHistory.store.ts | 16 +- .../editor-ui/src/views/WorkflowHistory.vue | 2 +- 6 files changed, 447 insertions(+), 195 deletions(-) create mode 100644 packages/editor-ui/src/components/__tests__/WorkflowPreview.test.ts diff --git a/packages/editor-ui/src/components/WorkflowHistory/WorkflowHistoryContent.vue b/packages/editor-ui/src/components/WorkflowHistory/WorkflowHistoryContent.vue index fb70484a92..f934ef801b 100644 --- a/packages/editor-ui/src/components/WorkflowHistory/WorkflowHistoryContent.vue +++ b/packages/editor-ui/src/components/WorkflowHistory/WorkflowHistoryContent.vue @@ -34,8 +34,9 @@ const workflowVersionPreview = computed(() => { if (!props.workflowVersion || !props.workflow) { return; } + const { pinData, ...workflow } = props.workflow; return { - ...props.workflow, + ...workflow, nodes: props.workflowVersion.nodes, connections: props.workflowVersion.connections, }; diff --git a/packages/editor-ui/src/components/WorkflowHistory/__tests__/WorkflowHistoryContent.test.ts b/packages/editor-ui/src/components/WorkflowHistory/__tests__/WorkflowHistoryContent.test.ts index cc3864c82f..8f57126e17 100644 --- a/packages/editor-ui/src/components/WorkflowHistory/__tests__/WorkflowHistoryContent.test.ts +++ b/packages/editor-ui/src/components/WorkflowHistory/__tests__/WorkflowHistoryContent.test.ts @@ -1,10 +1,13 @@ +import { vi } from 'vitest'; import { createPinia, setActivePinia } from 'pinia'; +import { waitFor } from '@testing-library/vue'; import userEvent from '@testing-library/user-event'; import type { UserAction } from 'n8n-design-system'; import { createComponentRenderer } from '@/__tests__/render'; import WorkflowHistoryContent from '@/components/WorkflowHistory/WorkflowHistoryContent.vue'; import type { WorkflowHistoryActionTypes } from '@/types/workflowHistory'; -import { workflowHistoryDataFactory } from '@/stores/__tests__/utils/workflowHistoryTestUtils'; +import { workflowVersionDataFactory } from '@/stores/__tests__/utils/workflowHistoryTestUtils'; +import type { IWorkflowDb } from '@/Interface'; const actionTypes: WorkflowHistoryActionTypes = ['restore', 'clone', 'open', 'download']; const actions: UserAction[] = actionTypes.map((value) => ({ @@ -16,15 +19,24 @@ const actions: UserAction[] = actionTypes.map((value) => ({ const renderComponent = createComponentRenderer(WorkflowHistoryContent); let pinia: ReturnType; +let postMessageSpy: vi.SpyInstance; describe('WorkflowHistoryContent', () => { beforeEach(() => { pinia = createPinia(); setActivePinia(pinia); + + postMessageSpy = vi.fn(); + Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', { + writable: true, + value: { + postMessage: postMessageSpy, + }, + }); }); it('should use the list item component to render version data', () => { - const workflowVersion = workflowHistoryDataFactory(); + const workflowVersion = workflowVersionDataFactory(); const { getByTestId } = renderComponent({ pinia, props: { @@ -38,7 +50,7 @@ describe('WorkflowHistoryContent', () => { }); test.each(actionTypes)('should emit %s event', async (action) => { - const workflowVersion = workflowHistoryDataFactory(); + const workflowVersion = workflowVersionDataFactory(); const { getByTestId, emitted } = renderComponent({ pinia, props: { @@ -56,4 +68,23 @@ describe('WorkflowHistoryContent', () => { [{ action, id: workflowVersion.versionId, data: { formattedCreatedAt: expect.any(String) } }], ]); }); + + it('should pass proper workflow data to WorkflowPreview component', async () => { + const workflowVersion = workflowVersionDataFactory(); + const workflow = { pinData: {} } as IWorkflowDb; + renderComponent({ + pinia, + props: { + workflow, + workflowVersion, + actions, + }, + }); + + window.postMessage('{"command":"n8nReady"}', '*'); + + await waitFor(() => { + expect(postMessageSpy).toHaveBeenCalledWith(expect.not.stringContaining('pinData'), '*'); + }); + }); }); diff --git a/packages/editor-ui/src/components/WorkflowPreview.vue b/packages/editor-ui/src/components/WorkflowPreview.vue index d7ecd49ae2..1fd3948b6e 100644 --- a/packages/editor-ui/src/components/WorkflowPreview.vue +++ b/packages/editor-ui/src/components/WorkflowPreview.vue @@ -8,202 +8,194 @@ + /> -