diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..1a9402a --- /dev/null +++ b/examples/README.md @@ -0,0 +1,8 @@ +# dashboardAPI Example Flows + +Import-ready Node-RED examples for dashboardAPI. + +## Files +- basic.flow.json +- integration.flow.json +- edge.flow.json diff --git a/examples/basic.flow.json b/examples/basic.flow.json new file mode 100644 index 0000000..bd4ff4c --- /dev/null +++ b/examples/basic.flow.json @@ -0,0 +1,6 @@ +[ + {"id":"dashboardAPI_basic_tab","type":"tab","label":"dashboardAPI basic","disabled":false,"info":"dashboardAPI basic example"}, + {"id":"dashboardAPI_basic_node","type":"dashboardapi","z":"dashboardAPI_basic_tab","name":"dashboardAPI basic","x":420,"y":180,"wires":[["dashboardAPI_basic_dbg"]]}, + {"id":"dashboardAPI_basic_inj","type":"inject","z":"dashboardAPI_basic_tab","name":"basic trigger","props":[{"p":"topic","vt":"str"},{"p":"payload","vt":"str"}],"topic":"ping","payload":"1","payloadType":"str","x":160,"y":180,"wires":[["dashboardAPI_basic_node"]]}, + {"id":"dashboardAPI_basic_dbg","type":"debug","z":"dashboardAPI_basic_tab","name":"dashboardAPI basic debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":660,"y":180,"wires":[]} +] diff --git a/examples/edge.flow.json b/examples/edge.flow.json new file mode 100644 index 0000000..7be6703 --- /dev/null +++ b/examples/edge.flow.json @@ -0,0 +1,6 @@ +[ + {"id":"dashboardAPI_edge_tab","type":"tab","label":"dashboardAPI edge","disabled":false,"info":"dashboardAPI edge example"}, + {"id":"dashboardAPI_edge_node","type":"dashboardapi","z":"dashboardAPI_edge_tab","name":"dashboardAPI edge","x":420,"y":180,"wires":[["dashboardAPI_edge_dbg"]]}, + {"id":"dashboardAPI_edge_inj","type":"inject","z":"dashboardAPI_edge_tab","name":"unknown topic","props":[{"p":"topic","vt":"str"},{"p":"payload","vt":"str"}],"topic":"doesNotExist","payload":"x","payloadType":"str","x":170,"y":180,"wires":[["dashboardAPI_edge_node"]]}, + {"id":"dashboardAPI_edge_dbg","type":"debug","z":"dashboardAPI_edge_tab","name":"dashboardAPI edge debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":660,"y":180,"wires":[]} +] diff --git a/examples/integration.flow.json b/examples/integration.flow.json new file mode 100644 index 0000000..8f5ca86 --- /dev/null +++ b/examples/integration.flow.json @@ -0,0 +1,6 @@ +[ + {"id":"dashboardAPI_int_tab","type":"tab","label":"dashboardAPI integration","disabled":false,"info":"dashboardAPI integration example"}, + {"id":"dashboardAPI_int_node","type":"dashboardapi","z":"dashboardAPI_int_tab","name":"dashboardAPI integration","x":420,"y":180,"wires":[["dashboardAPI_int_dbg"]]}, + {"id":"dashboardAPI_int_inj","type":"inject","z":"dashboardAPI_int_tab","name":"registerChild","props":[{"p":"topic","vt":"str"},{"p":"payload","vt":"str"}],"topic":"registerChild","payload":"example-child-id","payloadType":"str","x":170,"y":180,"wires":[["dashboardAPI_int_node"]]}, + {"id":"dashboardAPI_int_dbg","type":"debug","z":"dashboardAPI_int_tab","name":"dashboardAPI integration debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":680,"y":180,"wires":[]} +] diff --git a/package.json b/package.json index b914aab..879465b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "EVOLV Grafana dashboard generator (Node-RED node).", "main": "dashboardapi.js", "scripts": { - "test": "node --test test/*.test.js" + "test": "node --test test/basic/*.test.js test/integration/*.test.js test/edge/*.test.js" }, "keywords": [ "dashboard", @@ -23,4 +23,3 @@ } } } - diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000..f9cedf3 --- /dev/null +++ b/test/README.md @@ -0,0 +1,12 @@ +# dashboardAPI Test Suite Layout + +Required EVOLV layout: +- basic/ +- integration/ +- edge/ +- helpers/ + +Baseline structure tests: +- basic/structure-module-load.basic.test.js +- integration/structure-examples.integration.test.js +- edge/structure-examples-node-type.edge.test.js diff --git a/test/basic/.gitkeep b/test/basic/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/basic/structure-module-load.basic.test.js b/test/basic/structure-module-load.basic.test.js new file mode 100644 index 0000000..dde1c59 --- /dev/null +++ b/test/basic/structure-module-load.basic.test.js @@ -0,0 +1,8 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); + +test('dashboardAPI module load smoke', () => { + assert.doesNotThrow(() => { + require('../../dashboardapi.js'); + }); +}); diff --git a/test/edge/.gitkeep b/test/edge/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/edge/structure-examples-node-type.edge.test.js b/test/edge/structure-examples-node-type.edge.test.js new file mode 100644 index 0000000..d90c297 --- /dev/null +++ b/test/edge/structure-examples-node-type.edge.test.js @@ -0,0 +1,11 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); + +const flow = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../examples/basic.flow.json'), 'utf8')); + +test('basic example includes node type dashboardapi', () => { + const count = flow.filter((n) => n && n.type === 'dashboardapi').length; + assert.equal(count >= 1, true); +}); diff --git a/test/helpers/.gitkeep b/test/helpers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/integration/.gitkeep b/test/integration/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/integration/structure-examples.integration.test.js b/test/integration/structure-examples.integration.test.js new file mode 100644 index 0000000..5918e79 --- /dev/null +++ b/test/integration/structure-examples.integration.test.js @@ -0,0 +1,23 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); + +const dir = path.resolve(__dirname, '../../examples'); + +function loadJson(file) { + return JSON.parse(fs.readFileSync(path.join(dir, file), 'utf8')); +} + +test('examples package exists for dashboardAPI', () => { + for (const file of ['README.md', 'basic.flow.json', 'integration.flow.json', 'edge.flow.json']) { + assert.equal(fs.existsSync(path.join(dir, file)), true, file + ' missing'); + } +}); + +test('example flows are parseable arrays for dashboardAPI', () => { + for (const file of ['basic.flow.json', 'integration.flow.json', 'edge.flow.json']) { + const parsed = loadJson(file); + assert.equal(Array.isArray(parsed), true); + } +});