2017-06-01 7 views
1

私は、このページに地図を表示するためにangular2とopenlayers3を使用しています。これは完全に正常に動作openLayersをトリガーする方法3 'singleClick'をカルマテストから

 this.map.on('singleclick', (e) => { 
      this.showWellDetails(e.pixel); 
     }); 

が、私は私のカルマのテストからであるトリガーする方法がありません - 後singleClick機能は、地図上のマーカーをクリックしたときにポップアップを表示するために使用されます。 このコードブロックはカバーされていません。

編集 - ここだけでなく、テストケースのコードを追加しました -

@Component({ 
    selector: 'test-component-wrapper', 
    template: '<map [markers]="markers" [isDocked]="isDocked" ></map>', 
}) 
class TestComponentWrapper { 
    public isDocked = true; 
    public markers = [ 
     { 
      "latitude": 101.106074, 
      "longitude": 1.307283, 
      "name": "211/27-A17", 
     }, 
     { 
      "latitude": 61.034344, 
      "longitude": 1.703716, 
      "name": "211/29-A17", 
     }, 
    ]; 
} 
describe('MapComponent events',() => { 
    let component: MapComponent; 
    let fixture: ComponentFixture<TestComponentWrapper>; 

    beforeEach(async(() => { 
     TestBed.configureTestingModule({ 
      declarations: [ 
       TestComponentWrapper, 
       MapComponent, 
      ], 
      schemas: [CUSTOM_ELEMENTS_SCHEMA] 
     }) 
      .compileComponents(); 

     fixture = TestBed.createComponent(TestComponentWrapper); 
     component = fixture.debugElement.children[0].componentInstance; 
     fixture.detectChanges(); 
    })); 

    it('should create',() => { 
     expect(component).toBeTruthy(); 
    }); 

    it('should test showDetails functionality',() => { 
     component.isDocked = false; 
     component.initMap(); 
     expect(fixture.debugElement.query(By.css('#mapId'))).not.toBe(null); 
     let pixel = [ 
      233.10227584838867, 
      191.25, 
     ]; 

     // I want to trigger 'singleClick' on map from here... 
     // component.map.singleClick(); 
     // Since this is not working, I have to make showWellDetails function public and call it directly. 
     //at least it adds coverage for this function, but the original block of code mentioned above remains uncovered. 


     component.showWellDetails(pixel); 
     expect(fixture.debugElement.query(By.css('#featureDetails'))).toBe(null); 
     expect(component.locationCoordinate).toBeUndefined(); 
    }); 
    //other tests 
}); 

すべてのヘルプは歓迎です! TIA。私は最終的にそれがこの情報を探している人を助けるかもしれない達成方法

+0

してください、あなたはあなたのユニットテストコードを投稿できますか? – SrAxi

+1

@SrAxi - ポストにテストコードを追加しました –

+0

ちょっと - これで誰でも助けてくれますか? –

答えて

0

-

public singleClickCallback = (e) => { 
     this.showWellDetails(e.pixel); 
} 

this.map.on('singleclick', this.singleClickCallback); 
関連する問題