gotty/js/spice-web-client/unittest/timelapsedetector.test.js
Soren L. Hansen c66ae7b2e4 First, primitive stab at SPiCE integration
Launch an Xspice and run:
echo -ne "\033]844;127.0.0.1;9876\007"

This will launch a SPiCE client connecting to 127.0.0.1:9876.

Still need to add all the security stuff and generally be
more defensive in the implementation.
2021-04-16 06:50:05 -07:00

55 lines
1.4 KiB
JavaScript

suite('TimeLapseDetector:', function () {
var sut;
var clock;
var now;
setup(function () {
wdi.Debug.debug = false; //disable debugging, it slows tests
now = Date.now();
clock = sinon.useFakeTimers(now);
sut = new wdi.TimeLapseDetector();
});
teardown(function () {
clock.restore();
});
test('when the timer is running normally, lastTime is updated', function () {
sut.startTimer();
clock.tick(wdi.TimeLapseDetector.defaultInterval);
var expected = now + wdi.TimeLapseDetector.defaultInterval;
assert.equal(expected, sut.getLastTime());
});
test('when the timer is running late an event is fired', function () {
sut.startTimer();
sut.setLastTime(now - (wdi.TimeLapseDetector.maxIntervalAllowed));
var expected = wdi.TimeLapseDetector.maxIntervalAllowed + wdi.TimeLapseDetector.defaultInterval;
var mock = sinon.mock(sut);
var expectation = mock.expects('fire')
.once()
.withExactArgs('timeLapseDetected', expected);
clock.tick(wdi.TimeLapseDetector.defaultInterval);
expectation.verify();
});
test('when the timer is running late, lastTime is updated', function () {
sut.startTimer();
var passedTime = wdi.TimeLapseDetector.maxIntervalAllowed + 123;
var expected = 0;
while (expected + wdi.TimeLapseDetector.defaultInterval <= passedTime) {
expected += wdi.TimeLapseDetector.defaultInterval;
}
expected += now;
clock.tick(passedTime);
assert.equal(expected, sut.getLastTime());
});
});