feat(editor): Workflow history [WIP] - Remove pinned data from workflow history version preview (no-changelog) (#7406)

This commit is contained in:
Csaba Tuncsik
2023-10-19 14:38:00 +02:00
committed by GitHub
parent 82129694c6
commit c7c8048430
6 changed files with 447 additions and 195 deletions

View File

@@ -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,
};

View File

@@ -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<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: {
@@ -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'), '*');
});
});
});