More convenience with condition chaining
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import DoubleClickZoom from '../../../src/ol/interaction/DoubleClickZoom.js';
|
||||
import DragPan, {
|
||||
defaultCondition,
|
||||
} from '../../../src/ol/interaction/DragPan.js';
|
||||
import DragPan from '../../../src/ol/interaction/DragPan.js';
|
||||
import Feature from '../../../src/ol/Feature.js';
|
||||
import GeoJSON from '../../../src/ol/format/GeoJSON.js';
|
||||
import ImageLayer from '../../../src/ol/layer/Image.js';
|
||||
@@ -29,7 +27,6 @@ import {
|
||||
useGeographic,
|
||||
} from '../../../src/ol/proj.js';
|
||||
import {defaults as defaultInteractions} from '../../../src/ol/interaction.js';
|
||||
import {focusWithTabindex} from '../../../src/ol/events/condition.js';
|
||||
|
||||
describe('ol.Map', function () {
|
||||
describe('constructor', function () {
|
||||
@@ -705,7 +702,7 @@ describe('ol.Map', function () {
|
||||
});
|
||||
|
||||
describe('create interactions', function () {
|
||||
let options;
|
||||
let options, event, hasTabIndex, hasFocus, isPrimary;
|
||||
|
||||
beforeEach(function () {
|
||||
options = {
|
||||
@@ -718,6 +715,33 @@ describe('ol.Map', function () {
|
||||
pinchRotate: false,
|
||||
pinchZoom: false,
|
||||
};
|
||||
hasTabIndex = true;
|
||||
hasFocus = true;
|
||||
isPrimary = true;
|
||||
event = {
|
||||
map: {
|
||||
getTargetElement: function () {
|
||||
return {
|
||||
hasAttribute: function (attribute) {
|
||||
return hasTabIndex;
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
originalEvent: {
|
||||
isPrimary: isPrimary,
|
||||
button: 0,
|
||||
},
|
||||
target: {
|
||||
getTargetElement: function () {
|
||||
return {
|
||||
contains: function () {
|
||||
return hasFocus;
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('create mousewheel interaction', function () {
|
||||
@@ -731,11 +755,19 @@ describe('ol.Map', function () {
|
||||
expect(interactions.item(0).useAnchor_).to.eql(false);
|
||||
expect(interactions.item(0).condition_).to.be(TRUE);
|
||||
});
|
||||
it('uses the focus condition when onFocusOnly option is set', function () {
|
||||
it('does not use the default condition when onFocusOnly option is set', function () {
|
||||
options.onFocusOnly = true;
|
||||
options.mouseWheelZoom = true;
|
||||
const interactions = defaultInteractions(options);
|
||||
expect(interactions.item(0).condition_).to.be(focusWithTabindex);
|
||||
expect(interactions.item(0).condition_).to.not.be(TRUE);
|
||||
hasTabIndex = true;
|
||||
hasFocus = true;
|
||||
expect(interactions.item(0).condition_(event)).to.be(true);
|
||||
hasTabIndex = true;
|
||||
hasFocus = false;
|
||||
expect(interactions.item(0).condition_(event)).to.be(false);
|
||||
hasTabIndex = false;
|
||||
expect(interactions.item(0).condition_(event)).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -745,13 +777,28 @@ describe('ol.Map', function () {
|
||||
const interactions = defaultInteractions(options);
|
||||
expect(interactions.getLength()).to.eql(1);
|
||||
expect(interactions.item(0)).to.be.a(DragPan);
|
||||
expect(interactions.item(0).condition_).to.be(defaultCondition);
|
||||
expect(interactions.item(0).condition_(event)).to.be(true);
|
||||
hasTabIndex = true;
|
||||
hasFocus = false;
|
||||
expect(interactions.item(0).condition_(event)).to.be(true);
|
||||
event.originalEvent.altKey = true;
|
||||
expect(interactions.item(0).condition_(event)).to.be(false);
|
||||
delete event.originalEvent.altKey;
|
||||
event.originalEvent.button = 1;
|
||||
expect(interactions.item(0).condition_(event)).to.be(false);
|
||||
});
|
||||
it('does not use the default condition when onFocusOnly option is set', function () {
|
||||
options.onFocusOnly = true;
|
||||
options.dragPan = true;
|
||||
const interactions = defaultInteractions(options);
|
||||
expect(interactions.item(0).condition_).to.not.be(defaultCondition);
|
||||
hasTabIndex = true;
|
||||
hasFocus = true;
|
||||
expect(interactions.item(0).condition_(event)).to.be(true);
|
||||
hasTabIndex = true;
|
||||
hasFocus = false;
|
||||
expect(interactions.item(0).condition_(event)).to.be(false);
|
||||
hasTabIndex = false;
|
||||
expect(interactions.item(0).condition_(event)).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user