如何在角度单元测试中触发 openlayer 地图上的选择交互?以下是我选择的事件代码。
let select = new Select({style: null});
select.set('selectInteraction', 'name');
select.on('select', (e) => {
console.log('selected');
});
this.map.addInteraction(select);
在单元测试中,我尝试验证选择事件,如下所示,但无法实现。
it('should verify select event trigger', () => {
const mapEvent = new MapBrowserEvent('select', component.map, new UIEvent('select'));
var evt = new SelectEvent('select', [], [], mapEvent);
// Getting the select interaction to try for some action.
const selectInteraction = component.map.getInteractions().getArray().filter(action => action.get('mySelectInteraction'));
component.map.dispatchEvent(evt);
// here will do my expectation validation.
});
需要一些帮助才能执行此操作。
我自己成功触发了该事件。如果有人需要的话,我会发布答案。
var selectEvent = new SelectEvent('select', selectedFeatures, [], mapEvent);
const selectInteraction = component.map.getInteractions().getArray().filter(action => action.get('mySelectInteraction'));
selectInteraction[0].dispatchEvent(selectEvent);