mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +08:00
updated location and location tests
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import TKUnit = require("Tests/TKUnit");
|
||||
import locationModule = require("location/location");
|
||||
import types = require("location/location_types");
|
||||
|
||||
var LocationManager = locationModule.LocationManager;
|
||||
var Location = locationModule.Location;
|
||||
@ -16,17 +17,19 @@ export var testLocation = function () {
|
||||
locationManager.startLocationMonitoring(function(location) {
|
||||
locationReceived = true;
|
||||
}, function(error) {
|
||||
console.log('Location error received: ' + error);
|
||||
//console.log('Location error received: ' + error);
|
||||
locationReceived = error;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
var isReady = function () {
|
||||
return locationReceived;
|
||||
}
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 3);
|
||||
TKUnit.waitUntilReady(isReady, 10);
|
||||
|
||||
locationManager.stopLocationMonitoring();
|
||||
|
||||
TKUnit.assert(true === locationReceived, locationReceived);
|
||||
};
|
||||
|
||||
@ -46,4 +49,44 @@ export var testLastKnownLocation = function () {
|
||||
var lastKnownLocation = locationManager.lastKnownLocation;
|
||||
TKUnit.assert((lastKnownLocation != null), "There is no last known location");
|
||||
};
|
||||
|
||||
|
||||
function doOnce(options: locationModule.Options) {
|
||||
var locationReceived;
|
||||
locationModule.getLocation(options).then(function (location) {
|
||||
locationReceived = true;
|
||||
}).fail(function (error) {
|
||||
//console.log('Location error received: ' + error);
|
||||
locationReceived = error;
|
||||
});
|
||||
|
||||
var isReady = function () {
|
||||
return locationReceived;
|
||||
}
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 10);
|
||||
|
||||
TKUnit.assert(true === locationReceived, locationReceived);
|
||||
}
|
||||
|
||||
export var testLocationOnce = function () {
|
||||
doOnce(undefined);
|
||||
};
|
||||
|
||||
export var testLocationOnceTimeout0 = function () {
|
||||
doOnce({timeout: 0});
|
||||
};
|
||||
|
||||
export var testLocationOnceMaximumAge = function () {
|
||||
TKUnit.waitUntilReady(function () { return false; }, 2);
|
||||
doOnce({ maximumAge: 3000, timeout: 0 }); // this should pass
|
||||
try {
|
||||
doOnce({ maximumAge: 1000, timeout: 0 });
|
||||
TKUnit.assert(false, "maximumAge check failed");
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
};
|
||||
|
||||
export var testLocationOnceTimeout1000 = function () {
|
||||
doOnce({ timeout: 1000 });
|
||||
};
|
||||
|
Reference in New Issue
Block a user