diff --git a/cypress/e2e/48-subworkflow-inputs.cy.ts b/cypress/e2e/48-subworkflow-inputs.cy.ts index 02eff605f8494..1fddeff1be708 100644 --- a/cypress/e2e/48-subworkflow-inputs.cy.ts +++ b/cypress/e2e/48-subworkflow-inputs.cy.ts @@ -21,6 +21,16 @@ const DEFAULT_SUBWORKFLOW_NAME_2 = 'My Sub-Workflow 2'; type FieldRow = readonly string[]; +const exampleFields = [ + ['aNumber', 'Number'], + ['aString', 'String'], + ['aArray', 'Array'], + ['aObject', 'Object'], + ['aAny', 'Allow Any Type'], + // bool last since it's not an inputField so we'll skip it for some cases + ['aBool', 'Boolean'], +] as const; + /** * Populate multiValue fixedCollections. Only supports fixedCollections for which all fields can be defined via keyboard typing * @@ -83,6 +93,21 @@ function navigateWorkflowSelectionDropdown(index: number, expectedText: string) .click(); } +function populateMapperFields(values: readonly string[], offset: number) { + for (const [i, value] of values.entries()) { + cy.getByTestId('parameter-input') + .eq(offset + i) + .type(value); + + // Click on a parent to dismiss the pop up hiding the field below. + cy.getByTestId('parameter-input') + .eq(offset + i) + .parent() + .parent() + .click('topLeft'); + } +} + // This function starts off in the Child Workflow Input Trigger, assuming we just defined the input fields // It then navigates back to the parent and validates output function validateAndReturnToParent(targetChild: string, offset: number, fields: string[]) { @@ -127,7 +152,7 @@ function setWorkflowInputFieldValue(index: number, value: string) { ndv.actions.typeIntoFixedCollectionItem('workflowInputs', index, value); } -describe('Sub-workflow creation', () => { +describe('Sub-workflow creation and typed usage', () => { beforeEach(() => { navigateToNewWorkflowPage(); pasteWorkflow(SUB_WORKFLOW_INPUTS); @@ -150,23 +175,33 @@ describe('Sub-workflow creation', () => { openNode('Execute Workflow Trigger'); }); + it.only('works with type-checked values', () => { + populateFields(exampleFields); + + validateAndReturnToParent( + DEFAULT_SUBWORKFLOW_NAME_1, + 1, + exampleFields.map((f) => f[0]), + ); + + const values = [ + '-1', // number fields don't support `=` switch to expression, so let's test the Fixed case with it + ...exampleFields.slice(1).map((x) => `={{}{{} $json.a${x[0]}`), // }} are added automatically + ]; + + // this matches with the pinned data provided in the fixture + populateMapperFields(values, 2); + }); + it('works with Fields input source into JSON input source', () => { ndv.getters.nodeOutputHint().should('exist'); - const fields = [ - ['aString', 'String'], - ['aNumber', 'Number'], - ['aBool', 'Boolean'], - ['aArray', 'Array'], - ['aObject', 'Object'], - ['aAny', 'Allow Any Type'], - ] as const; - populateFields(fields); + populateFields(exampleFields); validateAndReturnToParent( DEFAULT_SUBWORKFLOW_NAME_1, 1, - fields.map((f) => f[0]), + exampleFields.map((f) => f[0]), ); cy.window().then((win) => { @@ -188,7 +223,7 @@ describe('Sub-workflow creation', () => { .type('Using JSON Example{downArrow}{enter}'); const exampleJson = - '{{}' + fields.map((x) => `"${x[0]}": ${makeExample(x[1])}`).join(',') + '}'; + '{{}' + exampleFields.map((x) => `"${x[0]}": ${makeExample(x[1])}`).join(',') + '}'; cy.getByTestId('parameter-input-jsonExample') .find('.cm-line') .eq(0) @@ -196,12 +231,11 @@ describe('Sub-workflow creation', () => { // first one doesn't work for some reason, might need to wait for something? ndv.actions.execute(); - ndv.actions.execute(); validateAndReturnToParent( DEFAULT_SUBWORKFLOW_NAME_2, 2, - fields.map((f) => f[0]), + exampleFields.map((f) => f[0]), ); // populateJson(fields); diff --git a/cypress/fixtures/Test_Subworkflow-Inputs.json b/cypress/fixtures/Test_Subworkflow-Inputs.json index 5b96c0e3f2c8e..aeb4d601fdeba 100644 --- a/cypress/fixtures/Test_Subworkflow-Inputs.json +++ b/cypress/fixtures/Test_Subworkflow-Inputs.json @@ -5,21 +5,11 @@ "nodes": [ { "parameters": {}, - "id": "313c177e-724b-4063-8ae0-0968074fe815", + "id": "bb7f8bb3-840a-464c-a7de-d3a80538c2be", "name": "When clicking ‘Test workflow’", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, - "position": [60, 240] - }, - { - "parameters": { - "category": "randomData" - }, - "id": "7e5d5a99-4c88-4746-b097-6ee20b7b2102", - "name": "DebugHelper", - "type": "n8n-nodes-base.debugHelper", - "typeVersion": 1, - "position": [280, 240] + "position": [0, 0] }, { "parameters": { @@ -44,17 +34,6 @@ ], "connections": { "When clicking ‘Test workflow’": { - "main": [ - [ - { - "node": "DebugHelper", - "type": "main", - "index": 0 - } - ] - ] - }, - "DebugHelper": { "main": [ [ { @@ -66,5 +45,26 @@ ] } }, - "pinData": {} + "pinData": { + "When clicking ‘Test workflow’": [ + { + "aaString": "A String", + "aaNumber": 1, + "aaArray": [1, true, "3"], + "aaObject": { + "aKey": -1 + }, + "aaAny": {} + }, + { + "aaString": "Another String", + "aaNumber": 2, + "aaArray": [], + "aaObject": { + "aDifferentKey": -1 + }, + "aaAny": [] + } + ] + } }