1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #1942 from node-red-hitachi/dev-uitest-place

Automatically adjust node deployment
This commit is contained in:
Nick O'Leary 2018-10-25 09:56:33 +01:00 committed by GitHub
commit ba7416450e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 165 additions and 139 deletions

View File

@ -21,12 +21,32 @@ var events = require("nr-test-utils").require("@node-red/runtime/lib/events.js")
var palette = require("./palette_page"); var palette = require("./palette_page");
var nodeFactory = require("../nodes/nodefactory_page"); var nodeFactory = require("../nodes/nodefactory_page");
var flowLayout = {
flowRightEnd : 600,
widthInterval : 300,
heightInterval : 80
};
var previousX = -flowLayout.widthInterval;
var previousY = 0;
function addNode(type, x, y) { function addNode(type, x, y) {
var offsetX = x ? x : 0; if (x !== undefined) {
var offsetY = y ? y : 0; previousX = x;
if (y !== undefined) {
previousY = y;
}
} else {
if (previousX < flowLayout.flowRightEnd) {
previousX = previousX + flowLayout.widthInterval;
} else {
previousX = 0;
previousY = previousY + flowLayout.heightInterval;
}
}
browser.moveToObject(palette.getId(type)); browser.moveToObject(palette.getId(type));
browser.buttonDown(); browser.buttonDown();
browser.moveToObject("#palette-search", offsetX + 300, offsetY + 100); // adjust to the top-left corner of workspace. browser.moveToObject("#palette-search", previousX + 300, previousY + 100); // adjust to the top-left corner of workspace.
browser.buttonUp(); browser.buttonUp();
// Last node is the one that has been created right now. // Last node is the one that has been created right now.
var nodeElement = browser.elements('//*[@class="node nodegroup"][last()]'); var nodeElement = browser.elements('//*[@class="node nodegroup"][last()]');
@ -55,8 +75,21 @@ function deploy() {
browser.waitForText('#btn-deploy', 2000); browser.waitForText('#btn-deploy', 2000);
} }
function init(width, height) {
deleteAllNodes();
if (width !== undefined) {
flowLayout.widthInterval = width;
}
if (height !== undefined) {
flowLayout.heightInterval = height;
}
previousX = -flowLayout.widthInterval;
previousY = 0;
}
module.exports = { module.exports = {
addNode: addNode, addNode: addNode,
deleteAllNodes: deleteAllNodes, deploy: deploy,
deploy: deploy init: init
}; };

View File

@ -22,11 +22,10 @@ var helper = require("../../editor_helper");
var debugTab = require('../../pageobjects/editor/debugTab_page'); var debugTab = require('../../pageobjects/editor/debugTab_page');
var workspace = require('../../pageobjects/editor/workspace_page'); var workspace = require('../../pageobjects/editor/workspace_page');
var nodeWidth = 200;
describe('Workspace', function() { describe('Workspace', function() {
beforeEach(function() { beforeEach(function() {
workspace.deleteAllNodes(); workspace.init();
}); });
before(function() { before(function() {
@ -43,7 +42,7 @@ describe('Workspace', function() {
it('should output a timestamp', function() { it('should output a timestamp', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var debugNode = workspace.addNode("debug", nodeWidth); var debugNode = workspace.addNode("debug");
injectNode.connect(debugNode); injectNode.connect(debugNode);
workspace.deploy(); workspace.deploy();

View File

@ -20,14 +20,12 @@ var helper = require("../../editor_helper");
var debugTab = require('../../pageobjects/editor/debugTab_page'); var debugTab = require('../../pageobjects/editor/debugTab_page');
var workspace = require('../../pageobjects/editor/workspace_page'); var workspace = require('../../pageobjects/editor/workspace_page');
var nodeWidth = 200;
var nodeHeight = 100;
var httpNodeRoot = "/api"; var httpNodeRoot = "/api";
// https://cookbook.nodered.org/ // https://cookbook.nodered.org/
describe('cookbook', function() { describe('cookbook', function() {
beforeEach(function() { beforeEach(function() {
workspace.deleteAllNodes(); workspace.init();
}); });
before(function() { before(function() {
@ -41,8 +39,8 @@ describe('cookbook', function() {
describe('HTTP endpoints', function () { describe('HTTP endpoints', function () {
it('create an HTTP endpoint', function () { it('create an HTTP endpoint', function () {
var httpinNode = workspace.addNode("httpin"); var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("get"); httpinNode.setMethod("get");
@ -59,9 +57,9 @@ describe('cookbook', function() {
templateNode.connect(httpResponseNode); templateNode.connect(httpResponseNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight); var injectNode = workspace.addNode("inject");
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight); var debugNode = workspace.addNode("debug");
httpRequestNode.edit(); httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello'); httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello');
@ -81,8 +79,8 @@ describe('cookbook', function() {
it('handle query parameters passed to an HTTP endpoint', function () { it('handle query parameters passed to an HTTP endpoint', function () {
var httpinNode = workspace.addNode("httpin"); var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("get"); httpinNode.setMethod("get");
@ -99,9 +97,9 @@ describe('cookbook', function() {
templateNode.connect(httpResponseNode); templateNode.connect(httpResponseNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight); var injectNode = workspace.addNode("inject");
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight); var debugNode = workspace.addNode("debug");
httpRequestNode.edit(); httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-query?name=Nick'); httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-query?name=Nick');
@ -121,8 +119,8 @@ describe('cookbook', function() {
it('handle url parameters in an HTTP endpoint', function () { it('handle url parameters in an HTTP endpoint', function () {
var httpinNode = workspace.addNode("httpin"); var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth * 2); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("get"); httpinNode.setMethod("get");
@ -139,9 +137,9 @@ describe('cookbook', function() {
templateNode.connect(httpResponseNode); templateNode.connect(httpResponseNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight); var injectNode = workspace.addNode("inject");
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight); var debugNode = workspace.addNode("debug");
httpRequestNode.edit(); httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-param/Dave'); httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-param/Dave');
@ -161,8 +159,8 @@ describe('cookbook', function() {
it('access HTTP request headers', function () { it('access HTTP request headers', function () {
var httpinNode = workspace.addNode("httpin"); var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth * 1.5); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2.5); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("get"); httpinNode.setMethod("get");
@ -179,10 +177,10 @@ describe('cookbook', function() {
templateNode.connect(httpResponseNode); templateNode.connect(httpResponseNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight); var injectNode = workspace.addNode("inject", 0, 100);
var changeNode = workspace.addNode("change", nodeWidth, nodeHeight); var changeNode = workspace.addNode("change");
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth * 2, nodeHeight); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 3, nodeHeight); var debugNode = workspace.addNode("debug");
changeNode.edit(); changeNode.edit();
changeNode.ruleSet("headers", "msg", '{"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}', "json"); changeNode.ruleSet("headers", "msg", '{"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}', "json");
@ -207,12 +205,12 @@ describe('cookbook', function() {
it('include data captured in another flow', function () { it('include data captured in another flow', function () {
var injectNodeTimestamp = workspace.addNode("inject"); var injectNodeTimestamp = workspace.addNode("inject");
var changeNodeStore = workspace.addNode("change", nodeWidth); var changeNodeStore = workspace.addNode("change");
var httpinNode = workspace.addNode("httpin", 0, nodeHeight); var httpinNode = workspace.addNode("httpin", 0, 100);
var changeNodeCopy = workspace.addNode("change", nodeWidth * 2, nodeHeight); var changeNodeCopy = workspace.addNode("change");
var templateNode = workspace.addNode("template", nodeWidth * 3, nodeHeight); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 4, nodeHeight); var httpResponseNode = workspace.addNode("httpResponse");
injectNodeTimestamp.edit(); injectNodeTimestamp.edit();
injectNodeTimestamp.setPayload("date"); injectNodeTimestamp.setPayload("date");
@ -244,9 +242,9 @@ describe('cookbook', function() {
templateNode.connect(httpResponseNode); templateNode.connect(httpResponseNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNodeCheck = workspace.addNode("inject", 0, nodeHeight * 2); var injectNodeCheck = workspace.addNode("inject", 0, 300);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight * 2); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight * 2); var debugNode = workspace.addNode("debug");
httpRequestNode.edit(); httpRequestNode.edit();
httpRequestNode.setMethod("GET"); httpRequestNode.setMethod("GET");
@ -268,9 +266,9 @@ describe('cookbook', function() {
it('serve JSON content', function () { it('serve JSON content', function () {
var httpinNode = workspace.addNode("httpin"); var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth); var templateNode = workspace.addNode("template");
var changeNode = workspace.addNode("change", nodeWidth * 2); var changeNode = workspace.addNode("change");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("get"); httpinNode.setMethod("get");
@ -294,9 +292,9 @@ describe('cookbook', function() {
changeNode.connect(httpResponseNode); changeNode.connect(httpResponseNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight); var injectNode = workspace.addNode("inject", 0, 200);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight); var debugNode = workspace.addNode("debug");
httpRequestNode.edit(); httpRequestNode.edit();
httpRequestNode.setMethod("GET"); httpRequestNode.setMethod("GET");
@ -322,9 +320,9 @@ describe('cookbook', function() {
it('serve a local file', function () { it('serve a local file', function () {
var httpinNode = workspace.addNode("httpin"); var httpinNode = workspace.addNode("httpin");
var fileinNode = workspace.addNode("filein", nodeWidth); var fileinNode = workspace.addNode("filein");
var changeNode = workspace.addNode("change", nodeWidth * 2, nodeHeight); var changeNode = workspace.addNode("change", 200, 100);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3.5, nodeHeight); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("get"); httpinNode.setMethod("get");
@ -347,9 +345,9 @@ describe('cookbook', function() {
changeNode.connect(httpResponseNode); changeNode.connect(httpResponseNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight * 2); var injectNode = workspace.addNode("inject", 0, 200);
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight * 2); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight * 2); var debugNode = workspace.addNode("debug");
httpRequestNode.edit(); httpRequestNode.edit();
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-file'); httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-file');
@ -369,8 +367,8 @@ describe('cookbook', function() {
it('post raw data to a flow', function() { it('post raw data to a flow', function() {
var httpinNode = workspace.addNode("httpin"); var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth * 2); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("post"); httpinNode.setMethod("post");
@ -387,9 +385,9 @@ describe('cookbook', function() {
templateNode.connect(httpResponseNode); templateNode.connect(httpResponseNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight); var injectNode = workspace.addNode("inject");
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth, nodeHeight); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight); var debugNode = workspace.addNode("debug");
injectNode.edit() injectNode.edit()
injectNode.setPayload("str", "Nick"); injectNode.setPayload("str", "Nick");
@ -413,8 +411,8 @@ describe('cookbook', function() {
it('post form data to a flow', function () { it('post form data to a flow', function () {
var httpinNode = workspace.addNode("httpin"); var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth * 1.5); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2.5); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("post"); httpinNode.setMethod("post");
@ -431,10 +429,10 @@ describe('cookbook', function() {
templateNode.connect(httpResponseNode); templateNode.connect(httpResponseNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight); var injectNode = workspace.addNode("inject", 0, 100);
var changeNode = workspace.addNode("change", nodeWidth, nodeHeight); var changeNode = workspace.addNode("change");
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth * 2, nodeHeight); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 3, nodeHeight); var debugNode = workspace.addNode("debug");
injectNode.edit() injectNode.edit()
injectNode.setPayload("str", "name=Nick"); injectNode.setPayload("str", "name=Nick");
@ -463,8 +461,8 @@ describe('cookbook', function() {
it('post JSON data to a flow', function() { it('post JSON data to a flow', function() {
var httpinNode = workspace.addNode("httpin"); var httpinNode = workspace.addNode("httpin");
var templateNode = workspace.addNode("template", nodeWidth * 2); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("post"); httpinNode.setMethod("post");
@ -481,10 +479,10 @@ describe('cookbook', function() {
templateNode.connect(httpResponseNode); templateNode.connect(httpResponseNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, nodeHeight); var injectNode = workspace.addNode("inject", 0, 100);
var changeNode = workspace.addNode("change", nodeWidth, nodeHeight); var changeNode = workspace.addNode("change");
var httpRequestNode = workspace.addNode("httpRequest", nodeWidth * 2, nodeHeight); var httpRequestNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 3, nodeHeight); var debugNode = workspace.addNode("debug");
injectNode.edit() injectNode.edit()
injectNode.setPayload("json", '{"name":"Nick"}'); injectNode.setPayload("json", '{"name":"Nick"}');
@ -515,16 +513,16 @@ describe('cookbook', function() {
this.timeout(60000); this.timeout(60000);
var httpinNodeFormat = workspace.addNode("httpin"); var httpinNodeFormat = workspace.addNode("httpin");
var functionNodeFormat = workspace.addNode("function", nodeWidth * 1.5); var functionNodeFormat = workspace.addNode("function", 240);
var templateNode = workspace.addNode("template", nodeWidth * 2.5); var templateNode = workspace.addNode("template", 400);
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3.5); var httpResponseNode = workspace.addNode("httpResponse", 600);
var httpinNodeAdd = workspace.addNode("httpin", 0, nodeHeight); var httpinNodeAdd = workspace.addNode("httpin", 0, 100);
var functionNodeAdd = workspace.addNode("function", nodeWidth * 1.5, nodeHeight); var functionNodeAdd = workspace.addNode("function", 240);
var changeNode = workspace.addNode("change", nodeWidth * 2.5, nodeHeight * 1.5); var changeNode = workspace.addNode("change", 400);
var httpinNodeClear = workspace.addNode("httpin", 0, nodeHeight * 2); var httpinNodeClear = workspace.addNode("httpin", 0, 200);
var functionNodeClear = workspace.addNode("function", nodeWidth * 1.5, nodeHeight * 2); var functionNodeClear = workspace.addNode("function", 240);
httpinNodeFormat.edit(); httpinNodeFormat.edit();
httpinNodeFormat.setMethod("get"); httpinNodeFormat.setMethod("get");

View File

@ -24,8 +24,6 @@ var workspace = require('../../pageobjects/editor/workspace_page');
var specUtil = require('../../pageobjects/util/spec_util_page'); var specUtil = require('../../pageobjects/util/spec_util_page');
var mqttConfig = require('../../pageobjects/nodes/core/io/10-mqttconfig_page.js'); var mqttConfig = require('../../pageobjects/nodes/core/io/10-mqttconfig_page.js');
var nodeWidth = 200;
var nodeHeight = 100;
var httpNodeRoot = "/api"; var httpNodeRoot = "/api";
var mqttServer; var mqttServer;
@ -42,7 +40,7 @@ var moscaSettings = {
// https://cookbook.nodered.org/ // https://cookbook.nodered.org/
describe('cookbook', function() { describe('cookbook', function() {
beforeEach(function() { beforeEach(function() {
workspace.deleteAllNodes(); workspace.init();
}); });
before(function() { before(function() {
@ -69,7 +67,7 @@ describe('cookbook', function() {
describe('MQTT', function() { describe('MQTT', function() {
it('Add an MQTT broker to prepare for UI test', function() { it('Add an MQTT broker to prepare for UI test', function() {
var mqttOutNode = workspace.addNode("mqttOut", nodeWidth); var mqttOutNode = workspace.addNode("mqttOut");
mqttOutNode.edit(); mqttOutNode.edit();
mqttConfig.edit(); mqttConfig.edit();
@ -82,10 +80,10 @@ describe('cookbook', function() {
it('Connect to an MQTT broker', function() { it('Connect to an MQTT broker', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var mqttOutNode = workspace.addNode("mqttOut", nodeWidth); var mqttOutNode = workspace.addNode("mqttOut");
var mqttInNode = workspace.addNode("mqttIn", 0, nodeHeight); var mqttInNode = workspace.addNode("mqttIn", 0, 100);
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight); var debugNode = workspace.addNode("debug");
injectNode.edit(); injectNode.edit();
injectNode.setPayload("num", 22); injectNode.setPayload("num", 22);
@ -117,7 +115,7 @@ describe('cookbook', function() {
it('Set the topic of a published message', function() { it('Set the topic of a published message', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var mqttOutNode = workspace.addNode("mqttOut", nodeWidth * 2); var mqttOutNode = workspace.addNode("mqttOut");
injectNode.edit(); injectNode.edit();
injectNode.setPayload("num", 22); injectNode.setPayload("num", 22);
@ -130,8 +128,8 @@ describe('cookbook', function() {
injectNode.connect(mqttOutNode); injectNode.connect(mqttOutNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var mqttInNode = workspace.addNode("mqttIn", 0, nodeHeight); var mqttInNode = workspace.addNode("mqttIn", 0, 100);
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight); var debugNode = workspace.addNode("debug");
mqttInNode.edit(); mqttInNode.edit();
mqttInNode.setTopic("sensors/kitchen/temperature"); mqttInNode.setTopic("sensors/kitchen/temperature");
@ -150,7 +148,7 @@ describe('cookbook', function() {
it('Publish a retained message to a topic', function() { it('Publish a retained message to a topic', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var mqttOutNode = workspace.addNode("mqttOut", nodeWidth); var mqttOutNode = workspace.addNode("mqttOut");
injectNode.edit(); injectNode.edit();
injectNode.setPayload("num", 22); injectNode.setPayload("num", 22);
@ -169,8 +167,8 @@ describe('cookbook', function() {
debugTab.clearMessage(); debugTab.clearMessage();
// The code for confirmation starts from here. // The code for confirmation starts from here.
var mqttInNode = workspace.addNode("mqttIn", 0, nodeHeight); var mqttInNode = workspace.addNode("mqttIn", 0, 100);
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight); var debugNode = workspace.addNode("debug");
mqttInNode.edit(); mqttInNode.edit();
mqttInNode.setTopic("sensors/livingroom/temp"); mqttInNode.setTopic("sensors/livingroom/temp");
@ -189,11 +187,11 @@ describe('cookbook', function() {
it('Receive a parsed JSON message', function() { it('Receive a parsed JSON message', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var mqttOutNode = workspace.addNode("mqttOut", nodeWidth); var mqttOutNode = workspace.addNode("mqttOut");
var mqttInNode = workspace.addNode("mqttIn", 0, nodeHeight); var mqttInNode = workspace.addNode("mqttIn", 0, 100);
var jsonNode = workspace.addNode("json", nodeWidth, nodeHeight); var jsonNode = workspace.addNode("json");
var debugNode = workspace.addNode("debug", nodeWidth * 2, nodeHeight); var debugNode = workspace.addNode("debug");
injectNode.edit(); injectNode.edit();
injectNode.setPayload("json", '{"sensor_id": 1234, "temperature": 13 }'); injectNode.setPayload("json", '{"sensor_id": 1234, "temperature": 13 }');

View File

@ -23,14 +23,12 @@ var debugTab = require('../../pageobjects/editor/debugTab_page');
var workspace = require('../../pageobjects/editor/workspace_page'); var workspace = require('../../pageobjects/editor/workspace_page');
var specUtil = require('../../pageobjects/util/spec_util_page'); var specUtil = require('../../pageobjects/util/spec_util_page');
var nodeWidth = 200;
var nodeHeight = 100;
var httpNodeRoot = "/api"; var httpNodeRoot = "/api";
// https://cookbook.nodered.org/ // https://cookbook.nodered.org/
describe('cookbook', function() { describe('cookbook', function() {
beforeEach(function() { beforeEach(function() {
workspace.deleteAllNodes(); workspace.init();
}); });
before(function() { before(function() {
@ -44,8 +42,8 @@ describe('cookbook', function() {
describe('messages', function() { describe('messages', function() {
it('set a message property to a fixed value', function() { it('set a message property to a fixed value', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change", nodeWidth); var changeNode = workspace.addNode("change");
var debugNode = workspace.addNode("debug", nodeWidth * 2); var debugNode = workspace.addNode("debug");
changeNode.edit(); changeNode.edit();
changeNode.ruleSet("payload", "msg", "Hello World!"); changeNode.ruleSet("payload", "msg", "Hello World!");
@ -64,8 +62,8 @@ describe('cookbook', function() {
it('delete a message property', function() { it('delete a message property', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change", nodeWidth); var changeNode = workspace.addNode("change");
var debugNode = workspace.addNode("debug", nodeWidth * 2); var debugNode = workspace.addNode("debug");
changeNode.edit(); changeNode.edit();
changeNode.ruleDelete(); changeNode.ruleDelete();
@ -84,8 +82,8 @@ describe('cookbook', function() {
it('move a message property', function() { it('move a message property', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change", nodeWidth); var changeNode = workspace.addNode("change");
var debugNode = workspace.addNode("debug", nodeWidth * 2); var debugNode = workspace.addNode("debug");
injectNode.edit(); injectNode.edit();
injectNode.setTopic("Hello"); injectNode.setTopic("Hello");
@ -108,10 +106,10 @@ describe('cookbook', function() {
it('map a property between different numeric ranges', function() { it('map a property between different numeric ranges', function() {
var injectNode1 = workspace.addNode("inject"); var injectNode1 = workspace.addNode("inject");
var injectNode2 = workspace.addNode("inject", 0, 50); var injectNode2 = workspace.addNode("inject", 0, 100);
var injectNode3 = workspace.addNode("inject", 0, 100); var injectNode3 = workspace.addNode("inject", 0, 200);
var rangeNode = workspace.addNode("range", nodeWidth); var rangeNode = workspace.addNode("range", 200, 100);
var debugNode = workspace.addNode("debug", nodeWidth * 2); var debugNode = workspace.addNode("debug", 400);
injectNode1.edit(); injectNode1.edit();
injectNode1.setPayload("num", 0); injectNode1.setPayload("num", 0);
@ -149,7 +147,7 @@ describe('cookbook', function() {
describe('flow control', function() { describe('flow control', function() {
it('trigger a flow whenever Node-RED starts', function() { it('trigger a flow whenever Node-RED starts', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var debugNode = workspace.addNode("debug", nodeWidth * 2); var debugNode = workspace.addNode("debug");
injectNode.edit(); injectNode.edit();
injectNode.setPayload("str", "Started!") injectNode.setPayload("str", "Started!")
@ -165,7 +163,7 @@ describe('cookbook', function() {
it('trigger a flow at regular intervals', function() { it('trigger a flow at regular intervals', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var debugNode = workspace.addNode("debug", nodeWidth * 2); var debugNode = workspace.addNode("debug");
injectNode.edit(); injectNode.edit();
injectNode.setRepeat("interval"); injectNode.setRepeat("interval");
@ -191,9 +189,9 @@ describe('cookbook', function() {
describe('HTTP requests', function() { describe('HTTP requests', function() {
it('simple get request', function() { it('simple get request', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var httpRequetNode = workspace.addNode("httpRequest", nodeWidth); var httpRequetNode = workspace.addNode("httpRequest");
var htmlNode = workspace.addNode("html", nodeWidth * 2); var htmlNode = workspace.addNode("html");
var debugNode = workspace.addNode("debug", nodeWidth * 3); var debugNode = workspace.addNode("debug");
httpRequetNode.edit(); httpRequetNode.edit();
httpRequetNode.setMethod("GET"); httpRequetNode.setMethod("GET");
@ -218,9 +216,9 @@ describe('cookbook', function() {
it('set the URL of a request', function() { it('set the URL of a request', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change", nodeWidth * 1.5); var changeNode = workspace.addNode("change");
var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2.5); var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 3.5); var debugNode = workspace.addNode("debug");
injectNode.edit(); injectNode.edit();
injectNode.setPayload("str", helper.url()); injectNode.setPayload("str", helper.url());
@ -244,9 +242,9 @@ describe('cookbook', function() {
it('set the URL of a request using a template', function() { it('set the URL of a request using a template', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change", nodeWidth * 1.5); var changeNode = workspace.addNode("change");
var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2.5); var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 3.5); var debugNode = workspace.addNode("debug");
injectNode.edit(); injectNode.edit();
injectNode.setPayload("str", 'settings'); injectNode.setPayload("str", 'settings');
@ -274,9 +272,9 @@ describe('cookbook', function() {
it('set the query string parameters', function() { it('set the query string parameters', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var changeNode = workspace.addNode("change", nodeWidth); var changeNode = workspace.addNode("change");
var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2); var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 3); var debugNode = workspace.addNode("debug");
injectNode.edit(); injectNode.edit();
injectNode.setPayload("str", 'Nick'); injectNode.setPayload("str", 'Nick');
@ -295,9 +293,9 @@ describe('cookbook', function() {
httpRequetNode.connect(debugNode); httpRequetNode.connect(debugNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var httpinNode = workspace.addNode("httpin", 0, nodeHeight); var httpinNode = workspace.addNode("httpin", 0, 200);
var templateNode = workspace.addNode("template", nodeWidth, nodeHeight); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2, nodeHeight); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("get"); httpinNode.setMethod("get");
@ -323,9 +321,9 @@ describe('cookbook', function() {
it('get a parsed JSON response', function() { it('get a parsed JSON response', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var changeNodeSetPost = workspace.addNode("change", nodeWidth); var changeNodeSetPost = workspace.addNode("change");
var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2); var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 3); var debugNode = workspace.addNode("debug");
injectNode.edit(); injectNode.edit();
injectNode.setPayload("str", "json-response"); injectNode.setPayload("str", "json-response");
@ -351,10 +349,10 @@ describe('cookbook', function() {
httpRequetNode.connect(debugNode); httpRequetNode.connect(debugNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var httpinNode = workspace.addNode("httpin", 0, nodeHeight); var httpinNode = workspace.addNode("httpin", 0, 200);
var templateNode = workspace.addNode("template", nodeWidth * 1.5, nodeHeight); var templateNode = workspace.addNode("template");
var changeNodeSetHeader = workspace.addNode("change", nodeWidth * 2.5, nodeHeight); var changeNodeSetHeader = workspace.addNode("change");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3.5, nodeHeight); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("get"); httpinNode.setMethod("get");
@ -385,8 +383,8 @@ describe('cookbook', function() {
it('get a binary response', function() { it('get a binary response', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var httpRequetNode = workspace.addNode("httpRequest", nodeWidth); var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 2); var debugNode = workspace.addNode("debug");
httpRequetNode.edit(); httpRequetNode.edit();
httpRequetNode.setMethod("GET"); httpRequetNode.setMethod("GET");
@ -408,9 +406,9 @@ describe('cookbook', function() {
it('set a request header', function() { it('set a request header', function() {
var injectNode = workspace.addNode("inject"); var injectNode = workspace.addNode("inject");
var functionNode = workspace.addNode("function", nodeWidth); var functionNode = workspace.addNode("function");
var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2); var httpRequetNode = workspace.addNode("httpRequest");
var debugNode = workspace.addNode("debug", nodeWidth * 3); var debugNode = workspace.addNode("debug");
functionNode.edit(); functionNode.edit();
functionNode.setFunction('msg.payload = "data to post";\nreturn msg;'); functionNode.setFunction('msg.payload = "data to post";\nreturn msg;');
@ -427,9 +425,9 @@ describe('cookbook', function() {
httpRequetNode.connect(debugNode); httpRequetNode.connect(debugNode);
// The code for confirmation starts from here. // The code for confirmation starts from here.
var httpinNode = workspace.addNode("httpin", 0, nodeHeight); var httpinNode = workspace.addNode("httpin", 0, 200);
var templateNode = workspace.addNode("template", nodeWidth * 1.5, nodeHeight); var templateNode = workspace.addNode("template");
var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2.5, nodeHeight); var httpResponseNode = workspace.addNode("httpResponse");
httpinNode.edit(); httpinNode.edit();
httpinNode.setMethod("post"); httpinNode.setMethod("post");