diff --git a/Tests/local-settings-tests.ts b/Tests/local-settings-tests.ts index ad4f029f7..0caaa49c0 100644 --- a/Tests/local-settings-tests.ts +++ b/Tests/local-settings-tests.ts @@ -1,6 +1,10 @@ - -var TKUnit = require("Tests/TKUnit"); +// +// # Local Settings +// ``` JavaScript var LocalSettings = require("local-settings"); +// ``` +// +var TKUnit = require("Tests/TKUnit"); var stringKey:string = "stringKey"; var boolKey: string = "boolKey"; @@ -9,35 +13,86 @@ var noStringKey: string = "noStringKey"; var noBoolKey: string = "noBoolKey"; var noNumberKey: string = "noNumberKey"; +// +// ## Working with string, number and boolean values +// + // ### set and get boolean value and provide default value in case it is not set + // ``` JavaScript + LocalSettings.setBoolean("boolKey", true); + var boolValue = LocalSettings.getBoolean("boolKey", false); + // ``` + // + TKUnit.assert(true == boolValue, "Cannot set boolean to true"); TKUnit.assert(true == LocalSettings.getBoolean(boolKey), "Cannot set boolean to true (no default)"); }; export var testString = function () { - LocalSettings.setString(stringKey, "String value"); - TKUnit.assert("String value" === LocalSettings.getString(stringKey), "Cannot set string value"); + // + // ### set and get string value + // ``` JavaScript + LocalSettings.setString("stringKey", "String value"); + var stringValue = LocalSettings.getString("stringKey"); + // ``` + // + TKUnit.assert("String value" === stringValue, "Cannot set string value"); }; export var testNumber = function () { - LocalSettings.setNumber(numberKey, 54.321); - var value = LocalSettings.getNumber(numberKey).toFixed(3); + // + // ### Set and get numeric value. We use toFixed() here in order to avoid number based errors + // ``` JavaScript + LocalSettings.setNumber("numberKey", 54.321); + var value = LocalSettings.getNumber("numberKey").toFixed(3); + // ``` + // TKUnit.assert(54.321 == value, "Cannot set number value 54.321 != " + value); }; export var testDefaults = function () { - TKUnit.assert("No string value" === LocalSettings.getString(noStringKey, "No string value"), "Bad default string value"); + // + // ### Reading values that are not set before while providing default value + // ``` JavaScript + var defaultValue = LocalSettings.getString("noStringKey", "No string value"); + //// will return "No string value" if there is no value for "noStringKey" + // ``` + // + TKUnit.assert("No string value" === defaultValue, "Bad default string value"); TKUnit.assert(true === LocalSettings.getBoolean(noBoolKey, true), "Bad default boolean value"); TKUnit.assert(123.45 === LocalSettings.getNumber(noNumberKey, 123.45), "Bad default number value"); + + // + // ### Reading values that are not set before not providing default value + // ``` JavaScript + var defaultValue = LocalSettings.getString("noStringKey"); + //// will return undefined if there is no value for "noStringKey" + // ``` + // + TKUnit.assert("undefined" === typeof defaultValue, "Default string value is not undefined"); + TKUnit.assert("undefined" === LocalSettings.getBoolean(noBoolKey), "Default boolean value is not undefined"); + TKUnit.assert("undefined" === LocalSettings.getNumber(noNumberKey), "Default number value is not undefined"); }; +// +// ## Other functions +// + // ### Checking for existence of value for key + // ``` JavaScript + var hasKey = LocalSettings.hasKey("noBoolKey"); + //// will return false if there is no value for "noBoolKey" + // ``` + // + TKUnit.assert(!hasKey, "There is a key: " + noBoolKey); TKUnit.assert(!LocalSettings.hasKey(noStringKey), "There is a key: " + noStringKey); TKUnit.assert(!LocalSettings.hasKey(noNumberKey), "There is a key: " + noNumberKey); @@ -47,7 +102,12 @@ export var testHasKey = function () { }; export var testRemove = function () { - LocalSettings.remove(boolKey); + // + // ### Removing value for key + // ``` JavaScript + LocalSettings.remove("boolKey"); + // ``` + // TKUnit.assert(!LocalSettings.hasKey(boolKey), "Failed to remove key: " + boolKey); LocalSettings.remove(stringKey); diff --git a/Tests/location-tests.ts b/Tests/location-tests.ts index 45fd92518..ecee6e620 100644 --- a/Tests/location-tests.ts +++ b/Tests/location-tests.ts @@ -96,28 +96,11 @@ export var testLastKnownLocation = function () { function doOnce(options: locationModule.Options) { var locationReceived; - // - // ### Get location once - // if there is `options.timeout` you will receive error on timeout. If `options.timeout` is 0 then the result is the same as the result from `LocationManager.lastKnownLocation` - // and there will be no wait. You can use `options.maximumAge` to specify you don't want to receive locations older than specified time in ms. - // - // ``` JavaScript - // var locationModule = require("location"); - //// options can also look like { maximumAge: 2000, timeout: 20 } - // locationModule.getLocation({ maximumAge: 30000, timeout: 0 }).then(function (location) { - // console.log('Location received: ' + location); - // locationModule.getLocation(options).then(function (location) { locationReceived = true; - // }).fail(function (error) { - //console.log('Location error received: ' + error); - // locationReceived = error; - // }); - // ``` - // var isReady = function () { return locationReceived;