2017-04-20 19:17:05 -04:00
|
|
|
const test = require('tap').test;
|
|
|
|
const Runtime = require('../../src/engine/runtime');
|
2017-05-24 15:42:29 -04:00
|
|
|
const MonitorRecord = require('../../src/engine/records');
|
2017-05-19 17:28:00 -04:00
|
|
|
const {Map} = require('immutable');
|
2016-04-18 17:20:30 -04:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('spec', t => {
|
|
|
|
const r = new Runtime();
|
2016-04-18 17:20:30 -04:00
|
|
|
|
|
|
|
t.type(Runtime, 'function');
|
|
|
|
t.type(r, 'object');
|
|
|
|
t.ok(r instanceof Runtime);
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
2017-05-19 12:28:05 -04:00
|
|
|
|
2017-05-19 17:28:00 -04:00
|
|
|
test('monitorStateEquals', t => {
|
2017-05-19 12:28:05 -04:00
|
|
|
const r = new Runtime();
|
2017-05-19 17:28:00 -04:00
|
|
|
const id = 'xklj4#!';
|
2017-05-24 15:42:29 -04:00
|
|
|
const prevMonitorState = MonitorRecord({
|
2017-05-19 17:28:00 -04:00
|
|
|
id,
|
2017-05-19 12:28:05 -04:00
|
|
|
category: 'data',
|
|
|
|
label: 'turtle whereabouts',
|
|
|
|
value: '25',
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
2017-05-19 17:28:00 -04:00
|
|
|
});
|
|
|
|
const newMonitorDelta = Map({
|
|
|
|
id,
|
2017-05-19 12:28:05 -04:00
|
|
|
value: String(25)
|
2017-05-19 17:28:00 -04:00
|
|
|
});
|
|
|
|
r.requestAddMonitor(prevMonitorState);
|
|
|
|
r.requestUpdateMonitor(newMonitorDelta);
|
|
|
|
|
|
|
|
t.equals(true, prevMonitorState.equals(r._monitorState.get(id)));
|
|
|
|
t.equals(String(25), r._monitorState.get(id).get('value'));
|
2017-05-19 12:28:05 -04:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-05-19 17:28:00 -04:00
|
|
|
test('monitorStateDoesNotEqual', t => {
|
2017-05-19 12:28:05 -04:00
|
|
|
const r = new Runtime();
|
2017-05-19 17:28:00 -04:00
|
|
|
const id = 'xklj4#!';
|
2017-05-24 15:42:29 -04:00
|
|
|
const prevMonitorState = MonitorRecord({
|
2017-05-19 17:28:00 -04:00
|
|
|
id,
|
2017-05-19 12:28:05 -04:00
|
|
|
category: 'data',
|
|
|
|
label: 'turtle whereabouts',
|
2017-05-24 15:42:29 -04:00
|
|
|
value: '25'
|
2017-05-19 17:28:00 -04:00
|
|
|
});
|
2017-05-19 12:28:05 -04:00
|
|
|
|
|
|
|
// Value change
|
2017-05-19 17:28:00 -04:00
|
|
|
let newMonitorDelta = Map({
|
|
|
|
id,
|
2017-05-19 12:28:05 -04:00
|
|
|
value: String(24)
|
2017-05-19 17:28:00 -04:00
|
|
|
});
|
|
|
|
r.requestAddMonitor(prevMonitorState);
|
|
|
|
r.requestUpdateMonitor(newMonitorDelta);
|
|
|
|
|
|
|
|
t.equals(false, prevMonitorState.equals(r._monitorState.get(id)));
|
|
|
|
t.equals(String(24), r._monitorState.get(id).get('value'));
|
2017-05-19 12:28:05 -04:00
|
|
|
|
|
|
|
// Prop change
|
2017-05-19 17:28:00 -04:00
|
|
|
newMonitorDelta = Map({
|
2017-05-19 12:28:05 -04:00
|
|
|
id: 'xklj4#!',
|
2017-05-24 15:42:29 -04:00
|
|
|
x: 7
|
2017-05-19 17:28:00 -04:00
|
|
|
});
|
|
|
|
r.requestUpdateMonitor(newMonitorDelta);
|
|
|
|
|
|
|
|
t.equals(false, prevMonitorState.equals(r._monitorState.get(id)));
|
|
|
|
t.equals(String(24), r._monitorState.get(id).get('value'));
|
2017-05-24 15:42:29 -04:00
|
|
|
t.equals(7, r._monitorState.get(id).get('x'));
|
2017-05-19 12:28:05 -04:00
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|