Skip to content

Commit

Permalink
add test and change col-lg
Browse files Browse the repository at this point in the history
  • Loading branch information
William-De71 committed Nov 8, 2024
1 parent b8be775 commit 78a0240
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion front/src/routes/scene/edit-scene/ActionCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const ActionCard = ({ children, ...props }) => {
'col-lg-6':
props.action.type === ACTIONS.MESSAGE.SEND ||
props.action.type === ACTIONS.CALENDAR.IS_EVENT_RUNNING ||
props.action.type === ACTIONS.MQTT.SEND ||
props.action.type === ACTIONS.MQTT.SEND || ACTIONS.ZIGBEE2MQTT.SEND ||
props.action.type === ACTIONS.LIGHT.BLINK,
'col-lg-4':
props.action.type !== ACTIONS.CONDITION.ONLY_CONTINUE_IF &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const { fake, assert } = require('sinon');
const EventEmitter = require('events');

const { ACTIONS } = require('../../../../utils/constants');
const { executeActions } = require('../../../../lib/scene/scene.executeActions');

const StateManager = require('../../../../lib/state');

const event = new EventEmitter();

describe('scene.send-zigbee2mqtt-message', () => {
it('should send message with value injected from device get-value', async () => {
const stateManager = new StateManager(event);
stateManager.setState('deviceFeature', 'my-device-feature', {
category: 'light',
type: 'binary',
last_value: 15,
});
const zigbee2MqttService = {
device: {
publish: fake.resolves(null),
},
};
const service = {
getService: fake.returns(zigbee2MqttService),
};
const scope = {};
await executeActions(
{ stateManager, event, service },
[
[
{
type: ACTIONS.DEVICE.GET_VALUE,
device_feature: 'my-device-feature',
},
],
[
{
type: ACTIONS.ZIGBEE2MQTT.SEND,
topic: '/my/mqtt/topic',
message: 'Temperature in the living room is {{0.0.last_value}} °C.',
},
],
],
scope,
);
assert.calledWith(zigbee2MqttService.device.publish, '/my/mqtt/topic', 'Temperature in the living room is 15 °C.');
});
it('should send message with value injected from http-request', async () => {
const stateManager = new StateManager(event);
const http = {
request: fake.resolves({ result: [15], error: null }),
};
const zigbee2MqttService = {
device: {
publish: fake.resolves(null),
},
};
const service = {
getService: fake.returns(zigbee2MqttService),
};
const scope = {};
await executeActions(
{ stateManager, event, service, http },
[
[
{
type: ACTIONS.HTTP.REQUEST,
method: 'post',
url: 'http://test.test',
body: '{"toto":"toto"}',
headers: [],
},
],
[
{
type: ACTIONS.ZIGBEE2MQTT.SEND,
topic: '/my/mqtt/topic',
message: 'Temperature in the living room is {{0.0.result.[0]}} °C.',
},
],
],
scope,
);
assert.calledWith(zigbee2MqttService.device.publish, '/my/mqtt/topic', 'Temperature in the living room is 15 °C.');
});
});

0 comments on commit 78a0240

Please sign in to comment.