Created
February 28, 2015 20:28
-
-
Save ischenkodv/8f663a4194a12c7474c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('findByNavigator()', function() { | |
var geolocator, fnDone, fnFail; | |
beforeEach(function() { | |
geolocator = new Geolocator({language: 'fi'}); | |
}); | |
it('can find user location', function() { | |
var location, address, components; | |
fnDone = jasmine.createSpy('done').and.callFake(function(l, a, c) { | |
location = l; | |
address = a; | |
components = c; | |
}); | |
fnFail = jasmine.createSpy('fail'); | |
spyOn(geolocator, 'getGeocoder').and.callFake(function(){ | |
var fakeGeolocator = { | |
geocode: function(params, callback) { | |
var result = fakeGeocoderResult; | |
callback(result, google.maps.GeocoderStatus.OK); | |
} | |
}; | |
return fakeGeolocator; | |
}); | |
spyOn(navigator.geolocation, 'getCurrentPosition').and.callFake(function(callback){ | |
var position = { | |
coords: { | |
latitude: 60, | |
longitude: 24 | |
} | |
}; | |
callback(position); | |
}); | |
var request = geolocator.findByNavigator(); | |
request.done(fnDone); | |
request.fail(fnFail); | |
expect(fnDone).toHaveBeenCalled(); | |
expect(fnFail).not.toHaveBeenCalled(); | |
expect(location instanceof google.maps.LatLng).toEqual(true); | |
expect(location.toString()).toEqual('(60, 24)'); | |
expect(address).toEqual('Helsinki, Suomi'); | |
expect(components.location).toEqual(location); | |
expect(components.address).toEqual('Helsinki, Suomi'); | |
expect(components.postcode).toEqual('00100'); | |
expect(components.city).toEqual('Helsinki'); | |
expect(components.country).toEqual('Suomi'); | |
expect(components.region).toEqual('Helsinki'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment