Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieKolb committed Dec 19, 2024
1 parent c70aae9 commit 3ac75f6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 38 deletions.
62 changes: 48 additions & 14 deletions cypress/e2e/48-subworkflow-inputs.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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[]) {
Expand Down Expand Up @@ -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);
Expand All @@ -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) => {
Expand All @@ -188,20 +223,19 @@ 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)
.type(`{selectAll}{backspace}${exampleJson}{enter}`);

// 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);
Expand Down
48 changes: 24 additions & 24 deletions cypress/fixtures/Test_Subworkflow-Inputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -44,17 +34,6 @@
],
"connections": {
"When clicking ‘Test workflow’": {
"main": [
[
{
"node": "DebugHelper",
"type": "main",
"index": 0
}
]
]
},
"DebugHelper": {
"main": [
[
{
Expand All @@ -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": []
}
]
}
}

0 comments on commit 3ac75f6

Please sign in to comment.