node-red-contrib-antenna-genius 0.1.0 → 0.2.2-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.
@@ -19,15 +19,9 @@
19
19
  "type": "node",
20
20
  "request": "launch",
21
21
  "name": "Mocha Tests",
22
- "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
22
+ "program": "${workspaceFolder}/node_modules/jest/bin/jest",
23
23
  "args": [
24
- "--reporter",
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
@@ -1,57 +1,61 @@
1
1
  # node-red-contrib-antenna-genius
2
2
  Antenna Genius Control and Monitoring Nodes
3
3
 
4
+ ![image](https://user-images.githubusercontent.com/7033002/148573983-00305f15-7acf-4d4d-bb1f-9c820c4b3a79.png) ![image](https://user-images.githubusercontent.com/7033002/148489672-9e2c03e0-a968-4c2f-9dc7-923c5423fad7.png)
5
+
6
+ ![image](https://user-images.githubusercontent.com/7033002/148574085-f0705a9c-7ac8-4ca0-b96a-ea7a14975d87.png)
7
+
4
8
  ## antenna-genius-band-labels
5
9
 
6
10
  Returns the current band labels for radio A and radio B.
7
11
 
8
12
  ### Properties
9
13
 
10
- `Server (antenna genius server)` select antenna genius server to use.
14
+ `Server (antenna genius server)`: select antenna genius server to use.
11
15
 
12
16
  ### Outputs
13
17
 
14
- `payload.bandLabelA (string)` is the current band for Radio A as a string. For example `12m`.
18
+ `payload.bandLabelA (string)`: is the current band for Radio A as a string. For example `12m`.
15
19
 
16
- `payload.bandLabelB (string)` is the current band for Radio B as a string. For example `10m`.
20
+ `payload.bandLabelB (string)`: is the current band for Radio B as a string. For example `10m`.
17
21
 
18
22
  ## antenna-genius-antenna-status
19
23
 
20
24
  ### Properties
21
25
 
22
- `Server (antenna genius server)` select antenna genius server to use.
26
+ `Server (antenna genius server)`: select antenna genius server to use.
23
27
 
24
- `Antenna Number (integer)` Antenna number to get status for. Valid values are from 1 up to 32 (8 for one, 16 for two, 24 for three and 32 for four interconnected Antenna Geniuses).
28
+ `Antenna Number (integer)`: Antenna number to get status for. Valid values are from 1 up to 32 (8 for one, 16 for two, 24 for three and 32 for four interconnected Antenna Geniuses).
25
29
 
26
30
  ### Outputs
27
31
 
28
32
  Port 1: Status for Radio A antenna.
29
33
 
30
- `payload.selected (boolean)` this is the currently selected antenna for Radio A on the current band.
34
+ `payload.selected (boolean)`: this is the currently selected antenna for Radio A on the current band.
31
35
 
32
- `payload.enabled (boolean)` this antenna can be selected for use by Radio A on the current band.
36
+ `payload.enabled (boolean)`: this antenna can be selected for use by Radio A on the current band.
33
37
 
34
- `payload.name (string )` the name of this antenna.
38
+ `payload.name (string )`: the name of this antenna.
35
39
 
36
- `payload.background (string)` the suggested background color for the current antenna state.
40
+ `payload.background (string)`: the suggested background color for the current antenna state.
37
41
 
38
- `enabled (boolean)` same as `payload.enabled`.
42
+ `enabled (boolean)`: same as `payload.enabled`.
39
43
 
40
- `topic (string)` string that can be used to ativate this antenna using the `activate-antenna` node.
44
+ `topic (string)`: string that can be used to activate this antenna using the `activate-antenna` node.
41
45
 
42
46
  Port 2: Status for Radio A antenna.
43
47
 
44
- `payload.selected (boolean)` this is the currently selected antenna for Radio B on the current band.
48
+ `payload.selected (boolean)`: this is the currently selected antenna for Radio B on the current band.
45
49
 
46
- `payload.enabled (boolean)` this antenna can be selected for use by Radio B on the current band.
50
+ `payload.enabled (boolean)`: this antenna can be selected for use by Radio B on the current band.
47
51
 
48
- `payload.name (string )` the name of this antenna.
52
+ `payload.name (string )`: the name of this antenna.
49
53
 
50
- `payload.background (string)` the suggested background color for the current antenna state.
54
+ `payload.background (string)`: the suggested background color for the current antenna state.
51
55
 
52
- `enabled (boolean)` same as `payload.enabled`.
56
+ `enabled (boolean)`: same as `payload.enabled`.
53
57
 
54
- `topic (string)` string that can be used to ativate this antenna using the `activate-antenna` node.
58
+ `topic (string)`: string that can be used to activate this antenna using the `activate-antenna` node.
55
59
 
56
60
  ### Details
57
61
 
@@ -63,15 +67,15 @@ Set the antenna defined in topic as active.
63
67
 
64
68
  ### Properties
65
69
 
66
- `Server (antenna genius server)` select antenna genius server to use.
70
+ `Server (antenna genius server)`: select antenna genius server to use.
67
71
 
68
72
  ### Inputs
69
73
 
70
- `topic (string)` Selection string for antenna. For example `"1;5"` for Radio A, antenna 5.
74
+ `topic (string)`: Selection string for antenna. For example `"1;5"` for Radio A, antenna 5.
71
75
 
72
76
  ### Details
73
77
 
74
- See the `antenna-status` node for more information.
78
+ See the `antenna-status`: node for more information.
75
79
 
76
80
  ## antenna-genius-server
77
81
 
@@ -79,18 +83,12 @@ Antenna Genius shared connection configuration.
79
83
 
80
84
  ### Configuration
81
85
 
82
- `Host (string)` Antenna Genius host name or IP address.
83
-
84
- `Port (integer)` Antenna Genius port number.
85
-
86
- `Disabled Background (string)` Background color to use for an antenna that is disabled.
87
-
88
- `Active Background (string)` Background color to use for an antenna that is active (e.g. can be selected).
89
-
90
- `Selected Background (string)` Background color to use for and antenna that is selected.
91
-
92
-
86
+ `Host (string)`: Antenna Genius host name or IP address.
93
87
 
88
+ `Port (integer)`: Antenna Genius port number.
94
89
 
90
+ `Disabled Background (string)`: Background color to use for an antenna that is disabled.
95
91
 
92
+ `Active Background (string)`: Background color to use for an antenna that is active (e.g. can be selected).
96
93
 
94
+ `Selected Background (string)`: Background color to use for and antenna that is selected.
@@ -11,15 +11,21 @@ module.exports = (RED) => {
11
11
  this.server = RED.nodes.getNode(config.server);
12
12
 
13
13
  this.server.updatesEventEmitter.on("connected", () => {
14
- this.status({ fill: "green", shape: "dot", text: this.server.info.name });
14
+ if(this.server.info.name) {
15
+ this.status({ fill: "green", shape: "dot", text: this.server.info.name });
16
+ }
15
17
  });
16
18
 
17
- this.server.client.on('close', () => {
19
+ this.server.updatesEventEmitter.on('closed', () => {
18
20
  this.status({ fill: "red", shape: "ring", text: "disconnected" });
19
21
  });
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);
@@ -31,6 +37,8 @@ module.exports = (RED) => {
31
37
  done();
32
38
  }
33
39
  });
40
+
41
+ this.server.connect();
34
42
  }
35
43
  }
36
44
  RED.nodes.registerType("antenna-genius-activate-antenna", AntennaGeniusActivateAntenna);
@@ -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 ativate this antenna using the `activate-antenna` node.
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 ativate this antenna using the `activate-antenna` node.
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,17 +20,19 @@ module.exports = (RED) => {
20
20
  this.server = RED.nodes.getNode(config.server);
21
21
 
22
22
  this.server.updatesEventEmitter.on("connected", () => {
23
- this.status({ fill: "green", shape: "dot", text: this.server.info.name });
23
+ if(this.server.info.name ) {
24
+ this.status({ fill: "green", shape: "dot", text: this.server.info.name });
25
+ }
24
26
  });
25
27
 
26
- this.server.client.on('close', () => {
28
+ this.server.updatesEventEmitter.on('closed', () => {
27
29
  this.status({ fill: "red", shape: "ring", text: "disconnected" });
28
30
  });
29
31
 
30
32
  this.server.updatesEventEmitter.on("status", () => {
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
  }
@@ -67,6 +69,7 @@ module.exports = (RED) => {
67
69
  if (this.radioA.name !== name) {
68
70
  changed = true;
69
71
  this.radioA.name = this.radioB.name = name;
72
+ this.status({ fill: "green", shape: "dot", text: this.server.info.name + " - " + name});
70
73
  }
71
74
 
72
75
  if (radioAenabled) {
@@ -100,6 +103,8 @@ module.exports = (RED) => {
100
103
  node.send([{ payload: this.radioA, enabled: this.radioA.enabled, topic: radioATopic }, { payload: this.radioB, enabled: this.radioB.enabled, topic: radioBTopic }]);
101
104
  }
102
105
  });
106
+
107
+ this.server.connect();
103
108
  }
104
109
  }
105
110
  RED.nodes.registerType("antenna-genius-antenna-status", AntennaGeniusAntennaStatus);
@@ -9,10 +9,12 @@ module.exports = (RED) => {
9
9
  this.server = RED.nodes.getNode(config.server);
10
10
 
11
11
  this.server.updatesEventEmitter.on("connected", () => {
12
- this.status({ fill: "green", shape: "dot", text: this.server.info.name });
12
+ if(this.server.info.name) {
13
+ this.status({ fill: "green", shape: "dot", text: this.server.info.name });
14
+ }
13
15
  });
14
16
 
15
- this.server.client.on('close', () => {
17
+ this.server.updatesEventEmitter.on('closed', () => {
16
18
  this.status({ fill: "red", shape: "ring", text: "disconnected" });
17
19
  });
18
20
 
@@ -20,6 +22,20 @@ module.exports = (RED) => {
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
 
@@ -34,8 +50,11 @@ module.exports = (RED) => {
34
50
  }
35
51
  if (changed) {
36
52
  node.send({ payload: { bandLabelA: bandNameA, bandLabelB: bandNameB } });
53
+ this.status({ fill: "green", shape: "dot", text: this.server.info.name + " - " + bandNameA + "/" + bandNameB });
37
54
  }
38
55
  });
56
+
57
+ this.server.connect();
39
58
  }
40
59
  }
41
60
  RED.nodes.registerType("antenna-genius-band-labels", AntennaGeniusBandLabels);
@@ -27,25 +27,31 @@ module.exports = (RED) => {
27
27
  this.updatesEventEmitter.setMaxListeners(0);
28
28
 
29
29
  this.client = new Net.Socket();
30
-
31
- this.client.setMaxListeners(0);
30
+ this.connected = false;
32
31
 
33
32
  this.client.on('close', () => {
34
33
  this.log('TCP connection disconnected with the server.');
35
34
  clearInterval(this.interval);
36
35
  clearTimeout(this.timer);
37
36
 
37
+ if(this.updatesEventEmitter.listenerCount('closed') == 0) {
38
+ this.log('Stop retrying. No nodes are refering this connection anymore.');
39
+ return;
40
+ }
41
+
38
42
  if(this.autoConnect) {
39
43
  this.log('TCP connection failed with the server. Will try to reconnect in 5 seconds');
40
44
  this.timer = setTimeout(() => {
41
45
  this.log('Reconnecting...');
42
- this.client.connect(this.port, this.host);
46
+ this.connect();
43
47
  }, 5000);
48
+ this.updatesEventEmitter.emit("closed");
44
49
  }
45
50
  });
46
51
 
47
52
  this.client.on('connect', async () => {
48
53
  this.log('TCP connection established with the server.');
54
+ this.connected = true;
49
55
 
50
56
  const promiseClient = new PromiseSocket(this.client);
51
57
 
@@ -86,6 +92,7 @@ module.exports = (RED) => {
86
92
  }
87
93
  });
88
94
 
95
+ // Poll status
89
96
  this.interval = setInterval(() => {
90
97
  let command = Utils.encode(0, 0, 401, 0, "");
91
98
  this.client.write(command);
@@ -102,17 +109,16 @@ module.exports = (RED) => {
102
109
  clearInterval(this.interval);
103
110
  clearTimeout(this.timer);
104
111
  this.autoConnect = false;
112
+ this.connected = false;
105
113
  this.client.end();
106
- this.log('Shutdown AG config node.');
107
114
  done();
108
115
  });
116
+ }
109
117
 
110
- if(this.autoConnect) {
118
+ connect() {
119
+ if(this.autoConnect && !this.connected & !this.client.connecting) {
111
120
  this.client.connect(this.port, this.host);
112
121
  }
113
- else {
114
- this.log('Autoconnect off');
115
- }
116
122
  }
117
123
  }
118
124
 
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "node-red-contrib-antenna-genius",
3
- "version": "0.1.0",
3
+ "version": "0.2.2-beta",
4
4
  "description": "Antenna Genius Control and Monitoring Nodes",
5
+ "keywords": [
6
+ "node-red"
7
+ ],
5
8
  "scripts": {
6
- "test": "mocha \"test/**/*_spec.js\"",
9
+ "test": "jest",
10
+ "watch": "jest --watch",
7
11
  "start": "node ./node_modules/node-red/red.js -v -u C:/Users/dahlj.GREATSTONE/.node-red ",
8
12
  "debug": "node --nolazy ./node_modules/node-red/red.js -v -u C:/Users/dahlj.GREATSTONE/.node-red"
9
13
  },
@@ -30,8 +34,11 @@
30
34
  "promise-socket": "^7.0.0"
31
35
  },
32
36
  "devDependencies": {
33
- "mocha": "^9.1.3",
37
+ "jest": "^27.4.7",
34
38
  "node-red": "^2.1.4",
35
39
  "node-red-node-test-helper": "^0.2.7"
40
+ },
41
+ "jest": {
42
+ "verbose": true
36
43
  }
37
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");
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");
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");
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");
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");
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
- });