From d0027fcfcad71723fb23dfb949a59ae59d593faf Mon Sep 17 00:00:00 2001 From: Joe Pavitt Date: Tue, 24 Oct 2023 17:25:48 +0100 Subject: [PATCH] Fix tests after we no loner use node._msg --- nodes/config/ui_base.js | 8 ++++++++ test/nodes/widgets/ui_button.spec.js | 1 - test/nodes/widgets/ui_dropdown.spec.js | 2 +- test/nodes/widgets/ui_slider.spec.js | 2 +- test/nodes/widgets/ui_switch.spec.js | 7 +++---- test/nodes/widgets/ui_text_input.spec.js | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/nodes/config/ui_base.js b/nodes/config/ui_base.js index be062aba4..cf5cefc1e 100644 --- a/nodes/config/ui_base.js +++ b/nodes/config/ui_base.js @@ -568,6 +568,14 @@ module.exports = function (RED) { node.ui.widgets.set(widget.id, widget) } + /** + * Helper Function for testing + */ + + widgetNode.getState = function () { + return datastore.get(widgetNode.id) + } + /** * Event Handlers */ diff --git a/test/nodes/widgets/ui_button.spec.js b/test/nodes/widgets/ui_button.spec.js index 685689bf8..0756aa11f 100644 --- a/test/nodes/widgets/ui_button.spec.js +++ b/test/nodes/widgets/ui_button.spec.js @@ -106,7 +106,6 @@ describe('ui-button node', function () { // add a fake connection so that button has somewhere to emit to and we can spy on it base.uiShared.connections['fake-conn-id'] = socket - base.connections['fake-conn-id'] = socket // now send a message to the node const button = helper.getNode('node-ui-button') diff --git a/test/nodes/widgets/ui_dropdown.spec.js b/test/nodes/widgets/ui_dropdown.spec.js index e66947d97..0f11c8530 100644 --- a/test/nodes/widgets/ui_dropdown.spec.js +++ b/test/nodes/widgets/ui_dropdown.spec.js @@ -131,7 +131,7 @@ describe('ui-dropdown node', function () { const helperAfterComplete = helper.getNode('helper-node-complete') helperAfterComplete.on('input', (msg) => { try { - dNode._msg.payload.should.equal(msg.payload) + dNode.getState().payload.should.equal(msg.payload) msgSent.should.be.false() resolve() } catch (err) { diff --git a/test/nodes/widgets/ui_slider.spec.js b/test/nodes/widgets/ui_slider.spec.js index 155428929..eb009a511 100644 --- a/test/nodes/widgets/ui_slider.spec.js +++ b/test/nodes/widgets/ui_slider.spec.js @@ -121,7 +121,7 @@ describe('ui-slider node', function () { const helperAfterComplete = helper.getNode('helper-node-complete') helperAfterComplete.on('input', (msg) => { try { - sNode._msg.payload.should.equal(msg.payload) + sNode.getState().payload.should.equal(msg.payload) msgSent.should.be.false() resolve() } catch (err) { diff --git a/test/nodes/widgets/ui_switch.spec.js b/test/nodes/widgets/ui_switch.spec.js index 88a361ceb..240b9fe45 100644 --- a/test/nodes/widgets/ui_switch.spec.js +++ b/test/nodes/widgets/ui_switch.spec.js @@ -117,7 +117,7 @@ describe('ui-switch node', function () { const hNode = helper.getNode('helper-node') hNode.on('input', (msg) => { try { - sNode._msg.payload.should.equal(msg.payload) + sNode.getState().payload.should.equal(msg.payload) resolve() } catch (err) { reject(err) @@ -141,7 +141,7 @@ describe('ui-switch node', function () { // we need to be sure that the helperAfterSwitch node has run first setTimeout(() => { try { - sNode._msg.payload.should.equal(msg.payload) + sNode.getState().payload.should.equal(msg.payload) msgSent.should.be.true() resolve() } catch (err) { @@ -173,7 +173,6 @@ describe('ui-switch node', function () { // we need to be sure that the helperAfterSwitch node has run first setTimeout(() => { try { - (sNode._msg === undefined).should.be.true() sNode.warn.should.be.called() msgSent.should.be.false() resolve() @@ -211,7 +210,7 @@ describe('ui-switch node', function () { const helperAfterComplete = helper.getNode('helper-node-complete') helperAfterComplete.on('input', (msg) => { try { - sNode._msg.payload.should.equal(msg.payload) + sNode.getState().payload.should.equal(msg.payload) msgSent.should.be.false() resolve() } catch (err) { diff --git a/test/nodes/widgets/ui_text_input.spec.js b/test/nodes/widgets/ui_text_input.spec.js index 6a9ad45e3..2933bd86d 100644 --- a/test/nodes/widgets/ui_text_input.spec.js +++ b/test/nodes/widgets/ui_text_input.spec.js @@ -114,7 +114,7 @@ describe('ui-text-input node', function () { const helperAfterComplete = helper.getNode('helper-node-complete') helperAfterComplete.on('input', (msg) => { try { - tNode._msg.payload.should.equal(msg.payload) + tNode.getState().payload.should.equal(msg.payload) msgSent.should.be.false() resolve() } catch (err) {