mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
const test = require('tap').test;
|
|
const Runtime = require('../../src/engine/runtime');
|
|
const MonitorRecord = require('../../src/engine/records');
|
|
const {Map} = require('immutable');
|
|
|
|
test('spec', t => {
|
|
const r = new Runtime();
|
|
|
|
t.type(Runtime, 'function');
|
|
t.type(r, 'object');
|
|
t.ok(r instanceof Runtime);
|
|
|
|
t.end();
|
|
});
|
|
|
|
test('monitorStateEquals', t => {
|
|
const r = new Runtime();
|
|
const id = 'xklj4#!';
|
|
const prevMonitorState = MonitorRecord({
|
|
id,
|
|
category: 'data',
|
|
label: 'turtle whereabouts',
|
|
value: '25',
|
|
x: 0,
|
|
y: 0
|
|
});
|
|
const newMonitorDelta = Map({
|
|
id,
|
|
value: String(25)
|
|
});
|
|
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'));
|
|
t.end();
|
|
});
|
|
|
|
test('monitorStateDoesNotEqual', t => {
|
|
const r = new Runtime();
|
|
const id = 'xklj4#!';
|
|
const prevMonitorState = MonitorRecord({
|
|
id,
|
|
category: 'data',
|
|
label: 'turtle whereabouts',
|
|
value: '25'
|
|
});
|
|
|
|
// Value change
|
|
let newMonitorDelta = Map({
|
|
id,
|
|
value: String(24)
|
|
});
|
|
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'));
|
|
|
|
// Prop change
|
|
newMonitorDelta = Map({
|
|
id: 'xklj4#!',
|
|
x: 7
|
|
});
|
|
r.requestUpdateMonitor(newMonitorDelta);
|
|
|
|
t.equals(false, prevMonitorState.equals(r._monitorState.get(id)));
|
|
t.equals(String(24), r._monitorState.get(id).get('value'));
|
|
t.equals(7, r._monitorState.get(id).get('x'));
|
|
|
|
t.end();
|
|
});
|