node-red-contrib-antenna-genius 0.2.1 → 0.2.5-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +2 -8
- package/README.md +2 -2
- package/antenna-genius-activate-antenna.js +8 -1
- package/antenna-genius-antenna-status.html +2 -2
- package/antenna-genius-antenna-status.js +7 -4
- package/antenna-genius-band-labels.js +19 -3
- package/antenna-genius-server.js +8 -2
- package/package.json +10 -4
- package/test/antenna-genius-activate-antenna.spec.js +88 -0
- package/test/antenna-genius-antenna-status.spec.js +122 -0
- package/test/antenna-genius-band-labels.spec.js +109 -0
- package/test/antenna-genius-server.spec.js +36 -0
- package/test/antenna-genius-activate-antenna_spec.js +0 -23
- package/test/antenna-genius-antenna-status_spec.js +0 -24
- package/test/antenna-genius-band-labels_spec.js +0 -23
- package/test/antenna-genius-server_spec.js +0 -25
package/.vscode/launch.json
CHANGED
|
@@ -19,15 +19,9 @@
|
|
|
19
19
|
"type": "node",
|
|
20
20
|
"request": "launch",
|
|
21
21
|
"name": "Mocha Tests",
|
|
22
|
-
"program": "${workspaceFolder}/node_modules/
|
|
22
|
+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
|
|
23
23
|
"args": [
|
|
24
|
-
|
|
25
|
-
"dot",
|
|
26
|
-
"--slow",
|
|
27
|
-
"5000",
|
|
28
|
-
"--colors",
|
|
29
|
-
"${workspaceFolder}/test/**/*_spec.js",
|
|
30
|
-
|
|
24
|
+
"-i"
|
|
31
25
|
],
|
|
32
26
|
"internalConsoleOptions": "openOnSessionStart",
|
|
33
27
|
"skipFiles": [
|
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Port 1: Status for Radio A antenna.
|
|
|
41
41
|
|
|
42
42
|
`enabled (boolean)`: same as `payload.enabled`.
|
|
43
43
|
|
|
44
|
-
`topic (string)`: string that can be used to
|
|
44
|
+
`topic (string)`: string that can be used to activate this antenna using the `activate-antenna` node.
|
|
45
45
|
|
|
46
46
|
Port 2: Status for Radio A antenna.
|
|
47
47
|
|
|
@@ -55,7 +55,7 @@ Port 2: Status for Radio A antenna.
|
|
|
55
55
|
|
|
56
56
|
`enabled (boolean)`: same as `payload.enabled`.
|
|
57
57
|
|
|
58
|
-
`topic (string)`: string that can be used to
|
|
58
|
+
`topic (string)`: string that can be used to activate this antenna using the `activate-antenna` node.
|
|
59
59
|
|
|
60
60
|
### Details
|
|
61
61
|
|
|
@@ -11,7 +11,9 @@ module.exports = (RED) => {
|
|
|
11
11
|
this.server = RED.nodes.getNode(config.server);
|
|
12
12
|
|
|
13
13
|
this.server.updatesEventEmitter.on("connected", () => {
|
|
14
|
-
|
|
14
|
+
if(this.server.info.name) {
|
|
15
|
+
this.status({ fill: "green", shape: "dot", text: this.server.info.name });
|
|
16
|
+
}
|
|
15
17
|
});
|
|
16
18
|
|
|
17
19
|
this.server.updatesEventEmitter.on('closed', () => {
|
|
@@ -20,12 +22,17 @@ module.exports = (RED) => {
|
|
|
20
22
|
|
|
21
23
|
node.on('input', (msg, send, done) => {
|
|
22
24
|
if(msg.topic) {
|
|
25
|
+
if(this.server.info.name) {
|
|
26
|
+
this.status({ fill: "green", shape: "dot", text: this.server.info.name });
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
let command = Utils.encode(0, 0, 415, 0, msg.topic);
|
|
24
30
|
|
|
25
31
|
this.server.client.write(command);
|
|
26
32
|
}
|
|
27
33
|
else {
|
|
28
34
|
this.status({ fill: "red", shape: "ring", text: "topic is not set" });
|
|
35
|
+
this.server.forceUpdate();
|
|
29
36
|
}
|
|
30
37
|
if(done) {
|
|
31
38
|
done();
|
|
@@ -56,7 +56,7 @@ Port 1: Status for Radio A antenna.
|
|
|
56
56
|
|
|
57
57
|
: enabled (boolean) : same as `payload.enabled`.
|
|
58
58
|
|
|
59
|
-
: topic (string) : string that can be used to
|
|
59
|
+
: topic (string) : string that can be used to activate this antenna using the `activate-antenna` node.
|
|
60
60
|
|
|
61
61
|
Port 2: Status for Radio A antenna.
|
|
62
62
|
|
|
@@ -70,7 +70,7 @@ Port 2: Status for Radio A antenna.
|
|
|
70
70
|
|
|
71
71
|
: enabled (boolean) : same as `payload.enabled`.
|
|
72
72
|
|
|
73
|
-
: topic (string) : string that can be used to
|
|
73
|
+
: topic (string) : string that can be used to activate this antenna using the `activate-antenna` node.
|
|
74
74
|
|
|
75
75
|
### Details
|
|
76
76
|
|
|
@@ -20,22 +20,25 @@ module.exports = (RED) => {
|
|
|
20
20
|
this.server = RED.nodes.getNode(config.server);
|
|
21
21
|
|
|
22
22
|
this.server.updatesEventEmitter.on("connected", () => {
|
|
23
|
-
|
|
23
|
+
if(this.server.info.name ) {
|
|
24
|
+
this.status({ fill: "green", shape: "dot", text: this.server.info.name });
|
|
25
|
+
}
|
|
24
26
|
});
|
|
25
27
|
|
|
26
28
|
this.server.updatesEventEmitter.on('closed', () => {
|
|
27
29
|
this.status({ fill: "red", shape: "ring", text: "disconnected" });
|
|
28
30
|
});
|
|
29
31
|
|
|
30
|
-
this.server.updatesEventEmitter.on("status", () => {
|
|
32
|
+
this.server.updatesEventEmitter.on("status", (forceUpdate) => {
|
|
31
33
|
|
|
32
34
|
let maxNumberOfAntennas = this.server.status.stackReach * 8;
|
|
33
|
-
if(this.antennaNumber < 1 || this.antennaNumber > maxNumberOfAntennas) {
|
|
35
|
+
if(this.antennaNumber < 1 || this.antennaNumber > maxNumberOfAntennas || this.antennaNumber > this.server.antennas.length) {
|
|
34
36
|
this.status({ fill: "red", shape: "ring", text: "antenna number is out of range" });
|
|
35
37
|
return;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
let changed =
|
|
40
|
+
let changed = forceUpdate;
|
|
41
|
+
|
|
39
42
|
// Selected?
|
|
40
43
|
let radioAselected = this.antennaNumber == this.server.status.portA_antenna;
|
|
41
44
|
if (radioAselected != this.radioA.selected) {
|
|
@@ -9,21 +9,37 @@ module.exports = (RED) => {
|
|
|
9
9
|
this.server = RED.nodes.getNode(config.server);
|
|
10
10
|
|
|
11
11
|
this.server.updatesEventEmitter.on("connected", () => {
|
|
12
|
-
|
|
12
|
+
if(this.server.info.name) {
|
|
13
|
+
this.status({ fill: "green", shape: "dot", text: this.server.info.name });
|
|
14
|
+
}
|
|
13
15
|
});
|
|
14
16
|
|
|
15
17
|
this.server.updatesEventEmitter.on('closed', () => {
|
|
16
18
|
this.status({ fill: "red", shape: "ring", text: "disconnected" });
|
|
17
19
|
});
|
|
18
20
|
|
|
19
|
-
this.server.updatesEventEmitter.on("status", () => {
|
|
21
|
+
this.server.updatesEventEmitter.on("status", (forceUpdate) => {
|
|
20
22
|
let bandIndexA = this.server.status.portA_band;
|
|
21
23
|
let bandIndexB = this.server.status.portB_band;
|
|
22
24
|
|
|
25
|
+
if(bandIndexA === undefined || bandIndexB === undefined) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if(bandIndexA < 0 || bandIndexA >= this.server.bands.length)
|
|
30
|
+
{
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if(bandIndexB < 0 || bandIndexB >= this.server.bands.length)
|
|
35
|
+
{
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
23
39
|
let bandNameA = this.server.bands[bandIndexA].band_name;
|
|
24
40
|
let bandNameB = this.server.bands[bandIndexB].band_name;
|
|
25
41
|
|
|
26
|
-
let changed =
|
|
42
|
+
let changed = forceUpdate;
|
|
27
43
|
if (bandNameA !== this.bandNameA) {
|
|
28
44
|
changed = true;
|
|
29
45
|
this.bandNameA = bandNameA;
|
package/antenna-genius-server.js
CHANGED
|
@@ -2,7 +2,6 @@ const Net = require('net');
|
|
|
2
2
|
const {PromiseSocket} = require("promise-socket");
|
|
3
3
|
const EventEmitter = require('events');
|
|
4
4
|
const Utils = require('./Utils');
|
|
5
|
-
const { connect } = require('http2');
|
|
6
5
|
|
|
7
6
|
class UpdatesEventEmitter extends EventEmitter {}
|
|
8
7
|
|
|
@@ -23,6 +22,7 @@ module.exports = (RED) => {
|
|
|
23
22
|
this.bands = [];
|
|
24
23
|
this.interval = null;
|
|
25
24
|
this.timer = null;
|
|
25
|
+
this.refresh = 0;
|
|
26
26
|
|
|
27
27
|
this.updatesEventEmitter = new UpdatesEventEmitter();
|
|
28
28
|
this.updatesEventEmitter.setMaxListeners(0);
|
|
@@ -89,7 +89,8 @@ module.exports = (RED) => {
|
|
|
89
89
|
let decoded = Utils.decode(packet);
|
|
90
90
|
if(decoded.command == 401) {
|
|
91
91
|
this.status = { ...this.status, ...Utils.decode(packet) };
|
|
92
|
-
this.
|
|
92
|
+
this.refresh = (this.refresh + 1) % 1500;
|
|
93
|
+
this.updatesEventEmitter.emit("status", this.refresh == 0);
|
|
93
94
|
}
|
|
94
95
|
});
|
|
95
96
|
|
|
@@ -99,6 +100,7 @@ module.exports = (RED) => {
|
|
|
99
100
|
this.client.write(command);
|
|
100
101
|
}, 400);
|
|
101
102
|
|
|
103
|
+
this.forceUpdate();
|
|
102
104
|
this.updatesEventEmitter.emit("connected");
|
|
103
105
|
})
|
|
104
106
|
|
|
@@ -121,6 +123,10 @@ module.exports = (RED) => {
|
|
|
121
123
|
this.client.connect(this.port, this.host);
|
|
122
124
|
}
|
|
123
125
|
}
|
|
126
|
+
|
|
127
|
+
forceUpdate() {
|
|
128
|
+
this.refresh = -1;
|
|
129
|
+
}
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
RED.nodes.registerType("antenna-genius-server",AntennaGeniusServerNode);
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-antenna-genius",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5-beta",
|
|
4
4
|
"description": "Antenna Genius Control and Monitoring Nodes",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"node-red"
|
|
7
|
+
],
|
|
6
8
|
"scripts": {
|
|
7
|
-
"test": "
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"watch": "jest --watch",
|
|
8
11
|
"start": "node ./node_modules/node-red/red.js -v -u C:/Users/dahlj.GREATSTONE/.node-red ",
|
|
9
12
|
"debug": "node --nolazy ./node_modules/node-red/red.js -v -u C:/Users/dahlj.GREATSTONE/.node-red"
|
|
10
13
|
},
|
|
@@ -31,8 +34,11 @@
|
|
|
31
34
|
"promise-socket": "^7.0.0"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
|
-
"
|
|
37
|
+
"jest": "^27.4.7",
|
|
35
38
|
"node-red": "^2.1.4",
|
|
36
39
|
"node-red-node-test-helper": "^0.2.7"
|
|
40
|
+
},
|
|
41
|
+
"jest": {
|
|
42
|
+
"verbose": true
|
|
37
43
|
}
|
|
38
44
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const helper = require("node-red-node-test-helper");
|
|
2
|
+
const activateAntennaNode = require("../antenna-genius-activate-antenna.js");
|
|
3
|
+
const serverNode = require("../antenna-genius-server.js");
|
|
4
|
+
|
|
5
|
+
const nodes = [activateAntennaNode, serverNode];
|
|
6
|
+
|
|
7
|
+
describe('antenna-genius-activate-antenna Node', () => {
|
|
8
|
+
const flow = [
|
|
9
|
+
{ id: "n1", type: "antenna-genius-server", name: "test name", hostname: "localhost", port: 9007, disabledColor: "Black", activeColor: "Green", selectedColor: "Blue", autoConnect: false},
|
|
10
|
+
{ id: "n2", type: "antenna-genius-activate-antenna", name: "test name", server: "n1", wires:[["n3"]]},
|
|
11
|
+
{ id: "n3", type: "helper" }
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
helper.unload();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should be loaded', done => {
|
|
22
|
+
helper.load(nodes, flow, () => {
|
|
23
|
+
var n2 = helper.getNode("n2");
|
|
24
|
+
expect(n2).toBeDefined();
|
|
25
|
+
done();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should have properties', done => {
|
|
30
|
+
helper.load(nodes, flow, () => {
|
|
31
|
+
var n2 = helper.getNode("n2");
|
|
32
|
+
expect(n2).toHaveProperty('name', 'test name');
|
|
33
|
+
done();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should not provide connected status', done => {
|
|
38
|
+
helper.load(nodes, flow, () => {
|
|
39
|
+
var n2 = helper.getNode("n2");
|
|
40
|
+
n2.server.updatesEventEmitter.emit("connected");
|
|
41
|
+
expect(n2.status.notCalled).toBeTruthy();
|
|
42
|
+
done();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should provide connected status', done => {
|
|
47
|
+
helper.load(nodes, flow, () => {
|
|
48
|
+
var n2 = helper.getNode("n2");
|
|
49
|
+
n2.server.info = { name: "Name" };
|
|
50
|
+
n2.server.updatesEventEmitter.emit("connected");
|
|
51
|
+
expect(n2.status.calledOnceWithExactly({ fill: "green", shape: "dot", text: "Name" })).toBeTruthy();
|
|
52
|
+
done();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should provide disconnected status', done => {
|
|
57
|
+
helper.load(nodes, flow, () => {
|
|
58
|
+
var n2 = helper.getNode("n2");
|
|
59
|
+
n2.server.info = { name: "Name" };
|
|
60
|
+
n2.server.updatesEventEmitter.emit("closed");
|
|
61
|
+
expect(n2.status.calledOnceWithExactly({ fill: "red", shape: "ring", text: "disconnected" })).toBeTruthy();
|
|
62
|
+
done();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should provide for invalid input', done => {
|
|
67
|
+
helper.load(nodes, flow, () => {
|
|
68
|
+
var n2 = helper.getNode("n2");
|
|
69
|
+
n2.server.info = { name: "Name" };
|
|
70
|
+
n2.receive({ payload: true });
|
|
71
|
+
n2.on("call:status", call => {
|
|
72
|
+
expect(n2.status.calledOnceWithExactly({ fill: "red", shape: "ring", text: "topic is not set" })).toBeTruthy();
|
|
73
|
+
done();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should provide for valid input', done => {
|
|
79
|
+
helper.load(nodes, flow, () => {
|
|
80
|
+
var n2 = helper.getNode("n2");
|
|
81
|
+
n2.server.info = { name: "Name" };
|
|
82
|
+
n2.receive({ payload: true, topic: "1;1" });
|
|
83
|
+
expect(n2.status.calledOnceWithExactly({ fill: "green", shape: "dot", text: "Name" })).toBeTruthy();
|
|
84
|
+
done();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const helper = require("node-red-node-test-helper");
|
|
2
|
+
const antennaStatusNode = require("../antenna-genius-antenna-status.js");
|
|
3
|
+
const serverNode = require("../antenna-genius-server.js");
|
|
4
|
+
|
|
5
|
+
const nodes = [antennaStatusNode, serverNode];
|
|
6
|
+
|
|
7
|
+
describe('antenna-genius-antenna-status Node', () => {
|
|
8
|
+
const flow = [
|
|
9
|
+
{ id: "n1", type: "antenna-genius-server", name: "test name", hostname: "localhost", port: 9007, disabledColor: "Black", activeColor: "Green", selectedColor: "Blue", autoConnect: false},
|
|
10
|
+
{ id: "n2", type: "antenna-genius-antenna-status", name: "test name", server: "n1", antennaNb: 2, wires:[["n3"],["n4"]]},
|
|
11
|
+
{ id: "n3", type: "helper" },
|
|
12
|
+
{ id: "n4", type: "helper" }
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
helper.unload();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should be loaded', done => {
|
|
20
|
+
helper.load(nodes, flow, () => {
|
|
21
|
+
var n2 = helper.getNode("n2");
|
|
22
|
+
expect(n2).toBeDefined();
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should have properties', done => {
|
|
28
|
+
helper.load(nodes, flow, () => {
|
|
29
|
+
var n2 = helper.getNode("n2");
|
|
30
|
+
expect(n2).toHaveProperty('name', 'test name');
|
|
31
|
+
expect(n2).toHaveProperty('antennaNumber', 2);
|
|
32
|
+
done();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should not provide connected status', done => {
|
|
37
|
+
helper.load(nodes, flow, () => {
|
|
38
|
+
var n2 = helper.getNode("n2");
|
|
39
|
+
n2.server.updatesEventEmitter.emit("connected");
|
|
40
|
+
expect(n2.status.notCalled).toBeTruthy();
|
|
41
|
+
done();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should provide connected status', done => {
|
|
46
|
+
helper.load(nodes, flow, () => {
|
|
47
|
+
var n2 = helper.getNode("n2");
|
|
48
|
+
n2.server.info = { name: "Name" };
|
|
49
|
+
n2.server.updatesEventEmitter.emit("connected");
|
|
50
|
+
expect(n2.status.calledOnceWithExactly({ fill: "green", shape: "dot", text: "Name" })).toBeTruthy();
|
|
51
|
+
done();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should provide disconnected status', done => {
|
|
56
|
+
helper.load(nodes, flow, () => {
|
|
57
|
+
var n2 = helper.getNode("n2");
|
|
58
|
+
n2.server.info = { name: "Name" };
|
|
59
|
+
n2.server.updatesEventEmitter.emit("closed");
|
|
60
|
+
expect(n2.status.calledOnceWithExactly({ fill: "red", shape: "ring", text: "disconnected" })).toBeTruthy();
|
|
61
|
+
done();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should provide A port output with valid input', done => {
|
|
66
|
+
helper.load(nodes, flow, () => {
|
|
67
|
+
var n2 = helper.getNode("n2");
|
|
68
|
+
n2.server.info = { name: "Name" };
|
|
69
|
+
n2.server.status = { portA_antenna: 1, portA_band: 0, portB_antenna: 2, portB_band: 1 };
|
|
70
|
+
n2.server.antennas = [{ antenna_name: "Antenna0", antenna_bands: [1, 1] }, { antenna_name: "Antenna1", antenna_bands: [1, 1] }];
|
|
71
|
+
n2.server.updatesEventEmitter.emit("status", false);
|
|
72
|
+
expect(n2.send.calledOnce).toBeTruthy();
|
|
73
|
+
expect(n2.status.calledOnceWithExactly({ fill: "green", shape: "dot", text: "Name - Antenna1" })).toBeTruthy();
|
|
74
|
+
|
|
75
|
+
var n3 = helper.getNode("n3");
|
|
76
|
+
n3.on("input", (msg) => {
|
|
77
|
+
try {
|
|
78
|
+
expect(msg).toHaveProperty("payload", {
|
|
79
|
+
selected: false,
|
|
80
|
+
enabled: true,
|
|
81
|
+
name: 'Antenna1',
|
|
82
|
+
background: 'Green'
|
|
83
|
+
});
|
|
84
|
+
expect(msg).toHaveProperty("enabled", true);
|
|
85
|
+
expect(msg).toHaveProperty("topic", "1;2");
|
|
86
|
+
done();
|
|
87
|
+
} catch (err) {
|
|
88
|
+
done(err);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should provide B port output with valid input', done => {
|
|
95
|
+
helper.load(nodes, flow, () => {
|
|
96
|
+
var n2 = helper.getNode("n2");
|
|
97
|
+
n2.server.info = { name: "Name" };
|
|
98
|
+
n2.server.status = { portA_antenna: 1, portA_band: 0, portB_antenna: 2, portB_band: 1 };
|
|
99
|
+
n2.server.antennas = [{ antenna_name: "Antenna0", antenna_bands: [1, 1] }, { antenna_name: "Antenna1", antenna_bands: [1, 1] }];
|
|
100
|
+
n2.server.updatesEventEmitter.emit("status", false);
|
|
101
|
+
expect(n2.send.calledOnce).toBeTruthy();
|
|
102
|
+
expect(n2.status.calledOnceWithExactly({ fill: "green", shape: "dot", text: "Name - Antenna1" })).toBeTruthy();
|
|
103
|
+
|
|
104
|
+
var n4 = helper.getNode("n4");
|
|
105
|
+
n4.on("input", (msg) => {
|
|
106
|
+
try {
|
|
107
|
+
expect(msg).toHaveProperty("payload", {
|
|
108
|
+
selected: true,
|
|
109
|
+
enabled: true,
|
|
110
|
+
name: 'Antenna1',
|
|
111
|
+
background: 'Blue'
|
|
112
|
+
});
|
|
113
|
+
expect(msg).toHaveProperty("enabled", true);
|
|
114
|
+
expect(msg).toHaveProperty("topic", "2;2");
|
|
115
|
+
done();
|
|
116
|
+
} catch (err) {
|
|
117
|
+
done(err);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const helper = require("node-red-node-test-helper");
|
|
2
|
+
const bandLabelsNode = require("../antenna-genius-band-labels.js");
|
|
3
|
+
const serverNode = require("../antenna-genius-server.js");
|
|
4
|
+
|
|
5
|
+
const nodes = [bandLabelsNode, serverNode];
|
|
6
|
+
|
|
7
|
+
describe('antenna-genius-band-labels Node', () => {
|
|
8
|
+
|
|
9
|
+
const flow = [
|
|
10
|
+
{ id: "n1", type: "antenna-genius-server", name: "test name", hostname: "localhost", port: 9007, disabledColor: "Black", activeColor: "Green", selectedColor: "Blue", autoConnect: false},
|
|
11
|
+
{ id: "n2", type: "antenna-genius-band-labels", name: "test name", server: "n1", wires:[["n3"]]},
|
|
12
|
+
{ id: "n3", type: "helper" }
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
helper.unload();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should be loaded', done => {
|
|
23
|
+
helper.load(nodes, flow, () => {
|
|
24
|
+
var n2 = helper.getNode("n2");
|
|
25
|
+
expect(n2).toBeDefined();
|
|
26
|
+
done();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should have properties', done => {
|
|
31
|
+
helper.load(nodes, flow, () => {
|
|
32
|
+
var n2 = helper.getNode("n2");
|
|
33
|
+
expect(n2).toHaveProperty('name', 'test name');
|
|
34
|
+
done();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
it('should provide no output with no input', done => {
|
|
40
|
+
helper.load(nodes, flow, () => {
|
|
41
|
+
var n2 = helper.getNode("n2");
|
|
42
|
+
n2.server.updatesEventEmitter.emit("status", false);
|
|
43
|
+
expect(n2.send.notCalled).toBeTruthy();
|
|
44
|
+
done();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should provide no output with no band definitions', done => {
|
|
49
|
+
helper.load(nodes, flow, () => {
|
|
50
|
+
var n2 = helper.getNode("n2");
|
|
51
|
+
n2.server.status = { portA_band: 0, portB_band: 1 };
|
|
52
|
+
n2.server.updatesEventEmitter.emit("status", false);
|
|
53
|
+
expect(n2.send.notCalled).toBeTruthy();
|
|
54
|
+
done();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should provide output', done => {
|
|
59
|
+
helper.load(nodes, flow, () => {
|
|
60
|
+
var n2 = helper.getNode("n2");
|
|
61
|
+
n2.server.status = { portA_band: 0, portB_band: 1 };
|
|
62
|
+
n2.server.bands = [{ band_name: "bandA" }, { band_name: "bandB" }];
|
|
63
|
+
n2.server.info = { name: "Name" };
|
|
64
|
+
|
|
65
|
+
var n3 = helper.getNode("n3");
|
|
66
|
+
n3.on("input", (msg) => {
|
|
67
|
+
try {
|
|
68
|
+
expect(msg).toHaveProperty("payload", { bandLabelA: "bandA", bandLabelB: "bandB" });
|
|
69
|
+
expect(n2.send.calledOnce).toBeTruthy();
|
|
70
|
+
expect(n2.status.calledOnceWithExactly({ fill: "green", shape: "dot", text: "Name - bandA/bandB" })).toBeTruthy();
|
|
71
|
+
done();
|
|
72
|
+
} catch (err) {
|
|
73
|
+
done(err);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
n2.server.updatesEventEmitter.emit("status", false);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should not provide connected status', done => {
|
|
82
|
+
helper.load(nodes, flow, () => {
|
|
83
|
+
var n2 = helper.getNode("n2");
|
|
84
|
+
n2.server.updatesEventEmitter.emit("connected");
|
|
85
|
+
expect(n2.status.notCalled).toBeTruthy();
|
|
86
|
+
done();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should provide connected status', done => {
|
|
91
|
+
helper.load(nodes, flow, () => {
|
|
92
|
+
var n2 = helper.getNode("n2");
|
|
93
|
+
n2.server.info = { name: "Name" };
|
|
94
|
+
n2.server.updatesEventEmitter.emit("connected");
|
|
95
|
+
expect(n2.status.calledOnceWithExactly({ fill: "green", shape: "dot", text: "Name" })).toBeTruthy();
|
|
96
|
+
done();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should provide disconnected status', done => {
|
|
101
|
+
helper.load(nodes, flow, () => {
|
|
102
|
+
var n2 = helper.getNode("n2");
|
|
103
|
+
n2.server.info = { name: "Name" };
|
|
104
|
+
n2.server.updatesEventEmitter.emit("closed");
|
|
105
|
+
expect(n2.status.calledOnceWithExactly({ fill: "red", shape: "ring", text: "disconnected" })).toBeTruthy();
|
|
106
|
+
done();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const helper = require("node-red-node-test-helper");
|
|
2
|
+
const serverNode = require("../antenna-genius-server.js");
|
|
3
|
+
|
|
4
|
+
describe('antenna-genius-server Node', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
helper.unload();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('should be loaded', done => {
|
|
10
|
+
var flow = [
|
|
11
|
+
{ id: "n1", type: "antenna-genius-server", name: "test name", host: "localhost", port: 9007, disabledColor: "Black", activeColor: "Green", selectedColor: "Blue", autoConnect: false},
|
|
12
|
+
];
|
|
13
|
+
helper.load(serverNode, flow, () => {
|
|
14
|
+
var n1 = helper.getNode("n1");
|
|
15
|
+
expect(n1).toBeDefined();
|
|
16
|
+
done();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should have properties', done => {
|
|
21
|
+
var flow = [
|
|
22
|
+
{ id: "n1", type: "antenna-genius-server", name: "test name", host: "localhost", port: 9007, disabledColor: "Black", activeColor: "Green", selectedColor: "Blue", autoConnect: false},
|
|
23
|
+
];
|
|
24
|
+
helper.load(serverNode, flow, () => {
|
|
25
|
+
var n1 = helper.getNode("n1");
|
|
26
|
+
expect(n1).toHaveProperty('name', 'test name');
|
|
27
|
+
expect(n1).toHaveProperty('host', 'localhost');
|
|
28
|
+
expect(n1).toHaveProperty('port', 9007);
|
|
29
|
+
expect(n1).toHaveProperty('disabledColor', 'Black');
|
|
30
|
+
expect(n1).toHaveProperty('activeColor', 'Green');
|
|
31
|
+
expect(n1).toHaveProperty('selectedColor', 'Blue');
|
|
32
|
+
expect(n1).toHaveProperty('autoConnect', false);
|
|
33
|
+
done();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const helper = require("node-red-node-test-helper");
|
|
2
|
-
const activateAntennaNode = require("../antenna-genius-activate-antenna.js");
|
|
3
|
-
const serverNode = require("../antenna-genius-server.js");
|
|
4
|
-
|
|
5
|
-
const nodes = [activateAntennaNode, serverNode];
|
|
6
|
-
|
|
7
|
-
describe('antenna-genius-activate-antenna Node', function () {
|
|
8
|
-
afterEach(function () {
|
|
9
|
-
helper.unload();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should be loaded', function (done) {
|
|
13
|
-
var flow = [
|
|
14
|
-
{ id: "n1", type: "antenna-genius-server", name: "test name", hostname: "localhost", port: 9007, disabledColor: "Black", activeColor: "Green", selectedColor: "Blue", autoConnect: false},
|
|
15
|
-
{ id: "n2", type: "antenna-genius-activate-antenna", name: "test name", server: "n1"}
|
|
16
|
-
];
|
|
17
|
-
helper.load(nodes, flow, function () {
|
|
18
|
-
var n2 = helper.getNode("n2");
|
|
19
|
-
n2.should.have.property('name', 'test name');
|
|
20
|
-
done();
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const helper = require("node-red-node-test-helper");
|
|
2
|
-
const antennaStatusNode = require("../antenna-genius-antenna-status.js");
|
|
3
|
-
const serverNode = require("../antenna-genius-server.js");
|
|
4
|
-
|
|
5
|
-
const nodes = [antennaStatusNode, serverNode];
|
|
6
|
-
|
|
7
|
-
describe('antenna-genius-antenna-status Node', function () {
|
|
8
|
-
afterEach(function () {
|
|
9
|
-
helper.unload();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should be loaded', function (done) {
|
|
13
|
-
var flow = [
|
|
14
|
-
{ id: "n1", type: "antenna-genius-server", name: "test name", hostname: "localhost", port: 9007, disabledColor: "Black", activeColor: "Green", selectedColor: "Blue", autoConnect: false},
|
|
15
|
-
{ id: "n2", type: "antenna-genius-antenna-status", name: "test name", server: "n1", antennaNb: 6}
|
|
16
|
-
];
|
|
17
|
-
helper.load(nodes, flow, function () {
|
|
18
|
-
var n2 = helper.getNode("n2");
|
|
19
|
-
n2.should.have.property('name', 'test name');
|
|
20
|
-
n2.should.have.property('antennaNumber', 6);
|
|
21
|
-
done();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const helper = require("node-red-node-test-helper");
|
|
2
|
-
const bandLabelsNode = require("../antenna-genius-band-labels.js");
|
|
3
|
-
const serverNode = require("../antenna-genius-server.js");
|
|
4
|
-
|
|
5
|
-
const nodes = [bandLabelsNode, serverNode];
|
|
6
|
-
|
|
7
|
-
describe('antenna-genius-band-labels Node', function () {
|
|
8
|
-
afterEach(function () {
|
|
9
|
-
helper.unload();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should be loaded', function (done) {
|
|
13
|
-
var flow = [
|
|
14
|
-
{ id: "n1", type: "antenna-genius-server", name: "test name", hostname: "localhost", port: 9007, disabledColor: "Black", activeColor: "Green", selectedColor: "Blue", autoConnect: false},
|
|
15
|
-
{ id: "n2", type: "antenna-genius-band-labels", name: "test name", server: "n1"}
|
|
16
|
-
];
|
|
17
|
-
helper.load(nodes, flow, function () {
|
|
18
|
-
var n2 = helper.getNode("n2");
|
|
19
|
-
n2.should.have.property('name', 'test name');
|
|
20
|
-
done();
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const helper = require("node-red-node-test-helper");
|
|
2
|
-
const serverNode = require("../antenna-genius-server.js");
|
|
3
|
-
|
|
4
|
-
describe('antenna-genius-server Node', function () {
|
|
5
|
-
afterEach(function () {
|
|
6
|
-
helper.unload();
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('should be loaded', function (done) {
|
|
10
|
-
var flow = [
|
|
11
|
-
{ id: "n1", type: "antenna-genius-server", name: "test name", host: "localhost", port: 9007, disabledColor: "Black", activeColor: "Green", selectedColor: "Blue", autoConnect: false},
|
|
12
|
-
];
|
|
13
|
-
helper.load(serverNode, flow, function () {
|
|
14
|
-
var n1 = helper.getNode("n1");
|
|
15
|
-
n1.should.have.property('name', 'test name');
|
|
16
|
-
n1.should.have.property('host', 'localhost');
|
|
17
|
-
n1.should.have.property('port', 9007);
|
|
18
|
-
n1.should.have.property('disabledColor', 'Black');
|
|
19
|
-
n1.should.have.property('activeColor', 'Green');
|
|
20
|
-
n1.should.have.property('selectedColor', 'Blue');
|
|
21
|
-
n1.should.have.property('autoConnect', false);
|
|
22
|
-
done();
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|