wix-style-react
Version:
wix-style-react
88 lines (75 loc) • 2.59 kB
JavaScript
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
import GoogleMapsClient from './GoogleMapsClient';
describe('GoogleMapsClient', function () {
afterEach(function () {
return delete window.google;
});
it('should handle null when autocompleting and getting ZERO_RESULTS', function () {
window.google = new GoogleMapsMock({
getPlacePredictions: function getPlacePredictions(request, callback) {
callback(null, window.google.maps.GeocoderStatus.ZERO_RESULTS);
}
});
var client = new GoogleMapsClient();
return client.autocomplete({ request: {} }).then(function (result) {
expect(result).toEqual([]);
});
});
it('should handle null when geocoding and getting ZERO_RESULTS', function () {
window.google = new GoogleMapsMock(null, {
geocode: function geocode(request, callback) {
callback(null, window.google.maps.GeocoderStatus.ZERO_RESULTS);
}
});
var client = new GoogleMapsClient();
return client.geocode({ request: {} }).then(function (result) {
expect(result).toEqual([]);
});
});
it('should handle null when placeDetails and getting ZERO_RESULTS', function () {
window.google = new GoogleMapsMock(null, null, {
getDetails: function getDetails(request, callback) {
callback(null, window.google.maps.places.PlacesServiceStatus.ZERO_RESULTS);
}
});
var client = new GoogleMapsClient();
return client.placeDetails({ request: {} }).then(function (result) {
expect(result).toEqual(undefined);
});
});
});
function GoogleMapsMock(autocompleteInstance, geocoderInstance, placesServiceInstance) {
var AutocompleteService = function AutocompleteService() {
_classCallCheck(this, AutocompleteService);
return autocompleteInstance;
};
var Geocoder = function Geocoder() {
_classCallCheck(this, Geocoder);
return geocoderInstance;
};
var Map = function Map() {
_classCallCheck(this, Map);
};
var PlacesService = function PlacesService() {
_classCallCheck(this, PlacesService);
return placesServiceInstance;
};
return {
maps: {
Map: Map,
places: {
AutocompleteService: AutocompleteService,
PlacesService: PlacesService,
PlacesServiceStatus: {
OK: 'OK',
ZERO_RESULTS: 'ZERO_RESULTS'
}
},
Geocoder: Geocoder,
GeocoderStatus: {
OK: 'OK',
ZERO_RESULTS: 'ZERO_RESULTS'
}
}
};
}