fix: Show Pinned data in demo mode (#11490)

This commit is contained in:
Mutasem Aldmour 2024-11-01 14:04:58 +01:00 committed by GitHub
parent 5b5bd7291d
commit ca2a583b5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 70 additions and 19 deletions

View file

@ -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');
}

View file

@ -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
*/

View file

@ -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', () => {

View file

@ -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';
@ -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', () => {

View file

@ -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[]) {