|
| 1 | +import {test} from '../../../util/test'; |
| 2 | +import window from '../../../../src/util/window'; |
| 3 | +import Map from '../../../../src/ui/map'; |
| 4 | +import DOM from '../../../../src/util/dom'; |
| 5 | +import simulate from '../../../util/simulate_interaction'; |
| 6 | + |
| 7 | +function createMap(t) { |
| 8 | + t.stub(Map.prototype, '_detectMissingCSS'); |
| 9 | + return new Map({interactive: false, container: DOM.create('div', '', window.document.body)}); |
| 10 | +} |
| 11 | + |
| 12 | +test('MapEvent handler fires touch events with correct values', (t) => { |
| 13 | + const map = createMap(t); |
| 14 | + |
| 15 | + const touchstart = t.spy(); |
| 16 | + const touchmove = t.spy(); |
| 17 | + const touchend = t.spy(); |
| 18 | + |
| 19 | + map.on('touchstart', touchstart); |
| 20 | + map.on('touchmove', touchmove); |
| 21 | + map.on('touchend', touchend); |
| 22 | + |
| 23 | + const touchesStart = [{identifier: 1, clientX: 0, clientY: 50}]; |
| 24 | + const touchesMove = [{identifier: 1, clientX: 0, clientY: 60}]; |
| 25 | + const touchesEnd = [{identifier: 1, clientX: 0, clientY: 60}]; |
| 26 | + |
| 27 | + simulate.touchstart(map.getCanvas(), {touches: touchesStart, targetTouches: touchesStart}); |
| 28 | + t.equal(touchstart.callCount, 1); |
| 29 | + t.deepEqual(touchstart.getCall(0).args[0].point, {x: 0, y: 50}); |
| 30 | + t.equal(touchmove.callCount, 0); |
| 31 | + t.equal(touchend.callCount, 0); |
| 32 | + console.log(touchstart); |
| 33 | + |
| 34 | + simulate.touchmove(map.getCanvas(), {touches: touchesMove, targetTouches: touchesMove}); |
| 35 | + t.equal(touchstart.callCount, 1); |
| 36 | + t.equal(touchmove.callCount, 1); |
| 37 | + t.deepEqual(touchmove.getCall(0).args[0].point, {x: 0, y: 60}); |
| 38 | + t.equal(touchend.callCount, 0); |
| 39 | + |
| 40 | + simulate.touchend(map.getCanvas(), {touches: [], targetTouches: [], changedTouches: touchesEnd}); |
| 41 | + t.equal(touchstart.callCount, 1); |
| 42 | + t.equal(touchmove.callCount, 1); |
| 43 | + t.equal(touchend.callCount, 1); |
| 44 | + t.deepEqual(touchend.getCall(0).args[0].point, {x: 0, y: 60}); |
| 45 | + |
| 46 | + map.remove(); |
| 47 | + t.end(); |
| 48 | +}); |
0 commit comments