2017-04-20 19:17:05 -04:00
|
|
|
const test = require('tap').test;
|
|
|
|
const Mouse = require('../../src/io/mouse');
|
|
|
|
const Runtime = require('../../src/engine/runtime');
|
2016-10-24 11:56:52 -04:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('spec', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const m = new Mouse(rt);
|
2016-10-24 11:56:52 -04:00
|
|
|
|
|
|
|
t.type(m, 'object');
|
|
|
|
t.type(m.postData, 'function');
|
|
|
|
t.type(m.getX, 'function');
|
|
|
|
t.type(m.getY, 'function');
|
2018-01-09 09:39:52 -05:00
|
|
|
t.type(m.getClampedX, 'function');
|
|
|
|
t.type(m.getClampedY, 'function');
|
2016-10-24 11:56:52 -04:00
|
|
|
t.type(m.getIsDown, 'function');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('mouseUp', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const m = new Mouse(rt);
|
2016-10-24 11:56:52 -04:00
|
|
|
|
|
|
|
m.postData({
|
2018-01-09 09:39:52 -05:00
|
|
|
x: -20,
|
2016-10-24 11:56:52 -04:00
|
|
|
y: 10,
|
|
|
|
isDown: false,
|
|
|
|
canvasWidth: 480,
|
|
|
|
canvasHeight: 360
|
|
|
|
});
|
2018-01-09 09:39:52 -05:00
|
|
|
t.strictEquals(m.getX(), -260);
|
2016-10-24 11:56:52 -04:00
|
|
|
t.strictEquals(m.getY(), 170);
|
2018-01-09 09:39:52 -05:00
|
|
|
t.strictEquals(m.getClampedX(), -240);
|
|
|
|
t.strictEquals(m.getClampedY(), 170);
|
2016-10-24 11:56:52 -04:00
|
|
|
t.strictEquals(m.getIsDown(), false);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('mouseDown', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const m = new Mouse(rt);
|
2016-10-24 11:56:52 -04:00
|
|
|
|
|
|
|
m.postData({
|
|
|
|
x: 10,
|
2018-01-09 09:39:52 -05:00
|
|
|
y: 400,
|
2016-10-24 11:56:52 -04:00
|
|
|
isDown: true,
|
|
|
|
canvasWidth: 480,
|
|
|
|
canvasHeight: 360
|
|
|
|
});
|
|
|
|
t.strictEquals(m.getX(), -230);
|
2018-01-09 09:39:52 -05:00
|
|
|
t.strictEquals(m.getY(), -220);
|
|
|
|
t.strictEquals(m.getClampedX(), -230);
|
|
|
|
t.strictEquals(m.getClampedY(), -180);
|
2016-10-24 11:56:52 -04:00
|
|
|
t.strictEquals(m.getIsDown(), true);
|
|
|
|
t.end();
|
|
|
|
});
|