2023-02-08 01:41:36 -08:00
|
|
|
import { WorkflowPage, NDV } from '../pages';
|
|
|
|
|
|
|
|
const wf = new WorkflowPage();
|
|
|
|
const ndv = new NDV();
|
|
|
|
|
|
|
|
describe('Data transformation expressions', () => {
|
2023-02-24 09:07:35 -08:00
|
|
|
beforeEach(() => {
|
2023-02-09 06:59:01 -08:00
|
|
|
wf.actions.visit();
|
2023-02-08 01:41:36 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('$json + native string methods', () => {
|
|
|
|
wf.actions.addInitialNodeToCanvas('Schedule Trigger', { keepNdvOpen: true });
|
|
|
|
ndv.actions.setPinnedData([{ myStr: 'Monday' }]);
|
|
|
|
ndv.actions.close();
|
|
|
|
addSet();
|
|
|
|
|
|
|
|
const input = '{{$json.myStr.toLowerCase() + " is " + "today".toUpperCase()';
|
|
|
|
const output = 'monday is TODAY';
|
|
|
|
|
|
|
|
ndv.getters.inlineExpressionEditorInput().clear().type(input);
|
|
|
|
ndv.actions.execute();
|
2023-02-24 09:07:35 -08:00
|
|
|
ndv.getters.outputDataContainer().should('be.visible');
|
2023-02-17 06:08:26 -08:00
|
|
|
ndv.getters.outputDataContainer().contains(output);
|
2023-02-08 01:41:36 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('$json + n8n string methods', () => {
|
|
|
|
wf.actions.addInitialNodeToCanvas('Schedule Trigger', { keepNdvOpen: true });
|
|
|
|
ndv.actions.setPinnedData([{ myStr: 'hello@n8n.io is an email' }]);
|
|
|
|
ndv.actions.close();
|
|
|
|
addSet();
|
|
|
|
|
|
|
|
const input = '{{$json.myStr.extractEmail() + " " + $json.myStr.isEmpty()';
|
|
|
|
const output = 'hello@n8n.io false';
|
|
|
|
|
|
|
|
ndv.getters.inlineExpressionEditorInput().clear().type(input);
|
|
|
|
ndv.actions.execute();
|
2023-02-24 09:07:35 -08:00
|
|
|
ndv.getters.outputDataContainer().should('be.visible');
|
2023-02-17 06:08:26 -08:00
|
|
|
ndv.getters.outputDataContainer().contains(output);
|
2023-02-08 01:41:36 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('$json + native numeric methods', () => {
|
|
|
|
wf.actions.addInitialNodeToCanvas('Schedule Trigger', { keepNdvOpen: true });
|
|
|
|
ndv.actions.setPinnedData([{ myNum: 9.123 }]);
|
|
|
|
ndv.actions.close();
|
|
|
|
addSet();
|
|
|
|
|
|
|
|
const input = '{{$json.myNum.toPrecision(3)';
|
|
|
|
const output = '9.12';
|
|
|
|
|
|
|
|
ndv.getters.inlineExpressionEditorInput().clear().type(input);
|
|
|
|
ndv.actions.execute();
|
2023-02-24 09:07:35 -08:00
|
|
|
ndv.getters.outputDataContainer().should('be.visible');
|
2023-02-17 06:08:26 -08:00
|
|
|
ndv.getters.outputDataContainer().contains(output);
|
2023-02-08 01:41:36 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('$json + n8n numeric methods', () => {
|
|
|
|
wf.actions.addInitialNodeToCanvas('Schedule Trigger', { keepNdvOpen: true });
|
|
|
|
ndv.actions.setPinnedData([{ myStr: 'hello@n8n.io is an email' }]);
|
|
|
|
ndv.actions.close();
|
|
|
|
addSet();
|
|
|
|
|
|
|
|
const input = '{{$json.myStr.extractEmail() + " " + $json.myStr.isEmpty()';
|
|
|
|
const output = 'hello@n8n.io false';
|
|
|
|
|
|
|
|
ndv.getters.inlineExpressionEditorInput().clear().type(input);
|
|
|
|
ndv.actions.execute();
|
2023-02-24 09:07:35 -08:00
|
|
|
ndv.getters.outputDataContainer().should('be.visible');
|
2023-02-17 06:08:26 -08:00
|
|
|
ndv.getters.outputDataContainer().contains(output);
|
2023-02-08 01:41:36 -08:00
|
|
|
});
|
|
|
|
|
2023-03-02 07:50:21 -08:00
|
|
|
it('$json + native array access', () => {
|
2023-02-08 01:41:36 -08:00
|
|
|
wf.actions.addInitialNodeToCanvas('Schedule Trigger', { keepNdvOpen: true });
|
|
|
|
ndv.actions.setPinnedData([{ myArr: [1, 2, 3] }]);
|
|
|
|
ndv.actions.close();
|
|
|
|
addSet();
|
2023-03-02 07:50:21 -08:00
|
|
|
const input = '{{$json.myArr.includes(1) + " " + $json.myArr[2]';
|
2023-02-08 01:41:36 -08:00
|
|
|
const output = 'true 3';
|
|
|
|
|
|
|
|
ndv.getters.inlineExpressionEditorInput().clear().type(input);
|
|
|
|
ndv.actions.execute();
|
2023-07-28 00:51:07 -07:00
|
|
|
ndv.getters.outputDataContainer().find('[class*=value_]').should('exist');
|
2023-03-02 07:50:21 -08:00
|
|
|
ndv.getters.outputDataContainer().find('[class*=value_]').should('contain', output);
|
2023-02-08 01:41:36 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('$json + n8n array methods', () => {
|
|
|
|
wf.actions.addInitialNodeToCanvas('Schedule Trigger', { keepNdvOpen: true });
|
|
|
|
ndv.actions.setPinnedData([{ myArr: [1, 2, 3] }]);
|
|
|
|
ndv.actions.close();
|
|
|
|
addSet();
|
|
|
|
|
|
|
|
const input = '{{$json.myArr.first() + " " + $json.myArr.last()';
|
|
|
|
const output = '1 3';
|
|
|
|
|
|
|
|
ndv.getters.inlineExpressionEditorInput().clear().type(input);
|
|
|
|
ndv.actions.execute();
|
2023-07-28 00:51:07 -07:00
|
|
|
ndv.getters.outputDataContainer().find('[class*=value_]').should('exist');
|
2023-03-02 07:50:21 -08:00
|
|
|
ndv.getters.outputDataContainer().find('[class*=value_]').should('contain', output);
|
2023-02-08 01:41:36 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// ----------------------------------
|
|
|
|
// utils
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
const addSet = () => {
|
|
|
|
wf.actions.addNodeToCanvas('Set', true, true);
|
2023-07-28 00:51:07 -07:00
|
|
|
ndv.getters.parameterInput('keepOnlySet').find('.el-switch').click(); // shorten output
|
2023-02-08 01:41:36 -08:00
|
|
|
cy.get('input[placeholder="Add Value"]').click();
|
|
|
|
cy.get('span').contains('String').click();
|
|
|
|
ndv.getters.nthParam(3).contains('Expression').invoke('show').click(); // Values to Set > String > Value
|
|
|
|
};
|