From a14366a575fb2e66b23c36af188f36016e9b5918 Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Thu, 4 Jan 2024 13:57:29 +0200 Subject: [PATCH 1/2] fix: Add template id to workflows created from templates --- .../e2e/34-template-credentials-setup.cy.ts | 18 +++++++++++++++++- .../src/utils/templates/templateActions.ts | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/34-template-credentials-setup.cy.ts b/cypress/e2e/34-template-credentials-setup.cy.ts index a65e3a55b2c9b..2dcd0e07824dd 100644 --- a/cypress/e2e/34-template-credentials-setup.cy.ts +++ b/cypress/e2e/34-template-credentials-setup.cy.ts @@ -86,7 +86,7 @@ describe('Template credentials setup', () => { workflowPage.getters.canvasNodes().should('have.length', 3); }); - it('can create credentials and workflow from the template', () => { + it.only('can create credentials and workflow from the template', () => { templateCredentialsSetupPage.visitTemplateCredentialSetupPage(testTemplate.id); // Continue button should be disabled if no credentials are created @@ -106,6 +106,22 @@ describe('Template credentials setup', () => { cy.wait('@createWorkflow'); workflowPage.getters.canvasNodes().should('have.length', 3); + + // Focus the canvas so the copy to clipboard works + workflowPage.getters.canvasNodes().eq(0).realClick(); + workflowPage.actions.selectAll(); + workflowPage.actions.hitCopy(); + + cy.grantBrowserPermissions('clipboardReadWrite', 'clipboardSanitizedWrite'); + // Check workflow JSON by copying it to clipboard + cy.readClipboard().then((workflowJSON) => { + const workflow = JSON.parse(workflowJSON); + + expect(workflow.meta).to.haveOwnProperty('templateId', testTemplate.id.toString()); + workflow.nodes.forEach((node: any) => { + expect(Object.keys(node.credentials ?? {})).to.have.lengthOf(1); + }); + }); }); it('should work with a template that has no credentials (ADO-1603)', () => { diff --git a/packages/editor-ui/src/utils/templates/templateActions.ts b/packages/editor-ui/src/utils/templates/templateActions.ts index ec81a94744fc4..1d380b6015084 100644 --- a/packages/editor-ui/src/utils/templates/templateActions.ts +++ b/packages/editor-ui/src/utils/templates/templateActions.ts @@ -37,7 +37,10 @@ export async function createWorkflowFromTemplate(opts: { nodes, connections, active: false, - // Ignored: pinData, settings, tags, versionId, meta + meta: { + templateId: template.id.toString(), + }, + // Ignored: pinData, settings, tags, versionId }; const createdWorkflow = await workflowsStore.createNewWorkflow(workflowToCreate); From b9862639399148b289f706b511ccf0b703f2f42d Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Thu, 4 Jan 2024 16:25:34 +0200 Subject: [PATCH 2/2] remove .only from test --- cypress/e2e/34-template-credentials-setup.cy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/e2e/34-template-credentials-setup.cy.ts b/cypress/e2e/34-template-credentials-setup.cy.ts index 2dcd0e07824dd..a55f45d24e58d 100644 --- a/cypress/e2e/34-template-credentials-setup.cy.ts +++ b/cypress/e2e/34-template-credentials-setup.cy.ts @@ -86,7 +86,7 @@ describe('Template credentials setup', () => { workflowPage.getters.canvasNodes().should('have.length', 3); }); - it.only('can create credentials and workflow from the template', () => { + it('can create credentials and workflow from the template', () => { templateCredentialsSetupPage.visitTemplateCredentialSetupPage(testTemplate.id); // Continue button should be disabled if no credentials are created