Skip to content

Commit

Permalink
feat(editor): Workflow history [WIP] - Remove pinned data from workfl…
Browse files Browse the repository at this point in the history
…ow history version preview (no-changelog) (#7406)
  • Loading branch information
cstuncsik authored Oct 19, 2023
1 parent 8212969 commit c7c8048
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ const workflowVersionPreview = computed<IWorkflowDb | undefined>(() => {
if (!props.workflowVersion || !props.workflow) {
return;
}
const { pinData, ...workflow } = props.workflow;
return {
...props.workflow,
...workflow,
nodes: props.workflowVersion.nodes,
connections: props.workflowVersion.connections,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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) => ({
Expand All @@ -16,15 +19,24 @@ const actions: UserAction[] = actionTypes.map((value) => ({
const renderComponent = createComponentRenderer(WorkflowHistoryContent);

let pinia: ReturnType<typeof createPinia>;
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: {
Expand All @@ -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: {
Expand All @@ -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'), '*');
});
});
});
Loading

0 comments on commit c7c8048

Please sign in to comment.