n8n/cypress/e2e/14-mapping.cy.ts

322 lines
10 KiB
TypeScript
Raw Normal View History

import {
MANUAL_TRIGGER_NODE_NAME,
MANUAL_TRIGGER_NODE_DISPLAY_NAME,
SCHEDULE_TRIGGER_NODE_NAME,
} from './../constants';
import { WorkflowPage, NDV } from '../pages';
const workflowPage = new WorkflowPage();
const ndv = new NDV();
describe('Data mapping', () => {
before(() => {
cy.resetAll();
cy.skipSetup();
});
beforeEach(() => {
workflowPage.actions.visit();
cy.window()
// @ts-ignore
.then(
ci(editor): Run e2e tests in parallel and improve build caching (#5445) * WIP: Cypress parallel CI run test * Trigger action on branch push * Change build artifacts path * Make sure to checkout the repo for testing job * Use Cypress action for installing * Lock cypress action userd version * Skip node install step since we're using cypress node16 container * Let Cypress handle pnpm install * Use setup-node action for caching pnpm * Set CYPRESS_CACHE_FOLDER * Set CYPRESS_CACHE_FOLDER * Manually cache pnpm store * Dont fix pnpm version * Use caching action also in testing job * Zip packages dist before uploading the artifacts and change caching key * Use absolute build paths for zipping job * Use zip command in action * Use tar for zipping packages * Debuggin directory ls * Debugging caching of modules * Attempt to fix permissions issue * Porivde Cypress executable via `CYPRESS_RUN_BINARY` * Cache /github/home * Adjust caching keys * Debug: search for cypress exec * Debugging: List dirs * Use pnpm install action to install node_modules * Do not log /home/runner * Use node_modules/.bin Cypress binary * Use absolute path to nodue modules * Run Cypress via custom command * Try with patched cypress action * Revert logging * Manually specify cypress config file * Use absolute paths * Fix cypress config name * Debug print cypress config * Remove debugging, increase to 4 containers * Increase amount of containers * Add env-version matrix * Replace node14 with node18 in testing matrix * Remove debugging and add node 14 * Use just node14 * Use cypress:base and remove browser req * Give more general timeouts * Try with node16 * Change cache directive position * Replace zip artifact upload with cache * Cache full packages not just dist * Test with variable inputs * Add commit info message * Remove wrongly commited code * Allow WF API dispatch * Try Chrome browser again for comparison * Include Monaco in the build * Make e2e workflow re-usable * Comment out invalid reusable workflow args * Use electron and add node 14 run * Fix env arg * Provide custom ci-build-id * Refactor remaining e2e workflow to use reusable action * Remove single matrix directive * Refactor ci-pull-req * Make lint job dependant on test jobs * Disable debugging job * Make containers dynamic * Cleanup & install git for linting action * Use regular buntu image for PR linting * Debugging failing tests * Remove fixed spec name * Debug e2e env var * Do not use realkeypress which crashes electron runner * Debugging * chore: remove console * chore: remove console * test: remove node 14 tests * test: replace test branch with master * test: use tests in current branch * test: use relative path * chore: clean up * test: only trigger on approval * ci: update test PR * ci: use curr branch * ci: only run 14 on schedule, not for slack command * ci: only run test on approval * ci: clean up branch, rename step * ci: rename steps * ci: clean up cancel * ci: clean up env var * ci: set var * ci: use chromef * ci: use electron * chore: add console log * chore: add console log * ci: update to string * ci: set all env options * test: build * ci: fix step issue * Fix failing tests & upgrade to Cypress 12 * Allow WF dispatch of e2e reusable * Fix wrong naming in e2e-tests workflow * Redeploy * Fix tests * Fix NDV tests and remove skipping of webhooks execution tests * Fix clipboard read command * Fix execution failing tests * Reset before each 15 and 3 * Fix flaky tests * Cleanup and log envs * Test fixes * Default owner spec fixes * Get rid of CYPRESS_RUN_ENV * Increase amount of containers, cleanup and add mock for credentials test call * Cleanup & fix PR tests unit tests * Wait for WF to loade in sharing spec * Do linting and unit tests first * Use frozen lockfile * Revert back ci pull request jobs order * Refine credential input selector and move cy.waitForLoad to correct position in 15-scheduler spec * test: build * Wait for WF execution instead of arbitraty timeout in WF execution spec, change order of jobs for ci pull request * Fix flaky 3-default owner spec and wait for execution list to load in 20-workflow-executions * Use setup node action * Remove caching for lint/unit tests * Experiment with parallel test & lint on ci * Provide cache key dynamically * Run e2e in parallel on pr * Only run node14 e2e on daily schedule * Make sure to generate generate new ci-build-id on re-runs * Remove debugging prints * Address PR comments * Rename custom onBeforeUnload handler * Make sure 19-execution spec waits for wf to load properly before import fixtures --------- Co-authored-by: Mutasem <mutdmour@gmail.com>
2023-03-02 07:50:21 -08:00
(win) => win.onBeforeUnloadNodeView && win.removeEventListener('beforeunload', win.onBeforeUnloadNodeView),
);
});
it('maps expressions from table header', () => {
cy.fixture('Test_workflow-actions_paste-data.json').then((data) => {
cy.get('body').paste(JSON.stringify(data));
});
workflowPage.actions.openNode('Set');
ndv.actions.executePrevious();
ndv.actions.switchInputMode('Table');
ndv.getters.inputDataContainer().get('table', { timeout: 10000 }).should('exist');
ndv.getters.nodeParameters().find('input[placeholder*="Add Value"]').click();
ndv.getters
.nodeParameters()
.find('.el-select-dropdown__list li:nth-child(3)')
.should('have.text', 'String')
.click();
ndv.getters
.parameterInput('name')
.should('have.length', 1)
.find('input')
.should('have.value', 'propertyName');
ndv.getters
.parameterInput('value')
.should('have.length', 1)
.find('input')
.should('have.value', '');
ndv.actions.mapDataFromHeader(1, 'value');
ndv.getters.inlineExpressionEditorInput().should('have.text', '{{ $json.timestamp }}');
ndv.actions.mapDataFromHeader(2, 'value');
ndv.getters
.inlineExpressionEditorInput()
.should('have.text', "{{ $json.timestamp }} {{ $json['Readable date'] }}");
});
it('maps expressions from table json, and resolves value based on hover', () => {
cy.fixture('Test_workflow_3.json').then((data) => {
cy.get('body').paste(JSON.stringify(data));
});
workflowPage.actions.openNode('Set');
ndv.actions.switchInputMode('Table');
ndv.getters.inputDataContainer().get('table', { timeout: 10000 }).should('exist');
ndv.getters
.parameterInput('name')
.should('have.length', 1)
.find('input')
.should('have.value', 'other');
ndv.getters
.parameterInput('value')
.should('have.length', 1)
.find('input')
.should('have.value', '');
ndv.getters
.inputTbodyCell(1, 0)
.find('span')
.contains('count')
.trigger('mousedown', { force: true });
ndv.actions.mapToParameter('value');
ndv.getters.inlineExpressionEditorInput().should('have.text', '{{ $json.input[0].count }}');
ndv.getters.parameterExpressionPreview('value').should('include.text', '0');
ndv.getters.inputTbodyCell(1, 0).realHover();
ndv.getters
.parameterExpressionPreview('value')
.should('include.text', '0')
.invoke('css', 'color')
.should('equal', 'rgb(125, 125, 135)');
ndv.getters.inputTbodyCell(2, 0).realHover();
ndv.getters
.parameterExpressionPreview('value')
.should('include.text', '1')
.invoke('css', 'color')
.should('equal', 'rgb(125, 125, 135)');
ndv.actions.execute();
ndv.getters.outputTbodyCell(1, 0).realHover();
ndv.getters
.parameterExpressionPreview('value')
.should('include.text', '0')
.invoke('css', 'color')
.should('equal', 'rgb(125, 125, 135)'); // todo update color
ndv.getters.outputTbodyCell(2, 0).realHover();
ndv.getters
.parameterExpressionPreview('value')
.should('include.text', '1')
.invoke('css', 'color')
.should('equal', 'rgb(125, 125, 135)');
});
it('maps expressions from json view', () => {
cy.fixture('Test_workflow_3.json').then((data) => {
cy.get('body').paste(JSON.stringify(data));
});
workflowPage.actions.openNode('Set');
ndv.actions.switchInputMode('JSON');
ndv.getters
.inputDataContainer()
.should('exist')
.find('.json-data')
.should(
'have.text',
'[{"input":[{"count":0,"with space":"!!","with.dot":"!!","with"quotes":"!!"}]},{"input":[{"count":1}]}]',
)
.find('span')
.contains('"count"')
.realMouseDown();
ndv.actions.mapToParameter('value');
ndv.getters.inlineExpressionEditorInput().should('have.text', '{{ $json.input[0].count }}');
ndv.getters.parameterExpressionPreview('value').should('include.text', '0');
ndv.getters
.inputDataContainer()
.find('.json-data')
.find('span')
.contains('"input"')
.realMouseDown();
ndv.actions.mapToParameter('value');
ndv.getters
.inlineExpressionEditorInput()
.should('have.text', '{{ $json.input[0].count }} {{ $json.input }}');
ndv.getters.parameterExpressionPreview('value').should('include.text', '0 [object Object]');
});
it('maps expressions from schema view', () => {
cy.fixture('Test_workflow_3.json').then((data) => {
cy.get('body').paste(JSON.stringify(data));
});
workflowPage.actions.openNode('Set');
ndv.actions.clearParameterInput('value');
cy.get('body').type('{esc}');
ndv.getters.inputDataContainer().should('exist').find('span').contains('count').realMouseDown();
ndv.actions.mapToParameter('value');
ndv.getters.inlineExpressionEditorInput().should('have.text', '{{ $json.input[0].count }}');
ndv.getters.parameterExpressionPreview('value').should('include.text', '0');
ndv.getters.inputDataContainer().find('span').contains('input').realMouseDown();
ndv.actions.mapToParameter('value');
ndv.getters
.inlineExpressionEditorInput()
.should('have.text', '{{ $json.input[0].count }} {{ $json.input }}');
ndv.getters.parameterExpressionPreview('value').should('include.text', '0 [object Object]');
});
it('maps expressions from previous nodes', () => {
cy.createFixtureWorkflow('Test_workflow_3.json', `My test workflow`);
workflowPage.actions.openNode('Set1');
ndv.actions.selectInputNode(SCHEDULE_TRIGGER_NODE_NAME);
ndv.getters.inputDataContainer().find('span').contains('count').realMouseDown();
ndv.actions.mapToParameter('value');
ndv.getters
.inlineExpressionEditorInput()
.should('have.text', `{{ $node['${SCHEDULE_TRIGGER_NODE_NAME}'].json.input[0].count }}`);
ndv.getters.parameterExpressionPreview('value').should('not.exist');
ndv.actions.switchInputMode('Table');
ndv.actions.mapDataFromHeader(1, 'value');
ndv.getters
.inlineExpressionEditorInput()
.should(
'have.text',
`{{ $node['${SCHEDULE_TRIGGER_NODE_NAME}'].json.input[0].count }} {{ $node['${SCHEDULE_TRIGGER_NODE_NAME}'].json.input }}`,
);
ndv.getters.parameterExpressionPreview('value').should('not.exist');
ndv.actions.selectInputNode('Set');
ndv.actions.executePrevious();
ndv.getters.executingLoader().should('not.exist');
ndv.getters.inputDataContainer().should('exist');
ndv.getters.parameterExpressionPreview('value').should('include.text', '0 [object Object]');
ndv.getters.inputTbodyCell(2, 0).realHover();
ndv.getters.parameterExpressionPreview('value').should('include.text', '1 [object Object]');
});
it('maps keys to path', () => {
workflowPage.actions.addInitialNodeToCanvas(MANUAL_TRIGGER_NODE_NAME);
workflowPage.getters.canvasNodeByName(MANUAL_TRIGGER_NODE_DISPLAY_NAME).click();
workflowPage.actions.openNode(MANUAL_TRIGGER_NODE_DISPLAY_NAME);
ndv.actions.setPinnedData([
{
input: [
{
'hello.world': {
'my count': 0,
},
},
],
},
{
input: [
{
'hello.world': {
'my count': 1,
},
},
],
},
]);
ndv.actions.close();
workflowPage.actions.addNodeToCanvas('Item Lists');
workflowPage.actions.openNode('Item Lists');
ndv.getters.parameterInput('operation').click().find('li').contains('Sort').click();
ndv.getters.nodeParameters().find('button').contains('Add Field To Sort By').click();
ndv.getters.inputDataContainer().find('span').contains('my count').realMouseDown();
ndv.actions.mapToParameter('fieldName');
ndv.getters.inlineExpressionEditorInput().should('have.length', 0);
ndv.getters
.parameterInput('fieldName')
.find('input')
.should('have.value', "input[0]['hello.world']['my count']");
});
it('maps expressions to updated fields correctly', () => {
cy.fixture('Test_workflow_3.json').then((data) => {
cy.get('body').paste(JSON.stringify(data));
});
workflowPage.actions.openNode('Set');
ndv.actions.typeIntoParameterInput('value', 'delete me');
ndv.actions.dismissMappingTooltip();
ndv.actions.typeIntoParameterInput('name', 'test');
ndv.actions.typeIntoParameterInput('value', 'fun');
ndv.actions.clearParameterInput('value'); // keep focus on param
ndv.getters.inputDataContainer().should('exist').find('span').contains('count').realMouseDown();
ndv.actions.mapToParameter('value');
ndv.getters.inlineExpressionEditorInput().should('have.text', '{{ $json.input[0].count }}');
ndv.getters.parameterExpressionPreview('value').should('include.text', '0');
ndv.getters.inputDataContainer().find('span').contains('input').realMouseDown();
ndv.actions.mapToParameter('value');
ndv.getters
.inlineExpressionEditorInput()
.should('have.text', '{{ $json.input[0].count }} {{ $json.input }}');
ndv.getters.parameterExpressionPreview('value').should('include.text', '0 [object Object]');
});
it('shows you can drop to inputs, including booleans', () => {
cy.fixture('Test_workflow_3.json').then((data) => {
cy.get('body').paste(JSON.stringify(data));
});
workflowPage.actions.openNode('Set');
ndv.actions.clearParameterInput('value');
cy.get('body').type('{esc}');
ndv.getters.parameterInput('keepOnlySet').find('input[type="checkbox"]').should('exist');
ndv.getters.parameterInput('keepOnlySet').find('input[type="text"]').should('not.exist');
ndv.getters.inputDataContainer().should('exist').find('span').contains('count').realMouseDown().realMouseMove(100, 100);
cy.wait(50);
ndv.getters.parameterInput('keepOnlySet').find('input[type="checkbox"]').should('not.exist');
ndv.getters.parameterInput('keepOnlySet').find('input[type="text"]')
.should('exist')
.invoke('css', 'border')
.then((border) => expect(border).to.include('1.5px dashed rgb(90, 76, 194)'));
ndv.getters.parameterInput('value').find('input[type="text"]')
.should('exist')
.invoke('css', 'border')
.then((border) => expect(border).to.include('1.5px dashed rgb(90, 76, 194)'));
});
});