diff --git a/package-lock.json b/package-lock.json index ebf1b6bad79..a984cea3427 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "bundlemon": "^2.0.0", "eslint": "^8.23.1", "eslint-config-mourner": "^3.0.0", - "happen": "~0.3.2", "husky": "^8.0.1", "karma": "^6.4.1", "karma-chrome-launcher": "^3.1.1", @@ -34,7 +33,8 @@ "simple-git": "^3.14.1", "sinon": "^15.0.0", "ssri": "^10.0.0", - "uglify-js": "^3.17.1" + "uglify-js": "^3.17.1", + "ui-event-simulator": "^1.0.0" } }, "node_modules/@babel/code-frame": { @@ -1925,12 +1925,6 @@ "uglify-js": "^3.1.4" } }, - "node_modules/happen": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/happen/-/happen-0.3.2.tgz", - "integrity": "sha512-fBouIWb3fMsRCfCySHgk6+/gTEijMAWUZM/TYKmjuui9VsdS2DGWNjcH9cN7/tPn9nSkxGSGLJU6FHh37G0WUg==", - "dev": true - }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -4326,6 +4320,12 @@ "node": ">=0.8.0" } }, + "node_modules/ui-event-simulator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ui-event-simulator/-/ui-event-simulator-1.0.0.tgz", + "integrity": "sha512-qNsfbIMkpMWPHrQu6UKDzoA29nEnyCeN/Wrak75lQOjZHzh4nsEUyZkbgyHEFeqRWkNATfFMHduIkKBN1hVAIA==", + "dev": true + }, "node_modules/universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -6092,12 +6092,6 @@ "wordwrap": "^1.0.0" } }, - "happen": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/happen/-/happen-0.3.2.tgz", - "integrity": "sha512-fBouIWb3fMsRCfCySHgk6+/gTEijMAWUZM/TYKmjuui9VsdS2DGWNjcH9cN7/tPn9nSkxGSGLJU6FHh37G0WUg==", - "dev": true - }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -7868,6 +7862,12 @@ "integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==", "dev": true }, + "ui-event-simulator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ui-event-simulator/-/ui-event-simulator-1.0.0.tgz", + "integrity": "sha512-qNsfbIMkpMWPHrQu6UKDzoA29nEnyCeN/Wrak75lQOjZHzh4nsEUyZkbgyHEFeqRWkNATfFMHduIkKBN1hVAIA==", + "dev": true + }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", diff --git a/package.json b/package.json index ce4229a9a5d..23b5efff855 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "bundlemon": "^2.0.0", "eslint": "^8.23.1", "eslint-config-mourner": "^3.0.0", - "happen": "~0.3.2", "husky": "^8.0.1", "karma": "^6.4.1", "karma-chrome-launcher": "^3.1.1", @@ -29,7 +28,8 @@ "simple-git": "^3.14.1", "sinon": "^15.0.0", "ssri": "^10.0.0", - "uglify-js": "^3.17.1" + "uglify-js": "^3.17.1", + "ui-event-simulator": "^1.0.0" }, "main": "dist/leaflet-src.js", "module": "dist/leaflet-src.esm.js", diff --git a/spec/.eslintrc.js b/spec/.eslintrc.js index 211c8ce7a24..2007ac7858c 100644 --- a/spec/.eslintrc.js +++ b/spec/.eslintrc.js @@ -10,7 +10,7 @@ module.exports = { L: true, expect: false, sinon: false, - happen: false, + UIEventSimulator: false, Hand: false, touchEventType: false, /* defined in SpecHelper.js */ createContainer: false, /* defined in SpecHelper.js */ diff --git a/spec/index.html b/spec/index.html index c94d95e6efb..07b29792821 100644 --- a/spec/index.html +++ b/spec/index.html @@ -11,7 +11,7 @@
- + diff --git a/spec/karma.conf.js b/spec/karma.conf.js index 1a85f61382a..a7097e43c2b 100644 --- a/spec/karma.conf.js +++ b/spec/karma.conf.js @@ -9,7 +9,7 @@ module.exports = function (config) { 'spec/before.js', 'src/LeafletWithGlobals.js', 'spec/after.js', - 'node_modules/happen/happen.js', + 'node_modules/ui-event-simulator/ui-event-simulator.js', 'node_modules/prosthetic-hand/dist/prosthetic-hand.js', 'spec/suites/SpecHelper.js', 'spec/suites/**/*.js', diff --git a/spec/suites/SpecHelper.js b/spec/suites/SpecHelper.js index 6ca73d40bb5..5386d2e8e5e 100644 --- a/spec/suites/SpecHelper.js +++ b/spec/suites/SpecHelper.js @@ -16,32 +16,6 @@ expect.Assertion.prototype.nearLatLng = function (expected, delta) { .be.within(expected.lng - delta, expected.lng + delta); }; -happen.at = function (what, x, y, props) { - this.once(document.elementFromPoint(x, y), L.Util.extend({ - type: what, - clientX: x, - clientY: y, - screenX: x, - screenY: y, - which: 1, - button: 0 - }, props || {})); -}; - -happen.makeEvent = (function (makeEvent) { - return function (o) { - const evt = makeEvent(o); - if (o.type.substring(0, 7) === 'pointer') { - evt.pointerId = o.pointerId; - evt.pointerType = o.pointerType; - } else if (o.type.includes('wheel')) { - evt.deltaY = evt.deltaY || o.deltaY; - evt.deltaMode = evt.deltaMode || o.deltaMode; - } - return evt; - }; -})(happen.makeEvent); - // A couple of tests need the browser to be touch-capable it.skipIfNotTouch = L.Browser.touch ? it : it.skip; diff --git a/spec/suites/control/Control.LayersSpec.js b/spec/suites/control/Control.LayersSpec.js index 30e0dff192a..986f8a0714a 100644 --- a/spec/suites/control/Control.LayersSpec.js +++ b/spec/suites/control/Control.LayersSpec.js @@ -19,11 +19,11 @@ describe('Control.Layers', () => { spy = sinon.spy(); map.on('baselayerchange', spy); - happen.click(layers._baseLayersList.getElementsByTagName('input')[0]); + UIEventSimulator.fire('click', layers._baseLayersList.getElementsByTagName('input')[0]); expect(spy.called).to.be.ok(); expect(spy.args[0][0].name).to.be('Layer 1'); expect(spy.args[0][0].layer).to.be(baseLayers['Layer 1']); - happen.click(layers._baseLayersList.getElementsByTagName('input')[1]); + UIEventSimulator.fire('click', layers._baseLayersList.getElementsByTagName('input')[1]); expect(spy.calledTwice).to.be.ok(); expect(spy.args[1][0].name).to.be('Layer 2'); expect(spy.args[1][0].layer).to.be(baseLayers['Layer 2']); @@ -39,11 +39,11 @@ describe('Control.Layers', () => { map.removeControl(layers); map.addControl(layers); - happen.click(layers._baseLayersList.getElementsByTagName('input')[0]); + UIEventSimulator.fire('click', layers._baseLayersList.getElementsByTagName('input')[0]); expect(spy.called).to.be.ok(); expect(spy.args[0][0].name).to.be('Layer 1'); expect(spy.args[0][0].layer).to.be(baseLayers['Layer 1']); - happen.click(layers._baseLayersList.getElementsByTagName('input')[1]); + UIEventSimulator.fire('click', layers._baseLayersList.getElementsByTagName('input')[1]); expect(spy.calledTwice).to.be.ok(); expect(spy.args[1][0].name).to.be('Layer 2'); expect(spy.args[1][0].layer).to.be(baseLayers['Layer 2']); @@ -55,7 +55,7 @@ describe('Control.Layers', () => { spy = sinon.spy(); map.on('baselayerchange', spy); - happen.click(layers._overlaysList.getElementsByTagName('input')[0]); + UIEventSimulator.fire('click', layers._overlaysList.getElementsByTagName('input')[0]); expect(spy.called).to.not.be.ok(); }); @@ -137,15 +137,15 @@ describe('Control.Layers', () => { } } - happen.click(layers._baseLayersList.getElementsByTagName('input')[1]); + UIEventSimulator.fire('click', layers._baseLayersList.getElementsByTagName('input')[1]); checkInputs(1); expect(map._layers[L.Util.stamp(layerB)]).to.be.equal(layerB); expect(map._layers[L.Util.stamp(layerA)]).to.be.equal(undefined); - happen.click(layers._baseLayersList.getElementsByTagName('input')[0]); + UIEventSimulator.fire('click', layers._baseLayersList.getElementsByTagName('input')[0]); checkInputs(0); expect(map._layers[L.Util.stamp(layerA)]).to.be.equal(layerA); expect(map._layers[L.Util.stamp(layerB)]).to.be.equal(undefined); - happen.click(layers._baseLayersList.getElementsByTagName('input')[2]); + UIEventSimulator.fire('click', layers._baseLayersList.getElementsByTagName('input')[2]); checkInputs(2); expect(map._layers[L.Util.stamp(layerA)]).to.be.equal(layerA); expect(map._layers[L.Util.stamp(layerB)]).to.be.equal(undefined); @@ -191,41 +191,41 @@ describe('Control.Layers', () => { it('expands on "Enter" keydown when toggle is focused', () => { const layersCtrl = L.control.layers(null, null, {collapsed: true}).addTo(map); const toggle = layersCtrl._container.querySelector('.leaflet-control-layers-toggle'); - happen.once(toggle, {type:'keydown', keyCode:13}); + UIEventSimulator.fire('keydown', toggle, {code: 'Enter'}); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.be.ok(); }); it('expands on click', () => { const layersCtrl = L.control.layers(null, null, {collapsed: true}).addTo(map); const toggle = layersCtrl._container.querySelector('.leaflet-control-layers-toggle'); - happen.once(toggle, {type:'click'}); + UIEventSimulator.fire('click', toggle); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.be.ok(); }); it('does not expand on "Enter" keydown when toggle is not focused', () => { L.control.layers(null, null, {collapsed: true}).addTo(map); - happen.once(document, {type:'keydown', keyCode:13}); + UIEventSimulator.fire('keydown', document, {code:'Enter'}); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.not.be.ok(); }); it('expands when mouse is over', () => { const layersCtrl = L.control.layers(null, null, {collapsed: true}).addTo(map); - happen.once(layersCtrl._container, {type:'mouseover'}); + UIEventSimulator.fire('mouseover', layersCtrl._container); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.be.ok(); }); it('collapses when mouse is out', () => { const layersCtrl = L.control.layers(null, null, {collapsed: true}).addTo(map); - happen.once(layersCtrl._container, {type:'mouseover'}); - happen.once(layersCtrl._container, {type:'mouseout'}); + UIEventSimulator.fire('mouseover', layersCtrl._container); + UIEventSimulator.fire('mouseout', layersCtrl._container); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.not.be.ok(); }); it('collapses when map is clicked', () => { const layersCtrl = L.control.layers(null, null, {collapsed: true}).addTo(map); - happen.once(layersCtrl._container, {type:'mouseover'}); + UIEventSimulator.fire('mouseover', layersCtrl._container); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.be.ok(); - happen.click(map._container); + UIEventSimulator.fire('click', map._container); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.not.be.ok(); }); }); @@ -234,16 +234,16 @@ describe('Control.Layers', () => { it('does not collapse when mouse enters or leaves', () => { const layersCtrl = L.control.layers(null, null, {collapsed: false}).addTo(map); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.be.ok(); - happen.once(layersCtrl._container, {type:'mouseover'}); + UIEventSimulator.fire('mouseover', layersCtrl._container); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.be.ok(); - happen.once(layersCtrl._container, {type:'mouseout'}); + UIEventSimulator.fire('mouseout', layersCtrl._container); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.be.ok(); }); it('does not collapse when map is clicked', () => { L.control.layers(null, null, {collapsed: false}).addTo(map); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.be.ok(); - happen.click(map._container); + UIEventSimulator.fire('click', map._container); expect(map._container.querySelector('.leaflet-control-layers-expanded')).to.be.ok(); }); diff --git a/spec/suites/dom/DomEvent.DoubleTapSpec.js b/spec/suites/dom/DomEvent.DoubleTapSpec.js index f6efbffef1e..be595f2d993 100644 --- a/spec/suites/dom/DomEvent.DoubleTapSpec.js +++ b/spec/suites/dom/DomEvent.DoubleTapSpec.js @@ -16,9 +16,9 @@ describe('DomEvent.DoubleTapSpec.js', () => { }); it('fires synthetic dblclick after two clicks with delay<200', () => { - happen.click(container, {detail: 1}); + UIEventSimulator.fire('click', container, {detail: 1}); clock.tick(100); - happen.click(container, {detail: 1}); + UIEventSimulator.fire('click', container, {detail: 1}); expect(spy.called).to.be.ok(); expect(spy.calledOnce).to.be.ok(); @@ -26,17 +26,17 @@ describe('DomEvent.DoubleTapSpec.js', () => { }); it('does not fire dblclick when delay>200', () => { - happen.click(container, {detail: 1}); + UIEventSimulator.fire('click', container, {detail: 1}); clock.tick(300); - happen.click(container, {detail: 1}); + UIEventSimulator.fire('click', container, {detail: 1}); expect(spy.notCalled).to.be.ok(); }); it('does not fire dblclick when detail !== 1', () => { - happen.click(container, {detail: 0}); // like in IE + UIEventSimulator.fire('click', container, {detail: 0}); // like in IE clock.tick(100); - happen.click(container, {detail: 0}); + UIEventSimulator.fire('click', container, {detail: 0}); clock.tick(100); expect(spy.notCalled).to.be.ok(); @@ -45,19 +45,19 @@ describe('DomEvent.DoubleTapSpec.js', () => { it('does not fire dblclick after removeListener', () => { L.DomEvent.off(container, 'dblclick', spy); - happen.click(container, {detail: 1}); + UIEventSimulator.fire('click', container, {detail: 1}); clock.tick(100); - happen.click(container, {detail: 1}); + UIEventSimulator.fire('click', container, {detail: 1}); clock.tick(100); expect(spy.notCalled).to.be.ok(); }); it('does not conflict with native dblclick', () => { - happen.click(container, {detail: 1}); + UIEventSimulator.fire('click', container, {detail: 1}); clock.tick(100); - happen.click(container, {detail: 2}); // native dblclick expected - happen.dblclick(container); + UIEventSimulator.fire('click', container, {detail: 2}); // native dblclick expected + UIEventSimulator.fire('dblclick', container); // native dblclick expected expect(spy.called).to.be.ok(); expect(spy.calledOnce).to.be.ok(); expect(spy.lastCall.args[0]._simulated).not.to.be.ok(); @@ -71,9 +71,9 @@ describe('DomEvent.DoubleTapSpec.js', () => { screenX: 4, screenY: 5 }; - happen.click(container, click); + UIEventSimulator.fire('click', container, click); clock.tick(100); - happen.click(container, click); + UIEventSimulator.fire('click', container, click); const event = spy.lastCall.args[0]; const expectedProps = L.extend(click, { @@ -105,9 +105,9 @@ describe('DomEvent.DoubleTapSpec.js', () => { map.addControl(new MyControl()); L.DomEvent.on(ctrl, 'dblclick', spyCtrl); - happen.click(ctrl, {detail: 1}); + UIEventSimulator.fire('click', ctrl, {detail: 1}); clock.tick(100); - happen.click(ctrl, {detail: 1}); + UIEventSimulator.fire('click', ctrl, {detail: 1}); expect(spyCtrl.called).to.be.ok(); expect(spyMap.notCalled).to.be.ok(); @@ -129,7 +129,7 @@ describe('DomEvent.DoubleTapSpec.js', () => { }); map.addControl(new MyControl()); // click on the label - happen.click(div.children[1], {detail: 1}); + UIEventSimulator.fire('click', div.children[1], {detail: 1}); clock.tick(100); expect(spyMap.notCalled).to.be.ok(); map.remove(); diff --git a/spec/suites/dom/DomEvent.PointerSpec.js b/spec/suites/dom/DomEvent.PointerSpec.js index c3fe8d23d9a..0d4408ae6e0 100644 --- a/spec/suites/dom/DomEvent.PointerSpec.js +++ b/spec/suites/dom/DomEvent.PointerSpec.js @@ -15,8 +15,8 @@ describe('DomEvent.Pointer', () => { }); afterEach(() => { - happen.once(el, {type: 'pointercancel'}); // to reset prosphetic-hand - happen.once(el, {type: 'touchcancel'}); // + UIEventSimulator.fire('pointercancel', el); // to reset prosphetic-hand + UIEventSimulator.fire('touchcancel', el); document.body.removeChild(el); }); @@ -26,7 +26,7 @@ describe('DomEvent.Pointer', () => { (pointerToTouch ? describe : skip)('#Simulates touch based on pointer events', () => { it('adds a listener and calls it on pointer event', () => { pointerEvents.forEach((type) => { - happen.once(el, {type}); + UIEventSimulator.fire(type, el); }); touchEvents.forEach((type) => { expect(listeners[type].called).to.be.ok(); @@ -39,7 +39,7 @@ describe('DomEvent.Pointer', () => { L.DomEvent.off(el, type, listeners[type]); }); pointerEvents.forEach((type) => { - happen.once(el, {type}); + UIEventSimulator.fire(type, el); }); touchEvents.forEach((type) => { expect(listeners[type].notCalled).to.be.ok(); @@ -48,7 +48,7 @@ describe('DomEvent.Pointer', () => { it('ignores events from mouse', () => { pointerEvents.forEach((type) => { - happen.once(el, {type, pointerType: 'mouse'}); + UIEventSimulator.fire(type, el, {pointerType: 'mouse'}); }); touchEvents.forEach((type) => { expect(listeners[type].notCalled).to.be.ok(); @@ -57,7 +57,7 @@ describe('DomEvent.Pointer', () => { it('ignores native touch events', () => { touchEvents.forEach((type) => { - happen.once(el, {type}); + UIEventSimulator.fire(type, el); }); touchEvents.forEach((type) => { expect(listeners[type].notCalled).to.be.ok(); @@ -99,7 +99,7 @@ describe('DomEvent.Pointer', () => { // pointerdown/touchstart const pointer1 = {clientX:1, clientY:1, pointerId: 1}; - happen.once(el, L.extend({type: 'pointerdown'}, pointer1)); + UIEventSimulator.fire('pointerdown', el, pointer1); let evt = listeners.touchstart.lastCall.args[0]; expect(evt.type).to.be('pointerdown'); expect(evt).to.have.keys('touches', 'changedTouches'); @@ -110,7 +110,7 @@ describe('DomEvent.Pointer', () => { // another pointerdown/touchstart (multitouch) const pointer2 = {clientX:2, clientY:2, pointerId: 2}; - happen.once(el, L.extend({type: 'pointerdown'}, pointer2)); + UIEventSimulator.fire('pointerdown', el, pointer2); evt = listeners.touchstart.lastCall.args[0]; expect(evt.type).to.be('pointerdown'); expect(evt).to.have.keys('touches', 'changedTouches'); @@ -121,7 +121,7 @@ describe('DomEvent.Pointer', () => { // pointermove/touchmove (multitouch) L.extend(pointer1, {clientX:11, clientY:11}); - happen.once(el, L.extend({type: 'pointermove'}, pointer1)); + UIEventSimulator.fire('pointermove', el, pointer1); evt = listeners.touchmove.lastCall.args[0]; expect(evt.type).to.be('pointermove'); expect(evt).to.have.keys('touches', 'changedTouches'); @@ -131,7 +131,7 @@ describe('DomEvent.Pointer', () => { expect(containIn([pointer1, pointer2], evt.touches)).to.be.ok(); // pointerup/touchend (multitouch) - happen.once(el, L.extend({type: 'pointerup'}, pointer2)); + UIEventSimulator.fire('pointerup', el, pointer2); evt = listeners.touchend.lastCall.args[0]; expect(evt.type).to.be('pointerup'); expect(evt).to.have.keys('touches', 'changedTouches'); @@ -141,7 +141,7 @@ describe('DomEvent.Pointer', () => { expect(containIn(pointer1, evt.touches[0])).to.be.ok(); // pointercancel/touchcancel - happen.once(el, L.extend({type: 'pointercancel'}, pointer1)); + UIEventSimulator.fire('pointercancel', el, pointer1); evt = listeners.touchcancel.lastCall.args[0]; expect(evt.type).to.be('pointercancel'); expect(evt).to.have.keys('touches', 'changedTouches'); @@ -159,7 +159,7 @@ describe('DomEvent.Pointer', () => { (L.Browser.pointer ? skip : describe)('#Does not intrude if pointer events are not available', () => { it('adds a listener and calls it on touch event', () => { touchEvents.forEach((type) => { - happen.once(el, {type}); + UIEventSimulator.fire(type, el); }); touchEvents.forEach((type) => { expect(listeners[type].calledOnce).to.be.ok(); @@ -168,7 +168,7 @@ describe('DomEvent.Pointer', () => { it('ignores pointer events', () => { pointerEvents.forEach((type) => { - happen.once(el, {type}); + UIEventSimulator.fire(type, el); }); touchEvents.forEach((type) => { expect(listeners[type].notCalled).to.be.ok(); diff --git a/spec/suites/dom/DomEventSpec.js b/spec/suites/dom/DomEventSpec.js index cdf2e5b097f..cb00a33e2fb 100644 --- a/spec/suites/dom/DomEventSpec.js +++ b/spec/suites/dom/DomEventSpec.js @@ -231,7 +231,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, 'click', listener); L.DomEvent.on(el, 'click', listener2); - happen.click(el); + UIEventSimulator.fire('click', el); expect(listener.called).to.be.ok(); expect(listener2.called).to.be.ok(); @@ -242,8 +242,8 @@ describe('DomEvent', () => { L.DomEvent.on(el, 'click keypress', listener); L.DomEvent.on(el, 'click', listener2); - happen.click(el); - happen.keypress(el); + UIEventSimulator.fire('click', el); + UIEventSimulator.fire('keypress', el); expect(listener.called).to.be.ok(); expect(listener2.called).to.be.ok(); @@ -254,7 +254,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, {click: listener}); - happen.click(el); + UIEventSimulator.fire('click', el); sinon.assert.called(listener); }); @@ -264,8 +264,8 @@ describe('DomEvent', () => { L.DomEvent.on(el, {click: listener, keypress: listener2}); - happen.click(el); - happen.keypress(el); + UIEventSimulator.fire('click', el); + UIEventSimulator.fire('keypress', el); sinon.assert.called(listener); sinon.assert.called(listener2); @@ -275,7 +275,7 @@ describe('DomEvent', () => { const obj = {foo: 'bar'}; L.DomEvent.on(el, 'click', listener, obj); - happen.click(el); + UIEventSimulator.fire('click', el); expect(listener.calledOn(obj)).to.be.ok(); }); @@ -284,8 +284,8 @@ describe('DomEvent', () => { const obj = {foo: 'bar'}; L.DomEvent.on(el, 'click keypress', listener, obj); - happen.click(el); - happen.keypress(el); + UIEventSimulator.fire('click', el); + UIEventSimulator.fire('keypress', el); expect(listener.calledOn(obj)).to.be.ok(); }); @@ -296,7 +296,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, {click: listener}, ctx); - happen.click(el); + UIEventSimulator.fire('click', el); sinon.assert.calledOn(listener, ctx); }); @@ -307,8 +307,8 @@ describe('DomEvent', () => { L.DomEvent.on(el, {click: listener, keypress: listener2}, ctx); - happen.click(el); - happen.keypress(el); + UIEventSimulator.fire('click', el); + UIEventSimulator.fire('keypress', el); sinon.assert.calledOn(listener, ctx); sinon.assert.calledOn(listener2, ctx); @@ -317,7 +317,7 @@ describe('DomEvent', () => { it('passes an event object to the listener', () => { L.DomEvent.on(el, 'click', listener); - happen.click(el); + UIEventSimulator.fire('click', el); expect(listener.lastCall.args[0].type).to.eql('click'); }); @@ -325,8 +325,8 @@ describe('DomEvent', () => { it('passes two event objects to the listener', () => { L.DomEvent.on(el, 'click keypress', listener); - happen.click(el); - happen.keypress(el); + UIEventSimulator.fire('click', el); + UIEventSimulator.fire('keypress', el); expect(listener.firstCall.args[0].type).to.eql('click'); expect(listener.secondCall.args[0].type).to.eql('keypress'); @@ -348,7 +348,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, 'click', listener); L.DomEvent.off(el, 'click', listener); - happen.click(el); + UIEventSimulator.fire('click', el); expect(listener.notCalled).to.be.ok(); }); @@ -357,8 +357,8 @@ describe('DomEvent', () => { L.DomEvent.on(el, 'click keypress', listener); L.DomEvent.off(el, 'click', listener); - happen.click(el); - happen.keypress(el); + UIEventSimulator.fire('click', el); + UIEventSimulator.fire('keypress', el); expect(listener.lastCall.args[0].type).to.eql('keypress'); }); @@ -371,7 +371,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, 'click', listenerB); L.DomEvent.off(el, 'click', listenerA); - happen.click(el); + UIEventSimulator.fire('click', el); expect(listenerA.called).to.not.be.ok(); expect(listenerB.called).to.be.ok(); @@ -384,7 +384,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, events); L.DomEvent.off(el, events); - happen.click(el); + UIEventSimulator.fire('click', el); sinon.assert.notCalled(listener); }); @@ -396,8 +396,8 @@ describe('DomEvent', () => { L.DomEvent.on(el, events); L.DomEvent.off(el, events); - happen.click(el); - happen.keypress(el); + UIEventSimulator.fire('click', el); + UIEventSimulator.fire('keypress', el); sinon.assert.notCalled(listener); sinon.assert.notCalled(listener2); @@ -411,8 +411,8 @@ describe('DomEvent', () => { L.DomEvent.on(el, events); L.DomEvent.off(el, events2); - happen.click(el); - happen.keypress(el); + UIEventSimulator.fire('click', el); + UIEventSimulator.fire('keypress', el); sinon.assert.notCalled(listener); expect(listener2.lastCall.args[0].type).to.eql('keypress'); @@ -425,7 +425,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, 'click', listener, ctx); L.DomEvent.off(el, 'click', listener, ctx); - happen.click(el); + UIEventSimulator.fire('click', el); sinon.assert.notCalled(listener); }); @@ -438,7 +438,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, events, ctx); L.DomEvent.off(el, events, ctx); - happen.click(el); + UIEventSimulator.fire('click', el); sinon.assert.notCalled(listener); }); @@ -452,8 +452,8 @@ describe('DomEvent', () => { L.DomEvent.on(el, events, ctx); L.DomEvent.off(el, events2, ctx); - happen.click(el); - happen.keypress(el); + UIEventSimulator.fire('click', el); + UIEventSimulator.fire('keypress', el); sinon.assert.notCalled(listener); expect(listener2.lastCall.args[0].type).to.eql('keypress'); @@ -466,7 +466,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, 'click', listener); L.DomEvent.off(el, 'click', listener, ctx); - happen.click(el); + UIEventSimulator.fire('click', el); sinon.assert.called(listener); @@ -475,7 +475,7 @@ describe('DomEvent', () => { L.DomEvent.off(el, 'click', listener, {}); // wrong context L.DomEvent.off(el, 'click', listener); - happen.click(el); + UIEventSimulator.fire('click', el); sinon.assert.called(listener); }); @@ -488,7 +488,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, events); L.DomEvent.off(el, events, ctx); - happen.click(el); + UIEventSimulator.fire('click', el); sinon.assert.called(listener); @@ -499,7 +499,7 @@ describe('DomEvent', () => { L.DomEvent.off(el, events); L.DomEvent.off(el, events, {}); // wrong context - happen.click(el); + UIEventSimulator.fire('click', el); sinon.assert.called(listener); }); @@ -512,7 +512,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, 'click', listenerB, {}); L.DomEvent.off(el); - happen.click(el); + UIEventSimulator.fire('click', el); expect(listenerA.called).to.not.be.ok(); expect(listenerB.called).to.not.be.ok(); @@ -525,8 +525,8 @@ describe('DomEvent', () => { L.DomEvent.on(el, 'click', listenerClick); L.DomEvent.on(el, 'dblclick', listenerDblClick); L.DomEvent.off(el, 'click'); - happen.click(el); - happen.dblclick(el); + UIEventSimulator.fire('click', el); + UIEventSimulator.fire('dblclick', el); sinon.assert.notCalled(listenerClick); sinon.assert.called(listenerDblClick); @@ -554,7 +554,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, 'click', listener); L.DomEvent.off(el, {'click': listener}); - happen.click(el); + UIEventSimulator.fire('click', el); expect(listener.called).to.not.be.ok(); }); @@ -577,7 +577,7 @@ describe('DomEvent', () => { L.DomEvent.on(child, 'click', L.DomEvent.stopPropagation); L.DomEvent.on(el, 'click', listener); - happen.click(child); + UIEventSimulator.fire('click', child); expect(listener.notCalled).to.be.ok(); }); @@ -591,7 +591,7 @@ describe('DomEvent', () => { L.DomEvent.on(el, wheel, listener); L.DomEvent.disableScrollPropagation(child); - happen.once(child, {type: wheel}); + UIEventSimulator.fire(wheel, child); expect(listener.notCalled).to.be.ok(); }); @@ -604,10 +604,10 @@ describe('DomEvent', () => { L.DomEvent.disableClickPropagation(child); L.DomEvent.on(el, 'dblclick contextmenu mousedown touchstart', listener); - happen.once(child, {type: 'dblclick'}); - happen.once(child, {type: 'contextmenu'}); - happen.once(child, {type: 'mousedown'}); - happen.once(child, {type: 'touchstart', touches: []}); + UIEventSimulator.fire('dblclick', child); + UIEventSimulator.fire('contextmenu', child); + UIEventSimulator.fire('mousedown', child); + UIEventSimulator.fire('touchstart', child, {touches: []}); expect(listener.notCalled).to.be.ok(); }); @@ -626,15 +626,15 @@ describe('DomEvent', () => { map.on('click', mapClickListener); // control case map.on('keypress', mapOtherListener); // control case - happen.once(grandChild, {type: 'click'}); - happen.once(grandChild, {type: 'keypress'}); + UIEventSimulator.fire('click', grandChild); + UIEventSimulator.fire('keypress', grandChild); expect(mapOtherListener.called).to.be.ok(); // control case expect(listener.called).to.be.ok(); expect(mapClickListener.notCalled).to.be.ok(); - happen.once(child, {type: 'click'}); - happen.once(child, {type: 'keypress'}); + UIEventSimulator.fire('click', child); + UIEventSimulator.fire('keypress', child); expect(listener.calledTwice).to.be.ok(); expect(mapClickListener.notCalled).to.be.ok(); @@ -662,7 +662,7 @@ describe('DomEvent', () => { done(); }); - happen.click(el); + UIEventSimulator.fire('click', el); }); }); }); diff --git a/spec/suites/dom/DomUtilSpec.js b/spec/suites/dom/DomUtilSpec.js index 8b7521de327..4fca627845e 100644 --- a/spec/suites/dom/DomUtilSpec.js +++ b/spec/suites/dom/DomUtilSpec.js @@ -276,11 +276,11 @@ describe('DomUtil', () => { L.DomUtil.disableImageDrag(); window.addEventListener('dragstart', checkPrevented); - happen.once(child, {type: 'dragstart'}); + UIEventSimulator.fire('dragstart', child); expect(selectionPrevented).to.be.ok(); L.DomUtil.enableImageDrag(); - happen.once(child, {type: 'dragstart'}); + UIEventSimulator.fire('dragstart', child); expect(selectionPrevented).to.not.be.ok(); }); }); @@ -302,7 +302,7 @@ describe('DomUtil', () => { // Implicit #restoreOutline test through simulation L.DomUtil.preventOutline(child); expect(child.style.outline).to.match(/(?:none)/); - happen.once(child, {type: 'keydown'}); + UIEventSimulator.fire('keydown', child); expect(child.style.outline).to.be.equal(child.style.outline); }); }); diff --git a/spec/suites/layer/PopupSpec.js b/spec/suites/layer/PopupSpec.js index 57220c8b0ff..e36f00b6f09 100644 --- a/spec/suites/layer/PopupSpec.js +++ b/spec/suites/layer/PopupSpec.js @@ -20,7 +20,7 @@ describe('Popup', () => { .setLatLng(center) .openOn(map); - happen.click(container); + UIEventSimulator.fire('click', container); expect(map.hasLayer(popup)).to.be(false); }); @@ -32,7 +32,7 @@ describe('Popup', () => { .setLatLng(center) .openOn(map); - happen.click(container); + UIEventSimulator.fire('click', container); expect(map.hasLayer(popup)).to.be(false); }); @@ -44,7 +44,7 @@ describe('Popup', () => { .setLatLng(center) .openOn(map); - happen.click(container); + UIEventSimulator.fire('click', container); expect(map.hasLayer(popup)).to.be(true); }); @@ -74,11 +74,11 @@ describe('Popup', () => { expect(map.hasLayer(marker._popup)).to.be(false); // toggle open popup - happen.click(marker._icon); + UIEventSimulator.fire('click', marker._icon); expect(map.hasLayer(marker._popup)).to.be(true); // toggle close popup - happen.click(marker._icon); + UIEventSimulator.fire('click', marker._icon); expect(map.hasLayer(marker._popup)).to.be(false); }); @@ -286,7 +286,7 @@ describe('Popup', () => { }); expect(map.hasLayer(layer._popup)).to.be(false); - happen.click(layer._path); + UIEventSimulator.fire('click', layer._path); expect(mapClicked).to.be(false); expect(map.hasLayer(layer._popup)).to.be(true); }); @@ -296,8 +296,8 @@ describe('Popup', () => { const layer = L.marker(center).addTo(map); layer.bindPopup('layer popup'); - happen.keypress(layer._icon, { - keyCode: 13 + UIEventSimulator.fire('keypress', layer._icon, { + code: 'Enter' }); expect(map.hasLayer(layer._popup)).to.be(true); @@ -582,7 +582,7 @@ describe('Popup', () => { const el = document.elementFromPoint(point.x, point.y); expect(el).to.be(popup._tip); - happen.click(el, { + UIEventSimulator.fire('click', el, { clientX: point.x, clientY: point.y }); diff --git a/spec/suites/layer/TooltipSpec.js b/spec/suites/layer/TooltipSpec.js index 309a994bd6d..04ea3f693c6 100644 --- a/spec/suites/layer/TooltipSpec.js +++ b/spec/suites/layer/TooltipSpec.js @@ -17,11 +17,11 @@ describe('Tooltip', () => { layer.bindTooltip('Tooltip'); - happen.mouseover(layer._icon, {relatedTarget: map._container}); + UIEventSimulator.fire('mouseover', layer._icon, {relatedTarget: map._container}); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.mouseout(layer._icon, {relatedTarget: map._container}); + UIEventSimulator.fire('mouseout', layer._icon, {relatedTarget: map._container}); expect(map.hasLayer(layer._tooltip)).to.be(false); }); @@ -32,11 +32,11 @@ describe('Tooltip', () => { const element = layer.getElement(); - happen.once(element, {type:'focus'}); + UIEventSimulator.fire('focus', element); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.once(element, {type:'blur'}); + UIEventSimulator.fire('blur', element); expect(map.hasLayer(layer._tooltip)).to.be(false); }); @@ -47,11 +47,11 @@ describe('Tooltip', () => { const element = layer.getElement(); - happen.once(element, {type:'focus'}); + UIEventSimulator.fire('focus', element); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.once(element, {type:'blur'}); + UIEventSimulator.fire('blur', element); expect(map.hasLayer(layer._tooltip)).to.be(false); }); @@ -64,20 +64,20 @@ describe('Tooltip', () => { const element1 = marker1.getElement(); const element2 = marker2.getElement(); - happen.once(element1, {type:'focus'}); + UIEventSimulator.fire('focus', element1); expect(map.hasLayer(group._tooltip)).to.be(true); expect(group._tooltip._container.innerHTML).to.be('Group tooltip: Marker 1'); - happen.once(element1, {type:'blur'}); + UIEventSimulator.fire('blur', element1); expect(map.hasLayer(group._tooltip)).to.be(false); - happen.once(element2, {type:'focus'}); + UIEventSimulator.fire('focus', element2); expect(map.hasLayer(group._tooltip)).to.be(true); expect(group._tooltip._container.innerHTML).to.be('Group tooltip: Marker 2'); - happen.once(element2, {type:'blur'}); + UIEventSimulator.fire('blur', element2); expect(map.hasLayer(group._tooltip)).to.be(false); }); @@ -87,7 +87,7 @@ describe('Tooltip', () => { layer.bindTooltip('Tooltip'); const element = layer.getElement(); - happen.once(element, {type:'focus'}); + UIEventSimulator.fire('focus', element); const tooltip = layer.getTooltip(); expect(element.getAttribute('aria-describedby')).to.equal(tooltip._container.id); @@ -101,7 +101,7 @@ describe('Tooltip', () => { const element = marker2.getElement(); - happen.once(element, {type:'focus'}); + UIEventSimulator.fire('focus', element); const tooltip = group.getTooltip(); expect(element.getAttribute('aria-describedby')).to.equal(tooltip._container.id); @@ -139,7 +139,7 @@ describe('Tooltip', () => { layer.bindTooltip('Tooltip', {permanent: true}); layer._tooltip.on('click', spy); - happen.click(layer._tooltip._container); + UIEventSimulator.fire('click', layer._tooltip._container); expect(spy.called).to.be(false); }); @@ -149,7 +149,7 @@ describe('Tooltip', () => { layer.bindTooltip('Tooltip', {permanent: true, interactive: true}); layer._tooltip.on('click', spy); - happen.click(layer._tooltip._container); + UIEventSimulator.fire('click', layer._tooltip._container); expect(spy.calledOnce).to.be(true); }); @@ -159,7 +159,7 @@ describe('Tooltip', () => { layer.on('click', spy); layer.bindTooltip('Tooltip', {permanent: true, interactive: true}); - happen.click(layer._tooltip._container); + UIEventSimulator.fire('click', layer._tooltip._container); expect(spy.calledOnce).to.be(true); }); @@ -182,7 +182,7 @@ describe('Tooltip', () => { layer.bindTooltip('A long tooltip that should be displayed on the left', {permanent: true, direction: 'left', interactive: true}); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.at('click', 150, 180); // Marker is on the map center, which is 400px large. + UIEventSimulator.fireAt('click', 150, 180); // Marker is on the map center, which is 400px large. expect(spy.calledOnce).to.be(true); }); @@ -193,9 +193,9 @@ describe('Tooltip', () => { layer.bindTooltip('A long tooltip that should be displayed on the left', {permanent: true, direction: 'left', interactive: true, offset: [-20, -20]}); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.at('click', 150, 180); + UIEventSimulator.fireAt('click', 150, 180); expect(spy.calledOnce).to.be(false); - happen.at('click', 130, 160); + UIEventSimulator.fireAt('click', 130, 160); expect(spy.calledOnce).to.be(true); }); @@ -206,7 +206,7 @@ describe('Tooltip', () => { layer.bindTooltip('A tooltip that should be displayed on the top', {permanent: true, direction: 'top', interactive: true}); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.at('click', 200, 180); // Marker is on the map center, which is 400px large. + UIEventSimulator.fireAt('click', 200, 180); // Marker is on the map center, which is 400px large. expect(spy.calledOnce).to.be(true); }); @@ -216,9 +216,9 @@ describe('Tooltip', () => { layer.on('click', spy); layer.bindTooltip('A tooltip that should be displayed on the top', {permanent: true, direction: 'top', interactive: true, offset: [-20, -20]}); - happen.at('click', 200, 180); + UIEventSimulator.fireAt('click', 200, 180); expect(spy.calledOnce).to.be(false); - happen.at('click', 180, 150); + UIEventSimulator.fireAt('click', 180, 150); expect(spy.calledOnce).to.be(true); }); @@ -229,7 +229,7 @@ describe('Tooltip', () => { layer.bindTooltip('A tooltip that should be displayed on the top', {permanent: true, direction: 'bottom', interactive: true}); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.at('click', 200, 220); // Marker is on the map center, which is 400px large. + UIEventSimulator.fireAt('click', 200, 220); // Marker is on the map center, which is 400px large. expect(spy.calledOnce).to.be(true); }); @@ -240,9 +240,9 @@ describe('Tooltip', () => { layer.bindTooltip('A tooltip that should be displayed on the top', {permanent: true, direction: 'bottom', interactive: true, offset: [20, 20]}); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.at('click', 200, 220); + UIEventSimulator.fireAt('click', 200, 220); expect(spy.calledOnce).to.be(false); - happen.at('click', 220, 230); + UIEventSimulator.fireAt('click', 220, 230); expect(spy.calledOnce).to.be(true); }); @@ -253,7 +253,7 @@ describe('Tooltip', () => { layer.bindTooltip('A tooltip that should be displayed on the center', {permanent: true, direction: 'center', interactive: true}); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.at('click', 150, 180); // Marker is on the map center, which is 400px large. + UIEventSimulator.fireAt('click', 150, 180); // Marker is on the map center, which is 400px large. expect(spy.calledOnce).to.be(true); }); @@ -279,12 +279,12 @@ describe('Tooltip', () => { group.bindTooltip(layer => layer.options.description); // toggle popup on marker1 - happen.mouseover(marker1._icon, {relatedTarget: map._container}); + UIEventSimulator.fire('mouseover', marker1._icon, {relatedTarget: map._container}); expect(map.hasLayer(group._tooltip)).to.be(true); expect(group._tooltip._container.innerHTML).to.be('I\'m marker 1.'); // toggle popup on marker2 - happen.mouseover(marker2._icon, {relatedTarget: map._container}); + UIEventSimulator.fire('mouseover', marker2._icon, {relatedTarget: map._container}); expect(map.hasLayer(group._tooltip)).to.be(true); expect(group._tooltip._container.innerHTML).to.be('I\'m marker 2.'); }); @@ -294,11 +294,11 @@ describe('Tooltip', () => { layer.bindTooltip('Tooltip'); - happen.mouseover(layer._path, {relatedTarget: map._container}); + UIEventSimulator.fire('mouseover', layer._path, {relatedTarget: map._container}); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.mouseout(layer._path, {relatedTarget: map._container}); + UIEventSimulator.fire('mouseout', layer._path, {relatedTarget: map._container}); expect(map.hasLayer(layer._tooltip)).to.be(false); }); @@ -327,11 +327,11 @@ describe('Tooltip', () => { layer.bindTooltip('Tooltip'); - happen.mouseover(layer._path, {relatedTarget: map._container}); + UIEventSimulator.fire('mouseover', layer._path, {relatedTarget: map._container}); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.mouseout(layer._path, {relatedTarget: map._container}); + UIEventSimulator.fire('mouseout', layer._path, {relatedTarget: map._container}); expect(map.hasLayer(layer._tooltip)).to.be(false); }); @@ -360,7 +360,7 @@ describe('Tooltip', () => { layer.bindTooltip('Tooltip'); expect(map.hasLayer(layer._tooltip)).to.be(false); - happen.click(layer._icon); + UIEventSimulator.fire('click', layer._icon); expect(map.hasLayer(layer._tooltip)).to.be(true); }); @@ -368,9 +368,9 @@ describe('Tooltip', () => { const layer = L.marker(center).addTo(map); layer.bindTooltip('Tooltip'); - happen.click(layer._icon); + UIEventSimulator.fire('click', layer._icon); expect(map.hasLayer(layer._tooltip)).to.be(true); - happen.click(map._container); + UIEventSimulator.fire('click', map._container); expect(map.hasLayer(layer._tooltip)).to.be(false); }); @@ -390,7 +390,7 @@ describe('Tooltip', () => { .on('click', spy); map.openTooltip(tooltip, center); - happen.click(tooltip._container); + UIEventSimulator.fire('click', tooltip._container); expect(spy.calledOnce).to.be(true); }); @@ -406,7 +406,7 @@ describe('Tooltip', () => { const tooltip = layer.getTooltip(); expect(tooltip.getLatLng().equals(layer.getCenter())).to.be(true); - happen.at('click', 120, 120); + UIEventSimulator.fireAt('click', 120, 120); const latlng = map.containerPointToLatLng([120, 120]); expect(tooltip.getLatLng().equals(latlng)).to.be(true); }); @@ -450,14 +450,14 @@ describe('Tooltip', () => { map.dragging.moving = function () { return true; }; - happen.at('mouseover', 210, 195); + UIEventSimulator.fireAt('mouseover', 210, 195); expect(tooltip.isOpen()).to.be(false); // simulate map not dragging anymore map.dragging.moving = function () { return false; }; - happen.at('mouseover', 210, 195); + UIEventSimulator.fireAt('mouseover', 210, 195); expect(tooltip.isOpen()).to.be.ok(); }); @@ -468,18 +468,18 @@ describe('Tooltip', () => { const tooltip = layer.getTooltip(); // open tooltip before "dragging map" - happen.at('mouseover', 210, 195); + UIEventSimulator.fireAt('mouseover', 210, 195); expect(tooltip.isOpen()).to.be.ok(); // simulate map dragging map.dragging.moving = function () { return true; }; - happen.mouseout(layer._icon, {relatedTarget: map._container}); + UIEventSimulator.fire('mouseout', layer._icon, {relatedTarget: map._container}); expect(tooltip.isOpen()).to.be(false); // tooltip should not open again while dragging - happen.at('mouseover', 210, 195); + UIEventSimulator.fireAt('mouseover', 210, 195); expect(tooltip.isOpen()).to.be(false); }); diff --git a/spec/suites/layer/marker/MarkerSpec.js b/spec/suites/layer/marker/MarkerSpec.js index a8835441904..4fbf36c8aa1 100644 --- a/spec/suites/layer/marker/MarkerSpec.js +++ b/spec/suites/layer/marker/MarkerSpec.js @@ -252,7 +252,7 @@ describe('Marker', () => { const marker = L.marker([0, 0]).addTo(map); marker.on('click', spy); - happen.click(marker._icon); + UIEventSimulator.fire('click', marker._icon); expect(spy.called).to.be.ok(); }); @@ -263,7 +263,7 @@ describe('Marker', () => { const marker = L.marker([0, 0], {icon: L.divIcon()}).addTo(map); marker.on('click', spy); - happen.click(marker._icon); + UIEventSimulator.fire('click', marker._icon); expect(spy.called).to.be.ok(); }); @@ -275,10 +275,10 @@ describe('Marker', () => { marker.on('click', spy); - happen.click(marker._icon); + UIEventSimulator.fire('click', marker._icon); expect(spy.called).to.be.ok(); - happen.click(marker._icon.querySelector('img')); + UIEventSimulator.fire('click', marker._icon.querySelector('img')); expect(spy.calledTwice).to.be.ok(); }); @@ -290,10 +290,10 @@ describe('Marker', () => { marker.on('click', spy); - happen.click(marker._icon); + UIEventSimulator.fire('click', marker._icon); expect(spy.called).to.be.ok(); - happen.click(marker._icon.querySelector('img')); + UIEventSimulator.fire('click', marker._icon.querySelector('img')); expect(spy.calledTwice).to.be.ok(); }); @@ -306,7 +306,7 @@ describe('Marker', () => { marker.on('click', spy); marker.on('click', spy2); map.on('click', mapSpy); - happen.click(marker._icon); + UIEventSimulator.fire('click', marker._icon); expect(spy.called).to.be.ok(); expect(spy2.called).to.be.ok(); expect(mapSpy.called).not.to.be.ok(); @@ -321,7 +321,7 @@ describe('Marker', () => { marker.on('dblclick', spy); marker.on('dblclick', spy2); map.on('dblclick', mapSpy); - happen.dblclick(marker._icon); + UIEventSimulator.fire('dblclick', marker._icon); expect(spy.called).to.be.ok(); expect(spy2.called).to.be.ok(); expect(mapSpy.called).not.to.be.ok(); @@ -334,14 +334,14 @@ describe('Marker', () => { // It should be the marker coordinates expect(e.latlng.equals(marker.getLatLng())).to.be.equal(true); }); - happen.mousemove(marker._icon); + UIEventSimulator.fire('mousemove', marker._icon); map.once('mousemove', (e) => { // It should be the mouse coordinates, not the marker ones expect(e.latlng.equals(marker.getLatLng())).to.be.equal(false); done(); }); - happen.mousemove(marker._icon); + UIEventSimulator.fire('mousemove', marker._icon); }); }); }); diff --git a/spec/suites/layer/vector/CanvasSpec.js b/spec/suites/layer/vector/CanvasSpec.js index 234179d6c62..4893fa84705 100644 --- a/spec/suites/layer/vector/CanvasSpec.js +++ b/spec/suites/layer/vector/CanvasSpec.js @@ -26,16 +26,16 @@ describe('Canvas', () => { it('should fire event when layer contains mouse', () => { const spy = sinon.spy(); layer.on('click', spy); - happen.at('click', 50, 50); // Click on the layer. + UIEventSimulator.fireAt('click', 50, 50); // Click on the layer. expect(spy.callCount).to.eql(1); - happen.at('click', 150, 150); // Click outside layer. + UIEventSimulator.fireAt('click', 150, 150); // Click outside layer. expect(spy.callCount).to.eql(1); }); it('DOM events propagate from canvas polygon to map', () => { const spy = sinon.spy(); map.on('click', spy); - happen.at('click', 50, 50); + UIEventSimulator.fireAt('click', 50, 50); expect(spy.callCount).to.eql(1); }); @@ -44,7 +44,7 @@ describe('Canvas', () => { const layerSpy = sinon.spy(); map.on('click', mapSpy); layer.on('click', L.DomEvent.stopPropagation).on('click', layerSpy); - happen.at('click', 50, 50); + UIEventSimulator.fireAt('click', 50, 50); expect(layerSpy.callCount).to.eql(1); expect(mapSpy.callCount).to.eql(0); }); @@ -53,7 +53,7 @@ describe('Canvas', () => { const spy = sinon.spy(); L.polygon(latLngs).addTo(map); // layer 2 map.on('click', spy); - happen.at('click', 50, 50); + UIEventSimulator.fireAt('click', 50, 50); expect(spy.callCount).to.eql(1); }); @@ -74,10 +74,10 @@ describe('Canvas', () => { marker.on('click', spyMarker); circle.on('click', spyCircle); - happen.at('click', 50, 50); // polygon (canvas) - happen.at('click', 151, 151); // empty space - happen.at('click', 150, 148); // marker - happen.at('click', 200, 200); // circle (svg) + UIEventSimulator.fireAt('click', 50, 50); // polygon (canvas) + UIEventSimulator.fireAt('click', 151, 151); // empty space + UIEventSimulator.fireAt('click', 150, 148); // marker + UIEventSimulator.fireAt('click', 200, 200); // circle (svg) expect(spyPolygon.callCount).to.eql(1); expect(spyMap.callCount).to.eql(3); // except marker expect(spyMarker.callCount).to.eql(1); @@ -87,7 +87,7 @@ describe('Canvas', () => { it('should not block mousemove event going to non-canvas features', () => { const spyMap = sinon.spy(); map.on('mousemove', spyMap); - happen.at('mousemove', 151, 151); // empty space + UIEventSimulator.fireAt('mousemove', 151, 151); // empty space expect(spyMap.calledOnce).to.be.ok(); }); @@ -99,10 +99,10 @@ describe('Canvas', () => { layer.once('preclick', () => { expect(clickSpy.called).to.be(false); }); - happen.at('click', 50, 50); // Click on the layer. + UIEventSimulator.fireAt('click', 50, 50); // Click on the layer. expect(clickSpy.callCount).to.eql(1); expect(preclickSpy.callCount).to.eql(1); - happen.at('click', 150, 150); // Click outside layer. + UIEventSimulator.fireAt('click', 150, 150); // Click outside layer. expect(clickSpy.callCount).to.eql(1); expect(preclickSpy.callCount).to.eql(1); }); @@ -119,7 +119,7 @@ describe('Canvas', () => { onStop() { // Prosthetic does not fire a click when we down+up, but it real world // browsers would, so let's simulate it. - happen.at('click', 70, 60); + UIEventSimulator.fireAt('click', 70, 60); expect(downSpy.called).to.be(true); expect(clickSpy.called).to.be(false); expect(preclickSpy.called).to.be(false); @@ -162,9 +162,9 @@ describe('Canvas', () => { const layer = L.polygon(latLngs, {interactive: false}).addTo(map); const spy = sinon.spy(); layer.on('click', spy); - happen.at('click', 50, 50); // Click on the layer. + UIEventSimulator.fireAt('click', 50, 50); // Click on the layer. expect(spy.callCount).to.eql(0); - happen.at('click', 150, 150); // Click outside layer. + UIEventSimulator.fireAt('click', 150, 150); // Click outside layer. expect(spy.callCount).to.eql(0); }); }); diff --git a/spec/suites/layer/vector/PathSpec.js b/spec/suites/layer/vector/PathSpec.js index f4d898581ae..91d5f261de1 100644 --- a/spec/suites/layer/vector/PathSpec.js +++ b/spec/suites/layer/vector/PathSpec.js @@ -50,7 +50,7 @@ describe('Path', () => { const spy = sinon.spy(); const layer = L.polygon([[1, 2], [3, 4], [5, 6]]).addTo(map); layer.on('click', spy); - happen.click(layer._path); + UIEventSimulator.fire('click', layer._path); expect(spy.called).to.be.ok(); }); @@ -62,7 +62,7 @@ describe('Path', () => { layer.on('click', spy); layer.on('click', spy2); map.on('click', mapSpy); - happen.click(layer._path); + UIEventSimulator.fire('click', layer._path); expect(spy.called).to.be.ok(); expect(spy2.called).to.be.ok(); expect(mapSpy.called).to.be.ok(); diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 3571d36651f..ec4853bb65c 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -56,7 +56,7 @@ describe('Map', () => { // before actual test: make sure that events are ok map.setView([0, 0], 0); map.on('click', spy); - happen.click(container); + UIEventSimulator.fire('click', container); expect(spy.called).to.be.ok(); // actual test @@ -65,11 +65,11 @@ describe('Map', () => { map.remove(); map = null; - happen.click(container); - happen.dblclick(container); - happen.mousedown(container); - happen.mouseup(container); - happen.mousemove(container); + UIEventSimulator.fire('click', container); + UIEventSimulator.fire('dblclick', container); + UIEventSimulator.fire('mousedown', container); + UIEventSimulator.fire('mouseup', container); + UIEventSimulator.fire('mousemove', container); expect(spy.called).to.not.be.ok(); }); @@ -693,17 +693,18 @@ describe('Map', () => { L.ClickHandler = getHandler(spy); map.addHandler('clickHandler', L.ClickHandler); - happen.once(window, {type: 'click'}); + UIEventSimulator.fire('click', window); + UIEventSimulator.fire('click', window); expect(spy.called).not.to.be.ok(); map.clickHandler.enable(); - happen.once(window, {type: 'click'}); + UIEventSimulator.fire('click', window); expect(spy.called).to.be.ok(); map.clickHandler.disable(); - happen.once(window, {type: 'click'}); + UIEventSimulator.fire('click', window); expect(spy.callCount).to.eql(1); }); }); @@ -1739,7 +1740,7 @@ describe('Map', () => { const spy = sinon.spy(); map.on('mousemove', spy); const layer = L.polygon([[1, 2], [3, 4], [5, 6]]).addTo(map); - happen.mousemove(layer._path); + UIEventSimulator.fire('mousemove', layer._path); expect(spy.calledOnce).to.be.ok(); }); @@ -1747,7 +1748,7 @@ describe('Map', () => { const spy = sinon.spy(); map.on('mousemove', spy); const layer = L.marker([1, 2]).addTo(map); - happen.mousemove(layer._icon); + UIEventSimulator.fire('mousemove', layer._icon); expect(spy.calledOnce).to.be.ok(); }); @@ -1757,7 +1758,7 @@ describe('Map', () => { map.on('mousemove', mapSpy); const layer = L.marker([1, 2]).addTo(map); layer.on('mousemove', L.DomEvent.stopPropagation).on('mousemove', layerSpy); - happen.mousemove(layer._icon); + UIEventSimulator.fire('mousemove', layer._icon); expect(layerSpy.calledOnce).to.be.ok(); expect(mapSpy.called).not.to.be.ok(); }); @@ -1768,7 +1769,7 @@ describe('Map', () => { map.on('mousemove', mapSpy); const layer = L.polygon([[1, 2], [3, 4], [5, 6]]).addTo(map); layer.on('mousemove', L.DomEvent.stopPropagation).on('mousemove', layerSpy); - happen.mousemove(layer._path); + UIEventSimulator.fire('mousemove', layer._path); expect(layerSpy.calledOnce).to.be.ok(); expect(mapSpy.called).not.to.be.ok(); }); @@ -1782,7 +1783,7 @@ describe('Map', () => { map.on('mouseout', mapSpy); layer.on('mouseout', layerSpy); other.on('mouseout', otherSpy); - happen.mouseout(layer._path, {relatedTarget: container}); + UIEventSimulator.fire('mouseout', layer._path, {relatedTarget: container}); expect(mapSpy.called).not.to.be.ok(); expect(otherSpy.called).not.to.be.ok(); expect(layerSpy.calledOnce).to.be.ok(); @@ -1798,7 +1799,7 @@ describe('Map', () => { layer = L.marker([1, 2], {icon}).addTo(map); map.on('mouseout', mapSpy); layer.on('mouseout', layerSpy); - happen.mouseout(layer._icon, {relatedTarget: container}); + UIEventSimulator.fire('mouseout', layer._icon, {relatedTarget: container}); expect(mapSpy.called).not.to.be.ok(); expect(layerSpy.calledOnce).to.be.ok(); }); @@ -1814,7 +1815,7 @@ describe('Map', () => { child = layer._icon.querySelector('p'); map.on('mouseout', mapSpy); layer.on('mouseout', layerSpy); - happen.mouseout(layer._icon, {relatedTarget: child}); + UIEventSimulator.fire('mouseout', layer._icon, {relatedTarget: child}); expect(mapSpy.called).not.to.be.ok(); expect(layerSpy.called).not.to.be.ok(); }); @@ -1830,7 +1831,7 @@ describe('Map', () => { child = layer._icon.querySelector('p'); map.on('mouseout', mapSpy); layer.on('mouseout', layerSpy); - happen.mouseout(child, {relatedTarget: layer._icon}); + UIEventSimulator.fire('mouseout', child, {relatedTarget: layer._icon}); expect(mapSpy.called).not.to.be.ok(); expect(layerSpy.called).not.to.be.ok(); }); @@ -1844,7 +1845,7 @@ describe('Map', () => { map.on('mouseout', mapSpy); layer.on('mouseout', layerSpy); other.on('mouseout', otherSpy); - happen.mouseout(container); + UIEventSimulator.fire('mouseout', container); expect(otherSpy.called).not.to.be.ok(); expect(layerSpy.called).not.to.be.ok(); expect(mapSpy.calledOnce).to.be.ok(); @@ -1869,7 +1870,7 @@ describe('Map', () => { expect(called++).to.eql(3); expect(e.latlng).to.ok(); }); - happen.click(layer._icon); + UIEventSimulator.fire('click', layer._icon); expect(called).to.eql(4); }); @@ -1891,9 +1892,9 @@ describe('Map', () => { }); const marker = L.circleMarker([0, 0]).addTo(map); - happen.at('contextmenu', 0, 0); // first + UIEventSimulator.fireAt('contextmenu', 0, 0); // first - happen.at('contextmenu', marker._point.x, marker._point.y); // second (#5995) + UIEventSimulator.fireAt('contextmenu', marker._point.x, marker._point.y); // second (#5995) expect(spy.callCount).to.be(2); expect(spy.firstCall.lastArg).to.be.ok(); @@ -1961,7 +1962,7 @@ describe('Map', () => { parent.remove(); }); expect(() => { - happen.once(child, {type: 'click'}); + UIEventSimulator.fire('click', child); }).to.not.throwException(); }); }); @@ -2398,7 +2399,7 @@ describe('Map', () => { map.on('click', (e) => { latlng = map.mouseEventToLatLng(e.originalEvent); }); - happen.at('click', 100, 100); + UIEventSimulator.fireAt('click', 100, 100); const expectedCenter = [80.178713496, -140.625]; expect(latlng).to.be.nearLatLng(expectedCenter); diff --git a/spec/suites/map/handler/Map.BoxZoom.js b/spec/suites/map/handler/Map.BoxZoom.js index d59fddfd2ed..735675f7a02 100644 --- a/spec/suites/map/handler/Map.BoxZoom.js +++ b/spec/suites/map/handler/Map.BoxZoom.js @@ -21,37 +21,37 @@ describe('Map.BoxZoom', () => { }); // check if click event on the map is fired - happen.click(map._container); + UIEventSimulator.fire('click', map._container); expect(mapClick).to.be(true); - // fire mousedown event with shiftKey = true, to start drawing the boxZoom let clientX = 100; let clientY = 100; - let event = new CustomEvent('mousedown'); - event.shiftKey = true; - event.clientX = clientX; - event.clientY = clientY; - event.button = 1; - map._container.dispatchEvent(event); - // fire mousemove event with shiftKey = true, to draw the boxZoom + // fire mousedown event with shiftKey = true, to start drawing the boxZoom + UIEventSimulator.fire('mousedown', map._container, { + shiftKey: true, + clientX, + clientY, + }); + clientX += 100; clientY += 100; - event = new CustomEvent('mousemove'); - event.shiftKey = true; - event.clientX = clientX; - event.clientY = clientY; - event.button = 1; - document.dispatchEvent(event); - - // fire keydown event with keyCode = 27 (ESC) to cancel boxZoom - event = new CustomEvent('keydown'); - event.keyCode = 27; - document.dispatchEvent(event); + + // fire mousemove event with shiftKey = true, to draw the boxZoom + UIEventSimulator.fire('mousemove', map._container, { + shiftKey: true, + clientX, + clientY, + }); + + // fire keydown event ESC to cancel boxZoom + UIEventSimulator.fire('keydown', document, { + code: 'Escape' + }); // check if click event on the map is fired mapClick = false; - happen.click(map._container); + UIEventSimulator.fire('click', map._container); expect(mapClick).to.be(true); }); diff --git a/spec/suites/map/handler/Map.DoubleClickZoomSpec.js b/spec/suites/map/handler/Map.DoubleClickZoomSpec.js index ae41fabadd9..ba6c062ac19 100644 --- a/spec/suites/map/handler/Map.DoubleClickZoomSpec.js +++ b/spec/suites/map/handler/Map.DoubleClickZoomSpec.js @@ -23,7 +23,7 @@ describe('Map.DoubleClickZoom', () => { done(); }); - happen.dblclick(container); + UIEventSimulator.fire('dblclick', container); }); it('zooms out while dblclick and holding shift', (done) => { @@ -35,7 +35,7 @@ describe('Map.DoubleClickZoom', () => { done(); }); - happen.dblclick(container, {shiftKey: true}); + UIEventSimulator.fire('dblclick', container, {shiftKey: true}); }); it('doubleClickZoom: \'center\'', (done) => { @@ -50,7 +50,7 @@ describe('Map.DoubleClickZoom', () => { done(); }); - happen.dblclick(container); + UIEventSimulator.fire('dblclick', container); }); }); diff --git a/spec/suites/map/handler/Map.DragSpec.js b/spec/suites/map/handler/Map.DragSpec.js index 9561e4ec2b0..a5a2a5bf02d 100644 --- a/spec/suites/map/handler/Map.DragSpec.js +++ b/spec/suites/map/handler/Map.DragSpec.js @@ -174,7 +174,7 @@ describe('Map.Drag', () => { onStop() { // A real user scenario would trigger a click on mouseup. // We want to be sure we are cancelling it after a drag. - happen.click(container); + UIEventSimulator.fire('click', container); expect(dragSpy.called).to.be(true); expect(clickSpy.called).to.be(false); expect(preclickSpy.called).to.be(false); @@ -211,7 +211,7 @@ describe('Map.Drag', () => { onStop() { // A real user scenario would trigger a click on mouseup. // We want to be sure we are cancelling it after a drag. - happen.click(container); + UIEventSimulator.fire('click', container); expect(mapDragSpy.called).to.be(true); expect(markerDragSpy.called).to.be(false); expect(clickSpy.called).to.be(false); @@ -251,7 +251,7 @@ describe('Map.Drag', () => { onStop() { // A real user scenario would trigger a click on mouseup. // We want to be sure we are cancelling it after a drag. - happen.click(marker._icon); + UIEventSimulator.fire('click', marker._icon); expect(markerDragSpy.called).to.be(true); expect(mapDragSpy.called).to.be(false); expect(clickSpy.called).to.be(false); diff --git a/spec/suites/map/handler/Map.KeyboardSpec.js b/spec/suites/map/handler/Map.KeyboardSpec.js index be4e775d88b..61e48e56a5c 100644 --- a/spec/suites/map/handler/Map.KeyboardSpec.js +++ b/spec/suites/map/handler/Map.KeyboardSpec.js @@ -1,12 +1,12 @@ describe('Map.Keyboard', () => { - const KEYCODE_LOWERCASE_A = 65; - const KEYCODE_ARROW_LEFT = 37; - const KEYCODE_ARROW_UP = 38; - const KEYCODE_ARROW_RIGHT = 39; - const KEYCODE_ARROW_DOWN = 40; - const KEYCODE_PLUS = 171; - const KEYCODE_MINUS = 173; - const KEYCODE_ESC = 27; + const KEYCODE_LOWERCASE_A = 'KeyA'; + const KEYCODE_ARROW_LEFT = 'ArrowLeft'; + const KEYCODE_ARROW_UP = 'ArrowUp'; + const KEYCODE_ARROW_RIGHT = 'ArrowRight'; + const KEYCODE_ARROW_DOWN = 'ArrowDown'; + const KEYCODE_PLUS = 'BracketRight'; + const KEYCODE_MINUS = 'Minus'; + const KEYCODE_ESC = 'Escape'; let map, container; @@ -33,33 +33,33 @@ describe('Map.Keyboard', () => { describe('arrow keys', () => { it('move the map north', () => { - happen.keydown(document, {keyCode: KEYCODE_ARROW_UP}); - happen.keypress(document, {keyCode: KEYCODE_ARROW_UP}); - happen.keyup(document, {keyCode: KEYCODE_ARROW_UP}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_ARROW_UP}); + UIEventSimulator.fire('keypress', document, {code: KEYCODE_ARROW_UP}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_ARROW_UP}); expect(map.getCenter().lat).to.be.greaterThan(0); }); it('move the map south', () => { - happen.keydown(document, {keyCode: KEYCODE_ARROW_DOWN}); - happen.keypress(document, {keyCode: KEYCODE_ARROW_DOWN}); - happen.keyup(document, {keyCode: KEYCODE_ARROW_DOWN}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_ARROW_DOWN}); + UIEventSimulator.fire('keypress', document, {code: KEYCODE_ARROW_DOWN}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_ARROW_DOWN}); expect(map.getCenter().lat).to.be.lessThan(0); }); it('move the map west', () => { - happen.keydown(document, {keyCode: KEYCODE_ARROW_LEFT}); - happen.keypress(document, {keyCode: KEYCODE_ARROW_LEFT}); - happen.keyup(document, {keyCode: KEYCODE_ARROW_LEFT}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_ARROW_LEFT}); + UIEventSimulator.fire('keypress', document, {code: KEYCODE_ARROW_LEFT}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_ARROW_LEFT}); expect(map.getCenter().lng).to.be.lessThan(0); }); it('move the map east', () => { - happen.keydown(document, {keyCode: KEYCODE_ARROW_RIGHT}); - happen.keypress(document, {keyCode: KEYCODE_ARROW_RIGHT}); - happen.keyup(document, {keyCode: KEYCODE_ARROW_RIGHT}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_ARROW_RIGHT}); + UIEventSimulator.fire('keypress', document, {code: KEYCODE_ARROW_RIGHT}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_ARROW_RIGHT}); expect(map.getCenter().lng).to.be.greaterThan(0); }); @@ -68,9 +68,9 @@ describe('Map.Keyboard', () => { map.panTo([0, 178], {animate: false}); map.options.worldCopyJump = true; - happen.keydown(document, {keyCode: KEYCODE_ARROW_RIGHT}); - happen.keypress(document, {keyCode: KEYCODE_ARROW_RIGHT}); - happen.keyup(document, {keyCode: KEYCODE_ARROW_RIGHT}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_ARROW_RIGHT}); + UIEventSimulator.fire('keypress', document, {code: KEYCODE_ARROW_RIGHT}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_ARROW_RIGHT}); expect(map.getCenter().lng).to.be.lessThan(-178); }); @@ -78,17 +78,17 @@ describe('Map.Keyboard', () => { describe('plus/minus keys', () => { it('zoom in', () => { - happen.keydown(document, {keyCode: KEYCODE_PLUS}); - happen.keypress(document, {keyCode: KEYCODE_PLUS}); - happen.keyup(document, {keyCode: KEYCODE_PLUS}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_PLUS}); + UIEventSimulator.fire('keypress', document, {code: KEYCODE_PLUS}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_PLUS}); expect(map.getZoom()).to.be.greaterThan(5); }); it('zoom out', () => { - happen.keydown(document, {keyCode: KEYCODE_MINUS}); - happen.keypress(document, {keyCode: KEYCODE_MINUS}); - happen.keyup(document, {keyCode: KEYCODE_MINUS}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_MINUS}); + UIEventSimulator.fire('keypress', document, {code: KEYCODE_MINUS}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_MINUS}); expect(map.getZoom()).to.be.lessThan(5); }); @@ -99,9 +99,9 @@ describe('Map.Keyboard', () => { map.keyboard.disable(); - happen.keydown(document, {keyCode: KEYCODE_PLUS}); - happen.keypress(document, {keyCode: KEYCODE_PLUS}); - happen.keyup(document, {keyCode: KEYCODE_PLUS}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_PLUS}); + UIEventSimulator.fire('keypress', document, {code: KEYCODE_PLUS}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_PLUS}); expect(map.getZoom()).to.eql(5); }); @@ -110,9 +110,9 @@ describe('Map.Keyboard', () => { map.keyboard.disable(); - happen.keydown(document, {keyCode: KEYCODE_ARROW_UP}); - happen.keypress(document, {keyCode: KEYCODE_ARROW_UP}); - happen.keyup(document, {keyCode: KEYCODE_ARROW_UP}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_ARROW_UP}); + UIEventSimulator.fire('keypress', document, {code: KEYCODE_ARROW_UP}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_ARROW_UP}); expect(map.getCenter().lat).to.eql(0); }); @@ -127,8 +127,8 @@ describe('Map.Keyboard', () => { expect(popup.isOpen()).to.be(true); - happen.keydown(document, {keyCode: KEYCODE_ESC}); - happen.keyup(document, {keyCode: KEYCODE_ESC}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_ESC}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_ESC}); expect(popup.isOpen()).to.be(false); }); @@ -142,8 +142,8 @@ describe('Map.Keyboard', () => { expect(popup.isOpen()).to.be(true); - happen.keydown(document, {keyCode: KEYCODE_ESC}); - happen.keyup(document, {keyCode: KEYCODE_ESC}); + UIEventSimulator.fire('keydown', document, {code: KEYCODE_ESC}); + UIEventSimulator.fire('keyup', document, {code: KEYCODE_ESC}); expect(popup.isOpen()).to.be(true); }); @@ -156,7 +156,7 @@ describe('Map.Keyboard', () => { const keyUpSpy = sinon.spy(); map.on('keypress', keyPressSpy); - happen.keypress(container, {keyCode: KEYCODE_LOWERCASE_A}); + UIEventSimulator.fire('keypress', container, {code: KEYCODE_LOWERCASE_A}); setTimeout(() => { expect(keyDownSpy.called).to.be(false); @@ -172,7 +172,7 @@ describe('Map.Keyboard', () => { const keyUpSpy = sinon.spy(); map.on('keydown', keyDownSpy); - happen.keydown(container, {keyCode: KEYCODE_LOWERCASE_A}); + UIEventSimulator.fire('keydown', container, {code: KEYCODE_LOWERCASE_A}); setTimeout(() => { expect(keyDownSpy.called).to.be.ok(); @@ -188,7 +188,7 @@ describe('Map.Keyboard', () => { const keyUpSpy = sinon.spy(); map.on('keyup', keyUpSpy); - happen.keyup(container, {keyCode: KEYCODE_LOWERCASE_A}); + UIEventSimulator.fire('keyup', container, {code: KEYCODE_LOWERCASE_A}); setTimeout(() => { expect(keyDownSpy.called).to.be(false); diff --git a/spec/suites/map/handler/Map.ScrollWheelZoomSpec.js b/spec/suites/map/handler/Map.ScrollWheelZoomSpec.js index 1e90832c2be..c19fdc69922 100644 --- a/spec/suites/map/handler/Map.ScrollWheelZoomSpec.js +++ b/spec/suites/map/handler/Map.ScrollWheelZoomSpec.js @@ -2,12 +2,10 @@ describe('Map.ScrollWheelZoom', () => { let container, map; const wheel = 'onwheel' in window ? 'wheel' : 'mousewheel'; const scrollIn = { - type: wheel, deltaY: -120, deltaMode: 0 }; const scrollOut = { - type: wheel, deltaY: 120, deltaMode: 0 }; @@ -27,7 +25,8 @@ describe('Map.ScrollWheelZoom', () => { it('zooms out while firing \'wheel\' event', (done) => { const zoom = map.getZoom(); - happen.once(container, scrollOut); + + UIEventSimulator.fire(wheel, container, scrollOut); map.on('zoomend', () => { // Bug 1.8.0: Firefox wheel zoom makes 2 steps #7403 @@ -39,7 +38,7 @@ describe('Map.ScrollWheelZoom', () => { it('zooms in while firing \'wheel\' event', (done) => { const zoom = map.getZoom(); - happen.once(container, scrollIn); + UIEventSimulator.fire(wheel, container, scrollIn); map.on('zoomend', () => { // Bug 1.8.0: Firefox wheel zoom makes 2 steps #7403 @@ -53,7 +52,7 @@ describe('Map.ScrollWheelZoom', () => { const scrollWheelZoomBefore = map.options.scrollWheelZoom; map.options.scrollWheelZoom = 'center'; const zoom = map.getZoom(); - happen.once(container, scrollIn); + UIEventSimulator.fire(wheel, container, scrollIn); map.on('zoomend', () => { expect(map.getCenter()).to.be.nearLatLng([0, 0]); @@ -71,9 +70,9 @@ describe('Map.ScrollWheelZoom', () => { const spy = sinon.spy(); map.on('zoomend', spy); - happen.once(container, scrollIn); + UIEventSimulator.fire(wheel, container, scrollIn); setTimeout(() => { - happen.once(container, scrollIn); + UIEventSimulator.fire(wheel, container, scrollIn); expect(spy.notCalled).to.be.ok(); }, 50); @@ -93,7 +92,7 @@ describe('Map.ScrollWheelZoom', () => { map.setZoom(15, {animate: false}); const zoom = map.getZoom(); - happen.once(container, scrollIn); + UIEventSimulator.fire(wheel, container, scrollIn); map.once('zoomend', () => { expect(map.getZoom()).to.be.greaterThan(zoom); @@ -103,7 +102,7 @@ describe('Map.ScrollWheelZoom', () => { expect(map.getZoom()).to.be(zoom); map.options.wheelPxPerZoomLevel = 30 / L.DomEvent.getWheelPxFactor(); - happen.once(container, scrollIn); + UIEventSimulator.fire(wheel, container, scrollIn); map.once('zoomend', () => { expect(map.getZoom()).to.be.greaterThan(zoom); diff --git a/spec/suites/map/handler/Map.TapHoldSpec.js b/spec/suites/map/handler/Map.TapHoldSpec.js index 41b4443c43a..cb2cb77ea18 100644 --- a/spec/suites/map/handler/Map.TapHoldSpec.js +++ b/spec/suites/map/handler/Map.TapHoldSpec.js @@ -25,17 +25,17 @@ describe('Map.TapHoldSpec.js', () => { }); afterEach(() => { - happen.once(container, {type: 'touchend'}); + UIEventSimulator.fire('touchend', container); for (let id = 0; id <= 2; id++) { // reset pointers (for prosphetic-hand) - happen.once(container, {type: 'pointercancel', pointerId:id}); + UIEventSimulator.fire('pointercancel', container, {pointerId:id}); } clock.restore(); removeMapContainer(map, container); }); it('fires synthetic contextmenu after hold delay>600', () => { - happen.once(container, {type: 'touchstart', touches: [posStart]}); - happen.once(container, L.extend({type: 'pointerdown', pointerId:0}, posStart)); + UIEventSimulator.fire('touchstart', container, {touches: [posStart]}); + UIEventSimulator.fire('pointerdown', container, {pointerId:0, ...posStart}); clock.tick(550); expect(spy.notCalled).to.be.ok(); @@ -51,43 +51,46 @@ describe('Map.TapHoldSpec.js', () => { }); it('does not fire contextmenu when touches > 1', () => { - happen.once(container, {type: 'touchstart', touches: [posStart]}); - happen.once(container, L.extend({type: 'pointerdown', pointerId:0}, posStart)); + + UIEventSimulator.fire('touchstart', container, {touches: [posStart]}); + UIEventSimulator.fire('pointerdown', container, {pointerId:0, ...posStart}); clock.tick(100); - happen.once(container, {type: 'touchstart', touches: [posStart, posNear]}); - happen.once(container, L.extend({type: 'pointerdown', pointerId:1}, posNear)); + UIEventSimulator.fire('touchstart', container, {touches: [posStart, posNear]}); + UIEventSimulator.fire('pointerdown', container, {pointerId:1, ...posNear}); clock.tick(550); expect(spy.notCalled).to.be.ok(); }); it('does not fire contextmenu when touches > 1 (case:2)', () => { - happen.once(container, {type: 'touchstart', touches: [posStart]}); - happen.once(container, L.extend({type: 'pointerdown', pointerId:0}, posStart)); + + UIEventSimulator.fire('touchstart', container, {touches: [posStart]}); + UIEventSimulator.fire('pointerdown', container, {pointerId:0, ...posStart}); clock.tick(100); - happen.once(container, {type: 'touchstart', touches: [posStart, posNear]}); - happen.once(container, L.extend({type: 'pointerdown', pointerId:1}, posNear)); + UIEventSimulator.fire('touchstart', container, {touches: [posStart, posNear]}); + UIEventSimulator.fire('pointerdown', container, {pointerId:1, ...posNear}); clock.tick(100); - happen.once(container, {type: 'touchend', touches: [posStart]}); - happen.once(container, L.extend({type: 'pointerup', pointerId:0}, posNear)); + UIEventSimulator.fire('touchend', container, {touches: [posStart]}); + UIEventSimulator.fire('pointerup', container, {pointerId:0, ...posNear}); clock.tick(450); expect(spy.notCalled).to.be.ok(); }); (L.Browser.pointer ? it : it.skip)('ignores events from mouse', () => { - happen.once(container, L.extend({type: 'pointerdown', pointerId:0, pointerType:'mouse'}, posStart)); + UIEventSimulator.fire('pointerdown', container, {pointerId:0, pointerType:'mouse', ...posStart}); clock.tick(650); expect(spy.notCalled).to.be.ok(); }); it('does not conflict with native contextmenu', () => { - happen.once(container, {type: 'touchstart', touches: [posStart]}); - happen.once(container, L.extend({type: 'pointerdown', pointerId:0}, posStart)); + + UIEventSimulator.fire('touchstart', container, {touches: [posStart]}); + UIEventSimulator.fire('pointerdown', container, {pointerId:0, ...posStart}); clock.tick(550); - happen.once(container, {type: 'contextmenu'}); + UIEventSimulator.fire('contextmenu', container); clock.tick(100); @@ -105,22 +108,23 @@ describe('Map.TapHoldSpec.js', () => { const clickSpy = sinon.spy(); map.on('click', clickSpy); - happen.once(container, {type: 'touchstart', touches: [posStart]}); - happen.once(container, L.extend({type: 'pointerdown', pointerId:0}, posStart)); + + UIEventSimulator.fire('touchstart', container, {touches: [posStart]}); + UIEventSimulator.fire('pointerdown', container, {pointerId:0, ...posStart}); clock.tick(650); - happen.once(container, {type: 'touchend', touches: [posStart]}); - happen.once(container, L.extend({type: 'pointerup', pointerId:0}, posNear)); + UIEventSimulator.fire('touchend', container, {touches: [posStart]}); + UIEventSimulator.fire('pointerup', container, {pointerId:0, ...posNear}); expect(clickSpy.notCalled).to.be.ok(); }); it('allows short movements', () => { - happen.once(container, {type: 'touchstart', touches: [posStart]}); - happen.once(container, L.extend({type: 'pointerdown', pointerId:0}, posStart)); + UIEventSimulator.fire('touchstart', container, {touches: [posStart]}); + UIEventSimulator.fire('pointerdown', container, {pointerId:0, ...posStart}); clock.tick(550); - happen.once(container, {type: 'touchmove', touches: [posNear]}); - happen.once(container, L.extend({type: 'pointermove', pointerId:0}, posNear)); + UIEventSimulator.fire('touchmove', container, {touches: [posNear]}); + UIEventSimulator.fire('pointermove', container, {pointerId:0, ...posNear}); clock.tick(100); @@ -131,12 +135,12 @@ describe('Map.TapHoldSpec.js', () => { expect(L.point(posStart.clientX, posStart.clientY).distanceTo([posFar.clientX, posFar.clientY])) .to.be.above(map.options.tapTolerance); - happen.once(container, {type: 'touchstart', touches: [posStart]}); - happen.once(container, L.extend({type: 'pointerdown', pointerId:0}, posStart)); + UIEventSimulator.fire('touchstart', container, {touches: [posStart]}); + UIEventSimulator.fire('pointerdown', container, {pointerId:0, ...posStart}); clock.tick(550); - happen.once(container, {type: 'touchmove', touches: [posFar]}); - happen.once(container, L.extend({type: 'pointermove', pointerId:0}, posFar)); + UIEventSimulator.fire('touchmove', container, {touches: [posFar]}); + UIEventSimulator.fire('pointermove', container, {pointerId:0, ...posFar}); clock.tick(100); @@ -149,8 +153,8 @@ describe('Map.TapHoldSpec.js', () => { screenY: 2, }); - happen.once(container, {type: 'touchstart', touches: [posStart]}); - happen.once(container, L.extend({type: 'pointerdown', pointerId:0}, posStart)); + UIEventSimulator.fire('touchstart', container, {touches: [posStart]}); + UIEventSimulator.fire('pointerdown', container, {pointerId:0, ...posStart}); clock.tick(650); const originalEvent = spy.lastCall.args[0].originalEvent; diff --git a/src/control/Control.Layers.js b/src/control/Control.Layers.js index f8319a624bb..6d063b7f7cb 100644 --- a/src/control/Control.Layers.js +++ b/src/control/Control.Layers.js @@ -199,7 +199,7 @@ export const Layers = Control.extend({ DomEvent.on(link, { keydown(e) { - if (e.keyCode === 13) { + if (e.code === 'Enter') { this._expandSafely(); } }, diff --git a/src/layer/Popup.js b/src/layer/Popup.js index 64237827536..a33b2abff21 100644 --- a/src/layer/Popup.js +++ b/src/layer/Popup.js @@ -502,7 +502,7 @@ Layer.include({ }, _onKeyPress(e) { - if (e.originalEvent.keyCode === 13) { + if (e.originalEvent.code === 'Enter') { this._openPopup(e); } } diff --git a/src/map/handler/Map.BoxZoom.js b/src/map/handler/Map.BoxZoom.js index 9513168d21f..3f66711207f 100644 --- a/src/map/handler/Map.BoxZoom.js +++ b/src/map/handler/Map.BoxZoom.js @@ -137,7 +137,7 @@ export const BoxZoom = Handler.extend({ }, _onKeyDown(e) { - if (e.keyCode === 27) { + if (e.code === 'Escape') { this._finish(); this._clearDeferredResetState(); this._resetState(); diff --git a/src/map/handler/Map.Keyboard.js b/src/map/handler/Map.Keyboard.js index 2dd858f3c89..aa88ef6d62b 100644 --- a/src/map/handler/Map.Keyboard.js +++ b/src/map/handler/Map.Keyboard.js @@ -24,12 +24,12 @@ Map.mergeOptions({ export const Keyboard = Handler.extend({ keyCodes: { - left: [37], - right: [39], - down: [40], - up: [38], - zoomIn: [187, 107, 61, 171], - zoomOut: [189, 109, 54, 173] + left: ['ArrowLeft'], + right: ['ArrowRight'], + down: ['ArrowDown'], + up: ['ArrowUp'], + zoomIn: ['Equal', 'NumpadAdd', 'BracketRight'], + zoomOut: ['Minus', 'NumpadSubtract', 'Digit6', 'Slash'] }, initialize(map) { @@ -140,7 +140,7 @@ export const Keyboard = Handler.extend({ _onKeyDown(e) { if (e.altKey || e.ctrlKey || e.metaKey) { return; } - const key = e.keyCode, + const key = e.code, map = this._map; let offset; @@ -165,7 +165,7 @@ export const Keyboard = Handler.extend({ } else if (key in this._zoomKeys) { map.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]); - } else if (key === 27 && map._popup && map._popup.options.closeOnEscapeKey) { + } else if (key === 'Escape' && map._popup && map._popup.options.closeOnEscapeKey) { map.closePopup(); } else {