Siema wszystkim! Tydzień temu zacząlem uczyć się testów jednostkowych w jasmine, i nie wiem jak mogę przetestować jedną funckjonalność google map, poniżej kod który chcę przetestować:
class Geolocations
{
constructor(radius_circle,elements,clearSearch,WaitForDataFromDatabase) {
this.radius_circle = radius_circle;
this.elements=elements;
this.clearSearch=clearSearch;
this.WaitForDataFromDatabase=WaitForDataFromDatabase;
}
init(options) {
if(!options.location)
{
return;
}
this.options = options;
this.location = this.options.location;
try {google.maps.event.addDomListener(window, "load", this.makeMap.bind(this)); } catch(e) { return; }
try {google.maps.event.addDomListener(window, "load", this.listener.bind(this)); } catch(e) { return; }
setTimeout(()=>{this.checkAddressValue();},1500);
}
makeMap() {
this.getAllLocationsOnMap();
var loc = this.location.split(","),
pos = new google.maps.LatLng(loc[0], loc[1]);
this.mapOptions =new google.maps.Map(document.querySelector("#map"), {
zoom: 13,
center: pos,
disableDefaultUI: false,
scaleControl: true,
zoomControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl:false,
mapTypeControl: true,
mapTypeControlOptions:
{
position: google.maps.ControlPosition.BOTTOM_LEFT
}
});
this.Map=new google.maps.Map(document.getElementById("map"), this.mapOptions);
this.TableTypeSelectedIcon=[];
this.TableIfIconSelect=[];
this.geokoder=new google.maps.Geocoder();
}
}
var geo=new Geolocations(3000,0,null,null);
geo.init({
location: "51.245412, 22.569592",
});
To tylko kawałek całości ale ten kawałek jest najważniejszy.
A poniżej kod testujący w jasmine:
describe('A Map', function() {
var geo;
beforeEach(function() {
geo=new Geolocations(3000,0,null,null);
geo.init({
location: "51.269262, 22.548271",
});
});
it('Check that map init variables', function() {
expect(geo.radius_circle).toEqual(3000);
expect(geo.elements).toEqual(0);
expect(geo.clearSearch).toBeNull();
expect(geo.WaitForDataFromDatabase).toBeNull();
});
it('Check call function init', function() {
expect(geo.options).toBeDefined();
expect(geo.location).toBeDefined();
});
});
Konstruktor i dwie zmienne w funkcji init przetestowałem, ale utknąłem na zdarzeniach "addDOMListener" nie pojęcia jak je przetestować a w internecie nie mogłem znaleźć niczego konkretnego, jak już mówiłem jeśli chodzi o testy jednostkowe to niedawno zacząłem, więc proszę o wyrozumiałość jeśli dla niektórych jakieś rzeczy są tutaj banalne:)