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');
|
2018-01-09 10:36:03 -05:00
|
|
|
t.type(m.getClientX, 'function');
|
|
|
|
t.type(m.getClientY, 'function');
|
|
|
|
t.type(m.getScratchX, 'function');
|
|
|
|
t.type(m.getScratchY, '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 10:36:03 -05:00
|
|
|
t.strictEquals(m.getClientX(), -20);
|
|
|
|
t.strictEquals(m.getClientY(), 10);
|
|
|
|
t.strictEquals(m.getScratchX(), -240);
|
|
|
|
t.strictEquals(m.getScratchY(), 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
|
|
|
|
});
|
2018-01-09 10:36:03 -05:00
|
|
|
t.strictEquals(m.getClientX(), 10);
|
|
|
|
t.strictEquals(m.getClientY(), 400);
|
|
|
|
t.strictEquals(m.getScratchX(), -230);
|
|
|
|
t.strictEquals(m.getScratchY(), -180);
|
2016-10-24 11:56:52 -04:00
|
|
|
t.strictEquals(m.getIsDown(), true);
|
|
|
|
t.end();
|
|
|
|
});
|
2018-01-09 10:36:03 -05:00
|
|
|
|
|
|
|
test('at zoomed scale', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const m = new Mouse(rt);
|
|
|
|
|
|
|
|
m.postData({
|
|
|
|
x: 240,
|
|
|
|
y: 540,
|
|
|
|
canvasWidth: 960,
|
|
|
|
canvasHeight: 720
|
|
|
|
});
|
|
|
|
t.strictEquals(m.getClientX(), 240);
|
|
|
|
t.strictEquals(m.getClientY(), 540);
|
|
|
|
t.strictEquals(m.getScratchX(), -120);
|
|
|
|
t.strictEquals(m.getScratchY(), -90);
|
|
|
|
t.end();
|
|
|
|
});
|