2023-02-08 01:41:36 -08:00
|
|
|
import { WorkflowPage, NDV } from '../pages';
|
2024-02-06 09:34:34 -08:00
|
|
|
import { getVisibleSelect } from '../utils';
|
2023-02-08 01:41:36 -08:00
|
|
|
|
|
|
|
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();
|
2023-09-19 03:16:35 -07:00
|
|
|
addEditFields();
|
2023-02-08 01:41:36 -08:00
|
|
|
|
|
|
|
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();
|
2023-09-19 03:16:35 -07:00
|
|
|
addEditFields();
|
2023-02-08 01:41:36 -08:00
|
|
|
|
|
|
|
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();
|
2023-09-19 03:16:35 -07:00
|
|
|
addEditFields();
|
2023-02-08 01:41:36 -08:00
|
|
|
|
|
|
|
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();
|
2023-09-19 03:16:35 -07:00
|
|
|
addEditFields();
|
2023-02-08 01:41:36 -08:00
|
|
|
|
|
|
|
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();
|
2023-09-19 03:16:35 -07:00
|
|
|
addEditFields();
|
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();
|
2023-09-19 03:16:35 -07:00
|
|
|
addEditFields();
|
2023-02-08 01:41:36 -08:00
|
|
|
|
|
|
|
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
|
|
|
|
// ----------------------------------
|
|
|
|
|
2023-09-19 03:16:35 -07:00
|
|
|
const addEditFields = () => {
|
|
|
|
wf.actions.addNodeToCanvas('Edit Fields', true, true);
|
2024-02-06 09:34:34 -08:00
|
|
|
ndv.getters.assignmentCollectionAdd('assignments').click();
|
|
|
|
ndv.getters.assignmentValue('assignments').contains('Expression').invoke('show').click();
|
2023-02-08 01:41:36 -08:00
|
|
|
};
|