Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show Pinned data in demo mode #11490

Merged
merged 5 commits into from
Nov 1, 2024
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
8 changes: 8 additions & 0 deletions cypress/composables/ndv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export function getOutputPanelDataContainer() {
return getOutputPanel().getByTestId('ndv-data-container');
}

export function getOutputTableRows() {
return getOutputPanelDataContainer().find('table tr');
}

export function getOutputTableRow(row: number) {
return getOutputTableRows().eq(row);
}

export function getOutputPanelTable() {
return getOutputPanelDataContainer().get('table');
}
Expand Down
7 changes: 7 additions & 0 deletions cypress/composables/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export function getNodeCreatorPlusButton() {
return cy.getByTestId('node-creator-plus-button');
}

export function getCanvasNodes() {
return cy.ifCanvasVersion(
() => cy.getByTestId('canvas-node'),
() => cy.getByTestId('canvas-node').not('[data-node-type="n8n-nodes-internal.addNodes"]'),
);
}

/**
* Actions
*/
Expand Down
22 changes: 15 additions & 7 deletions cypress/e2e/31-demo.cy.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import workflow from '../fixtures/Manual_wait_set.json';
import { getOutputTableRow } from '../composables/ndv';
import { getCanvasNodes, openNode } from '../composables/workflow';
import SIMPLE_WORKFLOW from '../fixtures/Manual_wait_set.json';
import WORKFLOW_WITH_PINNED from '../fixtures/Webhook_set_pinned.json';
import { importWorkflow, visitDemoPage } from '../pages/demo';
import { errorToast } from '../pages/notifications';
import { WorkflowPage } from '../pages/workflow';

const workflowPage = new WorkflowPage();

describe('Demo', () => {
beforeEach(() => {
cy.overrideSettings({ previewMode: true });
cy.signout();
});

it('can import template', () => {
visitDemoPage();
errorToast().should('not.exist');
importWorkflow(workflow);
workflowPage.getters.canvasNodes().should('have.length', 3);
importWorkflow(SIMPLE_WORKFLOW);
getCanvasNodes().should('have.length', 3);
});

it('can import workflow with pin data', () => {
visitDemoPage();
importWorkflow(WORKFLOW_WITH_PINNED);
getCanvasNodes().should('have.length', 2);
openNode('Webhook');
getOutputTableRow(0).should('include.text', 'headers');
getOutputTableRow(1).should('include.text', 'dragons');
});

it('can override theme to dark', () => {
Expand Down
31 changes: 25 additions & 6 deletions packages/editor-ui/src/stores/workflows.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ import type {
} from '@/Interface';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';

import {
SEND_AND_WAIT_OPERATION,
type ExecutionSummary,
type IConnection,
type INodeExecutionData,
} from 'n8n-workflow';
import { SEND_AND_WAIT_OPERATION } from 'n8n-workflow';
import type { IPinData, ExecutionSummary, IConnection, INodeExecutionData } from 'n8n-workflow';
import { stringSizeInBytes } from '@/utils/typesUtils';
import { dataPinningEventBus } from '@/event-bus';
import { useUIStore } from '@/stores/ui.store';
Expand Down Expand Up @@ -599,6 +595,29 @@ describe('useWorkflowsStore', () => {
},
);
});

it('sets workflow pin data', () => {
workflowsStore.workflow.pinData = undefined;
const data: IPinData = {
TestNode: [{ json: { test: true } }],
TestNode1: [{ json: { test: false } }],
};
workflowsStore.setWorkflowPinData(data);
expect(workflowsStore.workflow.pinData).toEqual(data);
});

it('sets workflow pin data, adding json keys', () => {
workflowsStore.workflow.pinData = undefined;
const data = {
TestNode: [{ test: true }],
TestNode1: [{ test: false }],
};
workflowsStore.setWorkflowPinData(data as unknown as IPinData);
expect(workflowsStore.workflow.pinData).toEqual({
TestNode: [{ json: { test: true } }],
TestNode1: [{ json: { test: false } }],
});
});
});

describe('finishActiveExecution', () => {
Expand Down
21 changes: 15 additions & 6 deletions packages/editor-ui/src/stores/workflows.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,23 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
};
}

function setWorkflowPinData(pinData?: IPinData) {
workflow.value = {
...workflow.value,
pinData: pinData ?? {},
};
function setWorkflowPinData(data: IPinData = {}) {
const validPinData = Object.keys(data).reduce((accu, nodeName) => {
accu[nodeName] = data[nodeName].map((item) => {
if (!isJsonKeyObject(item)) {
return { json: item };
}

return item;
});

return accu;
}, {} as IPinData);

workflow.value.pinData = validPinData;
updateCachedWorkflow();

dataPinningEventBus.emit('pin-data', pinData ?? {});
dataPinningEventBus.emit('pin-data', validPinData);
}

function setWorkflowTagIds(tags: string[]) {
Expand Down
Loading