diff --git a/apps/tests/application-settings-tests.ts b/apps/tests/application-settings-tests.ts index b7cb005b7..2ba9cd666 100644 --- a/apps/tests/application-settings-tests.ts +++ b/apps/tests/application-settings-tests.ts @@ -1,10 +1,7 @@ -// -// # Application Settings -// Using application settings methods requires to load "application settings" module. -// ``` JavaScript +// >> application-settings-require var appSettings = require("application-settings"); -// ``` -// +// << application-settings-require + var TKUnit = require("./TKUnit"); var stringKey:string = "stringKey"; @@ -14,72 +11,51 @@ var noStringKey: string = "noStringKey"; var noBoolKey: string = "noBoolKey"; var noNumberKey: string = "noNumberKey"; -// -// ## Working with string, number and boolean values -// - export var testBoolean = function () { appSettings.setBoolean(boolKey, false); var boolValueBefore = appSettings.getBoolean(boolKey); TKUnit.assert(false === boolValueBefore, "Cannot set boolean to false, currently it is: " + appSettings.getBoolean(boolKey)); - // - // ### Set and get boolean value and provide default value in case it is not set - // ``` JavaScript + // >> application-settings-boolean appSettings.setBoolean("boolKey", true); var boolValue = appSettings.getBoolean("boolKey", false); - // ``` - // + // << application-settings-boolean TKUnit.assert(true === boolValue, "Cannot set boolean to true"); TKUnit.assert(true === appSettings.getBoolean(boolKey), "Cannot set boolean to true (no default)"); }; export var testString = function () { - // - // ### Set and get string value - // ``` JavaScript + // >> application-settings-string appSettings.setString("stringKey", "String value"); var stringValue = appSettings.getString("stringKey"); - // ``` - // + // << application-settings-string TKUnit.assert("String value" === stringValue, "Cannot set string value"); }; export var testNumber = function () { - // - // ### Set and get numeric value. - // We use `toFixed()` here in order to avoid floating point errors - ex: `54.321` becoming `54.320999999537`. - // Beware the result of `toFixed()` is a string not a number therefore you cannot use `===` or `!==` when comparing with a number. - // ``` JavaScript + // >> application-settings-number appSettings.setNumber("numberKey", 54.321); var value = parseFloat(appSettings.getNumber("numberKey").toFixed(3)); - // ``` - // + // << application-settings-number TKUnit.assert(54.321 === value, "Cannot set number value 54.321 != " + value); }; export var testDefaults = function () { - // - // ### Reading values that are not set before while providing default value - // ``` JavaScript + // >> application-settings-notset var defaultValue = appSettings.getString("noStringKey", "No string value"); //// will return "No string value" if there is no value for "noStringKey" - // ``` - // + // << application-settings-notset TKUnit.assert("No string value" === defaultValue, "Bad default string value"); TKUnit.assert(true === appSettings.getBoolean(noBoolKey, true), "Bad default boolean value"); TKUnit.assert(123.45 === appSettings.getNumber(noNumberKey, 123.45), "Bad default number value"); } export var testDefaultsWithNoDefaultValueProvided = function () { - // - // ### Reading values that are not set before not providing default value - // ``` JavaScript + // >> application-settings-nodefault var defaultValue = appSettings.getString("noStringKey"); //// will return undefined if there is no value for "noStringKey" - // ``` - // + // << application-settings-nodefault TKUnit.assert("undefined" === typeof defaultValue, "Default string value is not undefined"); TKUnit.assert("undefined" === typeof appSettings.getBoolean(noBoolKey), "Default boolean value is not undefined"); @@ -91,13 +67,10 @@ export var testDefaultsWithNoDefaultValueProvided = function () { // export var testHasKey = function () { - // - // ### Checking for existence of value for key - // ``` JavaScript + // >> application-settings-haskey var hasKey = appSettings.hasKey("noBoolKey"); //// will return false if there is no value for "noBoolKey" - // ``` - // + // << application-settings-haskey TKUnit.assert(!hasKey, "There is a key: " + noBoolKey); TKUnit.assert(!appSettings.hasKey(noStringKey), "There is a key: " + noStringKey); TKUnit.assert(!appSettings.hasKey(noNumberKey), "There is a key: " + noNumberKey); @@ -108,12 +81,9 @@ export var testHasKey = function () { }; export var testRemove = function () { - // - // ### Removing value for key - // ``` JavaScript + // >> application-settings-removekey appSettings.remove("boolKey"); - // ``` - // + // << application-settings-removekey TKUnit.assert(!appSettings.hasKey(boolKey), "Failed to remove key: " + boolKey); appSettings.remove(stringKey); @@ -124,12 +94,9 @@ export var testRemove = function () { }; export var testClear = function () { - // - // ### Removing all values - // ``` JavaScript + // >> application-settings-clear appSettings.clear(); - // ``` - // + // << application-settings-clear TKUnit.assert(!appSettings.hasKey(boolKey), "Failed to remove key: " + boolKey); TKUnit.assert(!appSettings.hasKey(stringKey), "Failed to remove key: " + stringKey); TKUnit.assert(!appSettings.hasKey(numberKey), "Failed to remove key: " + numberKey); diff --git a/apps/tests/application-settings.md b/apps/tests/application-settings.md new file mode 100644 index 000000000..49d263280 --- /dev/null +++ b/apps/tests/application-settings.md @@ -0,0 +1,36 @@ +--- +nav-title: "application-settings How-To" +title: "How-To" +description: "Examples for using application-settings" +--- +# Application Settings +Using application settings methods requires to load "application settings" module. + + +## Working with string, number and boolean values +### Set and get boolean value and provide default value in case it is not set + + +### Set and get string value + + +### Set and get numeric value. +We use `toFixed()` here in order to avoid floating point errors - ex: `54.321` becoming `54.320999999537`. +Beware the result of `toFixed()` is a string not a number therefore you cannot use `===` or `!==` when comparing with a number. + + +### Reading values that are not set before while providing default value + + +### Reading values that are not set before not providing default value + + +## Other functions +### Checking for existence of value for key + + +### Removing value for key + + +### Removing all values + diff --git a/apps/tests/application-tests-common.ts b/apps/tests/application-tests-common.ts index 2f21cabd8..371819a58 100644 --- a/apps/tests/application-tests-common.ts +++ b/apps/tests/application-tests-common.ts @@ -1,26 +1,15 @@ -// -// # Application -// The Application module provides abstraction over the platform-specific Application implementations. -// It is the main BCL module and is required for other BCL modules to work properly. -// The default bootstrap.js implementation for each platform loads and initializes this module. -// ``` JavaScript +// >> application-require import app = require("application"); import platform = require("platform"); -// ``` -// The pre-required `app` module is used throughout the following code snippets. -// +// << application-require -// -// ### Checking the target platform -// Use the following code in case you need to check somewhere in your code the platform you are running against: -// ``` JavaScript +// >> application-app-check if (app.android) { console.log("We are running on Android device!"); } else if (app.ios) { console.log("We are running on iOS device"); } -// ``` -// +// << application-app-check import TKUnit = require("./TKUnit"); diff --git a/apps/tests/application-tests.android.ts b/apps/tests/application-tests.android.ts index 4b453a2be..4d196eae0 100644 --- a/apps/tests/application-tests.android.ts +++ b/apps/tests/application-tests.android.ts @@ -5,32 +5,23 @@ import commonTests = require("./application-tests-common"); global.moduleMerge(commonTests, exports); -// -// ### Using the Android-specific implementation -// Accessing the Android-specific object instance (will be undefined if running on iOS) -// ``` JavaScript +// >> application-app-android var androidApp = app.android; -// ``` -// -// -// ### Using the Android Application context -// ``` JavaScript +// << application-app-android + +// >> application-app-android-context var context = app.android.context; //// get the Files (Documents) folder (directory) var dir = context.getFilesDir(); -// ``` -// -// -// ### Tracking the current Activity -// ``` JavaScript +// << application-app-android-context + +// >> application-app-android-current if (androidApp.foregroundActivity === androidApp.startActivity) { ////console.log("We are currently in the main (start) activity of the application"); } -// ``` -// -// -// ### Registering a Broadcast Receiver (Android) -// ``` JavaScript +// << application-app-android-current + +// >> application-app-android-broadcast //// Register the broadcast receiver if (app.android) { app.android.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED, @@ -45,8 +36,7 @@ if (app.android) { if (app.android) { app.android.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED); } -// ``` -// +// << application-app-android-broadcast export var testAndroidApplicationInitialized = function () { TKUnit.assert(app.android, "Android application not initialized."); diff --git a/apps/tests/application-tests.ios.ts b/apps/tests/application-tests.ios.ts index cc515958d..e0c833e49 100644 --- a/apps/tests/application-tests.ios.ts +++ b/apps/tests/application-tests.ios.ts @@ -5,9 +5,7 @@ import commonTests = require("./application-tests-common"); global.moduleMerge(commonTests, exports); -// -// ### Adding a Notification Observer (iOS) -// ``` JavaScript +// >> application-ios-observer //// Add the notification observer if (app.ios) { var observer = app.ios.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification, @@ -21,5 +19,4 @@ if (app.ios) { if (app.ios) { app.ios.removeNotificationObserver(observer, UIDeviceBatteryLevelDidChangeNotification); } -// ``` -// \ No newline at end of file +// << application-ios-observer \ No newline at end of file diff --git a/apps/tests/application.md b/apps/tests/application.md new file mode 100644 index 000000000..3e72a181b --- /dev/null +++ b/apps/tests/application.md @@ -0,0 +1,32 @@ +--- +nav-title: "application How-To" +title: "How-To" +description: "Examples for using application" +--- +# Application +The Application module provides abstraction over the platform-specific Application implementations. +It is the main BCL module and is required for other BCL modules to work properly. +The default bootstrap.js implementation for each platform loads and initializes this module. + + +The pre-required `app` module is used throughout the following code snippets. +### Checking the target platform +Use the following code in case you need to check somewhere in your code the platform you are running against: + + +### Using the Android-specific implementation +Accessing the Android-specific object instance (will be undefined if running on iOS) + + + +### Using the Android Application context + + +### Tracking the current Activity + + +### Registering a Broadcast Receiver (Android) + + +### Adding a Notification Observer (iOS) + diff --git a/apps/tests/camera-tests.ts b/apps/tests/camera-tests.ts index c1fec0554..bedb973ed 100644 --- a/apps/tests/camera-tests.ts +++ b/apps/tests/camera-tests.ts @@ -1,20 +1,13 @@ import camera = require("camera"); -// -// # Camera module -// Using a camera requires the camera module. -// ``` JavaScript +// >> camera-require // var camera = require("camera"); -// ``` -// +// << camera-require export var test_takePicture = function () { - // - // ### Taking a picture. - // ``` JavaScript + // >> camera-take-picture camera.takePicture().then(result => { //// result is ImageSource }); - // ``` - // + // << camera-take-picture }; diff --git a/apps/tests/camera.md b/apps/tests/camera.md new file mode 100644 index 000000000..ea4a3199d --- /dev/null +++ b/apps/tests/camera.md @@ -0,0 +1,11 @@ +--- +nav-title: "camera How-To" +title: "How-To" +description: "Examples for using camera" +--- +# Camera module +Using a camera requires the camera module. + + +### Taking a picture. + diff --git a/apps/tests/color-tests.ts b/apps/tests/color-tests.ts index 0f921bf15..11a230d7c 100644 --- a/apps/tests/color-tests.ts +++ b/apps/tests/color-tests.ts @@ -1,21 +1,14 @@ -// -// # Color -// Using Colors requires the "color" module. -// ``` JavaScript +// >> color-require import colorModule = require("color"); var Color = colorModule.Color; -// ``` -// +// << color-require import TKUnit = require("./TKUnit"); export var test_Hex_Color = function () { - // - // ### Creating a Color from a hex value. - // ``` JavaScript + // >> color-hex //// Creates the red color var color = new Color("#FF0000"); - // ``` - // + // << color-hex TKUnit.assertEqual(color.a, 255, "Color.a not properly parsed"); TKUnit.assertEqual(color.r, 255, "Color.r not properly parsed"); TKUnit.assertEqual(color.g, 0, "Color.g not properly parsed"); @@ -25,13 +18,10 @@ export var test_Hex_Color = function () { } export var test_ShortHex_Color = function () { - // - // ### Creating a Color from a short hex value. - // ``` JavaScript + // >> color-hex-short //// Creates the color #FF8800 var color = new Color("#F80"); - // ``` - // + // << color-hex-short TKUnit.assertEqual(color.a, 255, "Color.a not properly parsed"); TKUnit.assertEqual(color.r, 255, "Color.r not properly parsed"); TKUnit.assertEqual(color.g, 136, "Color.g not properly parsed"); // 0x88 == 136 @@ -41,13 +31,10 @@ export var test_ShortHex_Color = function () { } export var test_Argb_Color = function () { - // - // ### Creating a Color from four ARGB values - // ``` JavaScript + // >> color-rgb //// Creates the color with 100 alpha, 255 red, 100 green, 100 blue var color = new Color(100, 255, 100, 100); - // ``` - // + // << color-rgb TKUnit.assertEqual(color.a, 100, "Color.a not properly parsed"); TKUnit.assertEqual(color.r, 255, "Color.r not properly parsed"); TKUnit.assertEqual(color.g, 100, "Color.g not properly parsed"); @@ -57,14 +44,11 @@ export var test_Argb_Color = function () { } export var test_ArgbInt_Color = function () { - // - // ### Creating a Color from a single ARGB value - // ``` JavaScript + // >> color-rgb-single //// Creates the color with 100 alpha, 100 red, 100 green, 100 blue var argb = (100 << 24) | (100 << 16) | (100 << 8) | 100; var color = new Color(argb); - // ``` - // + // << color-rgb-single TKUnit.assertEqual(color.a, 100, "Color.a not properly parsed"); TKUnit.assertEqual(color.r, 100, "Color.r not properly parsed"); TKUnit.assertEqual(color.g, 100, "Color.g not properly parsed"); diff --git a/apps/tests/color.md b/apps/tests/color.md new file mode 100644 index 000000000..e863bcc00 --- /dev/null +++ b/apps/tests/color.md @@ -0,0 +1,20 @@ +--- +nav-title: "color How-To" +title: "How-To" +description: "Examples for using color" +--- +# Color +Using Colors requires the "color" module. + + +### Creating a Color from a hex value. + + +### Creating a Color from a short hex value. + + +### Creating a Color from four ARGB values + + +### Creating a Color from a single ARGB value + diff --git a/apps/tests/connectivity-tests.ts b/apps/tests/connectivity-tests.ts index 28f99d95b..5831288a7 100644 --- a/apps/tests/connectivity-tests.ts +++ b/apps/tests/connectivity-tests.ts @@ -1,15 +1,9 @@ -// -// # Connectivity -// Obtaining connectivity information requires the "connectivity" module. -// ``` JavaScript +// >> connectivity-require import connectivity = require("connectivity"); -// ``` -// +// << connectivity-require export var test_DummyTestForSnippetOnly0 = function () { - // - // ### Getting connection type - // ``` JavaScript + // >> connectivity-type var connectionType = connectivity.getConnectionType(); switch (connectionType) { case connectivity.connectionType.none: @@ -22,14 +16,11 @@ export var test_DummyTestForSnippetOnly0 = function () { ////console.log("Mobile connection"); break; } - // ``` - // + // << connectivity-type } export var test_DummyTestForSnippetOnly1 = function () { - // - // ### Monitoring connection type. - // ``` JavaScript + // >> connectivity-monitoring connectivity.startMonitoring(function onConnectionTypeChanged(newConnectionType: number) { switch (newConnectionType) { case connectivity.connectionType.none: @@ -45,6 +36,5 @@ export var test_DummyTestForSnippetOnly1 = function () { }); ////... connectivity.stopMonitoring(); - // ``` - // + // << connectivity-monitoring } \ No newline at end of file diff --git a/apps/tests/connectivity.md b/apps/tests/connectivity.md new file mode 100644 index 000000000..e40458337 --- /dev/null +++ b/apps/tests/connectivity.md @@ -0,0 +1,14 @@ +--- +nav-title: "connectivity How-To" +title: "How-To" +description: "Examples for using connectivity" +--- +# Connectivity +Obtaining connectivity information requires the "connectivity" module. + + +### Getting connection type + + +### Monitoring connection type. + \ No newline at end of file diff --git a/apps/tests/console-tests.ts b/apps/tests/console-tests.ts index beebefb07..f87aff7b2 100644 --- a/apps/tests/console-tests.ts +++ b/apps/tests/console-tests.ts @@ -11,9 +11,9 @@ export var test_DummyTestForSnippetOnly1 = function () { // >> console-time console.time("LoadTime"); // << console-time - // >> console-timeEnd + // >> console-timeend console.timeEnd("LoadTime"); - // << console-timeEnd + // << console-timeend } export var test_DummyTestForSnippetOnly2 = function () { diff --git a/apps/tests/console.md b/apps/tests/console.md index 0accb7510..47071cdd9 100644 --- a/apps/tests/console.md +++ b/apps/tests/console.md @@ -14,7 +14,7 @@ Begins counting a time span for a given name (key). Ends a previously started time span through the time method. - + ### Assert Asserts a boolean condition and prints a message in case the assert fails. diff --git a/apps/tests/fetch-tests.ts b/apps/tests/fetch-tests.ts index 3d7bcfb5d..cee835282 100644 --- a/apps/tests/fetch-tests.ts +++ b/apps/tests/fetch-tests.ts @@ -8,89 +8,77 @@ export var test_fetch_defined = function () { export var test_fetch = function (done: (err: Error, res?: string) => void) { var result; - // - // ### Get Response from URL - // ``` JavaScript + // >> fetch-response fetch("https://httpbin.org/get").then(function (r) { //// Argument (r) is Response! - // + // >> (hide) TKUnit.assert(r instanceof Response, "Result from fetch() should be valid Response object! Actual result is: " + result); done(null); - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << fetch-response }; export var test_fetch_text = function (done: (err: Error, res?: string) => void) { var result; - // - // ### Get string from URL - // ``` JavaScript + // >> fetch-string' fetch("https://httpbin.org/get").then(response => { return response.text(); }).then(function (r) { //// Argument (r) is string! - // + // >> (hide) TKUnit.assert(types.isString(r), "Result from text() should be string! Actual result is: " + r); done(null); - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << fetch-string' }; export var test_fetch_json = function (done: (err: Error, res?: string) => void) { var result; - // - // ### Get JSON from URL - // ``` JavaScript + // >> fetch-json fetch("https://httpbin.org/get").then(response => { return response.json(); }).then(function (r) { //// Argument (r) is JSON object! - // + // >> (hide) TKUnit.assert(types.isString(JSON.stringify(r)), "Result from json() should be JSON object! Actual result is: " + r); done(null); - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << fetch-json }; export var test_fetch_formData = function (done: (err: Error, res?: string) => void) { var result; - // - // ### Get FormData from URL - // ``` JavaScript + // >> fetch-formdata fetch("https://httpbin.org/get").then(response => { return response.formData(); }).then(function (r) { //// Argument (r) is FormData object! - // + // >> (hide) TKUnit.assert(r instanceof FormData, "Result from formData() should be FormData object! Actual result is: " + r); done(null); - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << fetch-formdata }; export var test_fetch_fail_invalid_url = function (done) { @@ -105,13 +93,11 @@ export var test_fetch_fail_invalid_url = function (done) { export var test_fetch_response_status = function (done) { - // - // ### Get Response status - // ``` JavaScript + // >> fetch-status-response fetch("https://httpbin.org/get").then(function (response) { //// Argument (response) is Response! var statusCode = response.status; - // + // >> (hide) try { TKUnit.assert(types.isDefined(statusCode), "response.status should be defined! Actual result is: " + statusCode); done(null); @@ -119,26 +105,23 @@ export var test_fetch_response_status = function (done) { catch (err) { done(err); } - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << fetch-status-response }; export var test_fetch_response_headers = function (done) { - // - // ### Get response headers - // ``` JavaScript + // >> fetch-headers-response fetch("https://httpbin.org/get").then(function (response) { //// Argument (response) is Response! // var all = response.headers.getAll(); - // + // >> (hide) try { TKUnit.assert(types.isDefined(response.headers), "response.headers should be defined! Actual result is: " + response.headers); done(null); @@ -146,15 +129,14 @@ export var test_fetch_response_headers = function (done) { catch (err) { done(err); } - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << fetch-headers-response }; export var test_fetch_headers_sent = function (done) { @@ -202,15 +184,13 @@ export var test_fetch_post_form_data = function (done) { }; export var test_fetch_post_json = function (done) { - // - // ### Post JSON - // ``` JavaScript + // >> fetch-post-json fetch("https://httpbin.org/post", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ MyVariableOne: "ValueOne", MyVariableTwo: "ValueTwo" }) }).then(r => { return r.json(); }).then(function (r) { - // + // >> (hide) try { TKUnit.assert(r.json["MyVariableOne"] === "ValueOne" && r.json["MyVariableTwo"] === "ValueTwo", "Content not sent/received properly! Actual result is: " + r.json); done(null); @@ -218,14 +198,13 @@ export var test_fetch_post_json = function (done) { catch (err) { done(err); } - // + // << (hide) // console.log(result); }, function (e) { - // + // >> (hide) done(e); - // + // << (hide) // console.log("Error occurred " + e); }); - // ``` - // + // << fetch-post-json }; diff --git a/apps/tests/fetch.md b/apps/tests/fetch.md new file mode 100644 index 000000000..096699419 --- /dev/null +++ b/apps/tests/fetch.md @@ -0,0 +1,25 @@ +--- +nav-title: "fetch How-To" +title: "How-To" +description: "Examples for using fetch" +--- +### Get Response from URL + + +### Get string from URL + + +### Get JSON from URL + + +### Get FormData from URL + + +### Get Response status + + +### Get response headers + + +### Post JSON + diff --git a/apps/tests/file-system-tests.ts b/apps/tests/file-system-tests.ts index 97fd2c219..f02ee8069 100644 --- a/apps/tests/file-system-tests.ts +++ b/apps/tests/file-system-tests.ts @@ -1,73 +1,50 @@ /* tslint:disable:no-unused-variable */ -// -// # File System -// Using the file system requires the FileSystem module. -// ``` JavaScript +// >> file-system-require import fs = require("file-system"); -// ``` -// The pre-required `fs` module is used throughout the following code snippets. -// +// << file-system-require import TKUnit = require("./TKUnit"); import appModule = require("application"); import platform = require("platform"); -// -// ## Path -// - export var testPathNormalize = function () { - // - // ### Normalize a Path - // ``` JavaScript + // >> file-system-normalize var documents = fs.knownFolders.documents(); var testPath = "///test.txt"; //// Get a normalized path such as /test.txt from ///test.txt var normalizedPath = fs.path.normalize(documents.path + testPath); - // + // >> (hide) var expected = documents.path + "/test.txt"; TKUnit.assert(normalizedPath === expected); - // - // ``` - // + // << (hide) + // << file-system-normalize }; export var testPathJoin = function () { - // - // ### Path Join - // Concatenate a path to a file by providing multiple path arguments. - // ``` JavaScript + // >> file-system-multiple-args var documents = fs.knownFolders.documents(); //// Generate a path like /myFiles/test.txt var path = fs.path.join(documents.path, "myFiles", "test.txt"); - // + // >> (hide) var expected = documents.path + "/myFiles/test.txt"; TKUnit.assert(path === expected); - // - // ``` - // + // << (hide) + // << file-system-multiple-args }; export var testPathSeparator = function () { - // - // ### Get the Path Separator - // ``` JavaScript + // >> file-system-separator //// An OS dependent path separator, "\" or "/". var separator = fs.path.separator; - // + // >> (hide) var expected = "/"; TKUnit.assert(separator === expected); - // - // ``` - // + // << (hide) + // << file-system-separator }; export var testFileFromPath = function () { - // - // ### Get or Create a File With Path - // The following example writes some text to a file created for path. - // It will create a new file or overwrite an existing file. - // ``` JavaScript + // >> file-system-create var documents = fs.knownFolders.documents(); var path = fs.path.join(documents.path, "FileFromPath.txt"); var file = fs.File.fromPath(path); @@ -76,7 +53,7 @@ export var testFileFromPath = function () { file.writeText("Something") .then(function () { //// Succeeded writing to the file. - // + // >> (hide) file.readText() .then(function (content) { TKUnit.assert(content === "Something", "File read/write not working."); @@ -85,43 +62,31 @@ export var testFileFromPath = function () { TKUnit.assert(false, "Failed to read/write text"); //console.dump(error); }); - // + // << (hide) }, function (error) { //// Failed to write to the file. - // + // >> (hide) TKUnit.assert(false, "Failed to read/write text"); //console.dump(error); - // + // << (hide) }); - // ``` - // + // << file-system-create } export var testFolderFromPath = function () { - // - // ### Get or Create a Folder With Path - // ``` JavaScript + // >> file-system-create-folder var path = fs.path.join(fs.knownFolders.documents().path, "music"); var folder = fs.Folder.fromPath(path); - // + // >> (hide) TKUnit.assert(folder, "Folder.getFolder API not working."); TKUnit.assert(fs.Folder.exists(folder.path), "Folder.getFolder API not working."); folder.remove(); - // - // ``` - // + // << (hide) + // << file-system-create-folder } -// -// ## Create -// - export var testFileWrite = function () { - // - // ### Writing a string to a File - // The following example writes some text to a file. - // It will create a new file or overwrite an existing file. - // ``` JavaScript + // >> file-system-write-string var documents = fs.knownFolders.documents(); var file = documents.getFile("Test_Write.txt"); @@ -129,7 +94,7 @@ export var testFileWrite = function () { file.writeText("Something") .then(function () { //// Succeeded writing to the file. - // + // >> (hide) file.readText() .then(function (content) { TKUnit.assert(content === "Something", "File read/write not working."); @@ -138,57 +103,43 @@ export var testFileWrite = function () { TKUnit.assert(false, "Failed to read/write text"); //console.dump(error); }); - // + // << (hide) }, function (error) { //// Failed to write to the file. - // + // >> (hide) TKUnit.assert(false, "Failed to read/write text"); //console.dump(error); - // + // << (hide) }); - // ``` - // + // << file-system-write-string }; export var testGetFile = function () { - // - // ### Get or Create a File - // ``` JavaScript + // >> file-system-create-file var documents = fs.knownFolders.documents(); var file = documents.getFile("NewFileToCreate.txt"); - // + // >> (hide) TKUnit.assert(file, "File.getFile API not working."); TKUnit.assert(fs.File.exists(file.path), "File.getFile API not working."); file.remove(); - // - // ``` - // + // << (hide) + // << file-system-create-file } export var testGetFolder = function () { - // - // ### Get or Create a Folder - // ``` JavaScript + // >> file-system-get-folder var documents = fs.knownFolders.documents(); var folder = documents.getFolder("NewFolderToCreate"); - // + // >> (hide) TKUnit.assert(folder, "Folder.getFolder API not working."); TKUnit.assert(fs.Folder.exists(folder.path), "Folder.getFolder API not working."); folder.remove(); - // - // ``` - // + // << (hide) + // << file-system-get-folder }; -// -// ## Read -// - export var testFileRead = function () { - // - // ### Reading from a File - // The following example writes some text to a file and then reads it back. - // ``` JavaScript + // >> file-system-example-text var documents = fs.knownFolders.documents(); var myFile = documents.getFile("Test_Write.txt"); @@ -202,33 +153,30 @@ export var testFileRead = function () { myFile.readText() .then(function (content) { //// Successfully read the file's content. - // + // >> (hide) written = content === "Something"; TKUnit.assert(written, "File read/write not working."); myFile.remove(); - // + // << (hide) }, function (error) { //// Failed to read from the file. - // + // >> (hide) TKUnit.assert(false, "Failed to read/write text"); //console.dump(error); - // + // << (hide) }); }, function (error) { //// Failed to write to the file. - // + // >> (hide) TKUnit.assert(false, "Failed to read/write text"); //console.dump(error); - // + // << (hide) }); - // ``` - // + // << file-system-example-text }; export var testFileReadWriteBinary = function () { - // - // ### Reading/writing binary data from/to a File - // ``` JavaScript + // >> file-system-read-binary var fileName = "logo.png"; var error; @@ -239,7 +187,7 @@ export var testFileReadWriteBinary = function () { destinationFile.writeSync(source, e=> { error = e; }); - // + // >> (hide) var destination = destinationFile.readSync(e=> { error = e; }); TKUnit.assertNull(error); if (platform.device.os === platform.platformNames.ios) { @@ -249,39 +197,31 @@ export var testFileReadWriteBinary = function () { } destinationFile.removeSync(); - // - // ``` - // + // << (hide) + // << file-system-read-binary }; export var testGetKnownFolders = function () { - // - // ### Getting the Known Folders - // Each app has several well known folders. This is how to access them: - // ``` JavaScript + // >> file-system-known-folders //// Getting the application's 'documents' folder. var documents = fs.knownFolders.documents(); - // + // >> (hide) TKUnit.assert(documents, "Could not retrieve the Documents known folder."); TKUnit.assert(documents.isKnown, "The Documents folder should have its isKnown property set to true."); - // + // << (hide) //// Getting the application's 'temp' folder. var temp = fs.knownFolders.temp(); - // + // >> (hide) TKUnit.assert(temp, "Could not retrieve the Temporary known folder."); TKUnit.assert(temp.isKnown, "The Temporary folder should have its isKnown property set to true."); - // - // ``` - // + // << (hide) + // << file-system-known-folders }; export var testGetEntities = function () { - // - // ### Getting Folder Contents - // Getting all files and folders within a folder: - // ``` JavaScript + // >> file-system-folders-content var documents = fs.knownFolders.documents(); - // + // >> (hide) var file = documents.getFile("Test.txt"); var file1 = documents.getFile("Test1.txt"); @@ -300,37 +240,32 @@ export var testGetEntities = function () { } }; - // + // << (hide) documents.getEntities() .then(function (entities) { //// entities is array with the document's files and folders. entities.forEach(function (entity) { console.log(entity.name); }); - // + // >> (hide) TKUnit.assert(fileFound, "Failed to enumerate Test.txt"); TKUnit.assert(file1Found, "Failed to enumerate Test1.txt"); file.remove(); file1.remove(); - // + // << (hide) }, function (error) { //// Failed to obtain folder's contents. // globalConsole.error(error.message); }); - // ``` - // + // << file-system-folders-content }; export var testEnumEntities = function () { - // - // ### Enumerating Folder Contents - // Getting all folder entities in array may be slow with large number of files. - // Enumerating the folder entities would iterate the files one by one without blocking the UI. - // ``` JavaScript + // >> file-system-enum-content var documents = fs.knownFolders.documents(); - // + // >> (hide) var file = documents.getFile("Test.txt"); var file1 = documents.getFile("Test1.txt"); var testFolder = documents.getFolder("testFolder"); @@ -348,13 +283,13 @@ export var testEnumEntities = function () { } } } - // + // << (hide) documents.eachEntity(function (entity) { console.log(entity.name); //// Return true to continue, or return false to stop the iteration. return true; }); - // + // >> (hide) TKUnit.assert(fileFound, "Failed to enumerate Test.txt"); TKUnit.assert(file1Found, "Failed to enumerate Test1.txt"); TKUnit.assert(testFolderFound, "Failed to enumerate testFolder"); @@ -362,79 +297,66 @@ export var testEnumEntities = function () { file.remove(); file1.remove(); testFolder.remove(); - // - // ``` - // + // << (hide) + // << file-system-enum-content }; export var testGetParent = function () { - // - // ### Getting Parent Folder - // ``` JavaScript + // >> file-system-parent var documents = fs.knownFolders.documents(); var file = documents.getFile("Test.txt"); - // + // >> (hide) TKUnit.assert(file, "Failed to create file in the Documents folder."); - // + // << (hide) //// The parent folder of the file would be the documents folder. var parent = file.parent; - // + // >> (hide) TKUnit.assert(documents === parent, "The parent folder should be the Documents folder."); file.remove(); - // - // ``` - // + // << (hide) + // << file-system-parent }; export var testFileNameExtension = function () { - // - // ### Getting File Name and Extension - // ``` JavaScript + // >> file-system-extension var documents = fs.knownFolders.documents(); var file = documents.getFile("Test.txt"); //// Getting the file name "Test.txt". var fileName = file.name; //// Getting the file extension ".txt". var fileExtension = file.extension; - // + // >> (hide) TKUnit.assert(fileName === "Test.txt", "Wrong file name."); TKUnit.assert(fileExtension === ".txt", "Wrong extension."); file.remove(); - // - // ``` - // + // << (hide) + // << file-system-extension }; export var testFileExists = function () { - // - // ### Checking if a File Exists - // ``` JavaScript + // >> file-system-fileexists var documents = fs.knownFolders.documents(); var file = documents.getFile("Test.txt"); var exists = fs.File.exists(file.path); - // + // >> (hide) TKUnit.assert(exists, "File.exists API not working."); exists = fs.File.exists(file.path + "_"); TKUnit.assert(!exists, "File.exists API not working."); file.remove(); - // - // ``` - // + // << (hide) + // << file-system-fileexists }; export var testFolderExists = function () { - // - // ### Checking if a Folder Exists - // ``` JavaScript + // >> file-system-folderexists var documents = fs.knownFolders.documents(); var exists = fs.Folder.exists(documents.path); - // + // >> (hide) TKUnit.assert(exists, "Folder.exists API not working."); exists = fs.Folder.exists(documents.path + "_"); TKUnit.assert(!exists, "Folder.exists API not working."); - // - // ``` - // + // << (hide) + // << file-system-folderexists }; export var testContainsFile = function () { @@ -449,143 +371,118 @@ export var testContainsFile = function () { file.remove(); }; -// -// ## Update -// - export var testFileRename = function () { - // - // ### Renaming a File - // ``` JavaScript + // >> file-system-renaming var documents = fs.knownFolders.documents(); var file = documents.getFile("Test.txt"); file.rename("Test_renamed.txt") .then(function (result) { //// Successfully Renamed. - // + // >> (hide) TKUnit.assert(file.name === "Test_renamed.txt", "File.rename API not working."); file.remove(); documents.getFile("Test.txt").remove(); - // + // << (hide) }, function (error) { //// Failed to rename the file. - // + // >> (hide) TKUnit.assert(false, "Failed to rename file"); - // + // << (hide) }); - // ``` - // + // << file-system-renaming }; export var testFolderRename = function () { - // - // ### Renaming a Folder - // ``` JavaScript + // >> file-system-renaming-folder var folder = fs.knownFolders.documents(); var myFolder = folder.getFolder("Test__"); myFolder.rename("Something") .then(function (result) { //// Successfully Renamed. - // + // >> (hide) TKUnit.assert(myFolder.name === "Something", "Folder.rename API not working."); myFolder.remove(); folder.getFolder("Test__").remove(); - // + // << (hide) }, function (error) { //// Failed to rename the folder. - // + // >> (hide) TKUnit.assert(false, "Folder.rename API not working."); - // + // << (hide) }); - // ``` - // + // << file-system-renaming-folder }; -// -// ## Delete -// - export var testFileRemove = function () { - // - // ### Removing a File - // To 'delete', 'remove' or 'unlink' a file use the file's remove method: - // ``` JavaScript + // >> file-system-remove-file var documents = fs.knownFolders.documents(); var file = documents.getFile("AFileToRemove.txt"); file.remove() .then(function (result) { //// Success removing the file. - // + // >> (hide) TKUnit.assert(!fs.File.exists(file.path)); - // + // << (hide) }, function (error) { //// Failed to remove the file. - // + // >> (hide) TKUnit.assert(false, "File.remove API not working."); - // + // << (hide) }); - // ``` - // + // << file-system-remove-file }; export var testFolderRemove = function () { - // - // ### Removing a Folder - // ``` JavaScript + // >> file-system-remove-folder var documents = fs.knownFolders.documents(); var file = documents.getFolder("AFolderToRemove"); //// Remove a folder and recursively its content. file.remove() .then(function (result) { //// Success removing the folder. - // + // >> (hide) TKUnit.assert(!fs.File.exists(file.path)); - // + // << (hide) }, function (error) { //// Failed to remove the folder. - // + // >> (hide) TKUnit.assert(false, "File.remove API not working."); - // + // << (hide) }); - // ``` - // + // << file-system-remove-folder } export var testFolderClear = function () { - // - // ### Clearing the Contents of a Folder - // The clear method removes all files within a folder. - // ``` JavaScript + // >> file-system-clear-folder var documents = fs.knownFolders.documents(); var folder = documents.getFolder("testFolderEmpty"); - // + // >> (hide) folder.getFile("Test1.txt"); folder.getFile("Test2.txt"); var emptied; - // + // << (hide) folder.clear() .then(function () { //// Successfully cleared the folder. - // + // >> (hide) emptied = true; - // + // << (hide) }, function (error) { //// Failed to clear the folder. - // + // >> (hide) TKUnit.assert(false, error.message); - // + // << (hide) }); - // + // >> (hide) folder.getEntities() .then(function (entities) { TKUnit.assert(entities.length === 0, "Failed to clear a Folder"); folder.remove(); }); - // - // ``` - // + // << (hide) + // << file-system-clear-folder }; // misc diff --git a/apps/tests/file-system.md b/apps/tests/file-system.md new file mode 100644 index 000000000..3dd04b30b --- /dev/null +++ b/apps/tests/file-system.md @@ -0,0 +1,91 @@ +--- +nav-title: "file-system How-To" +title: "How-To" +description: "Examples for using file-system" +--- +# File System +Using the file system requires the FileSystem module. + +The pre-required `fs` module is used throughout the following code snippets. +## Path +### Normalize a Path + + +### Path Join +Concatenate a path to a file by providing multiple path arguments. + + +### Get the Path Separator + + +### Get or Create a File With Path +The following example writes some text to a file created for path. +It will create a new file or overwrite an existing file. + + +### Get or Create a Folder With Path + + +## Create +### Writing a string to a File +The following example writes some text to a file. +It will create a new file or overwrite an existing file. + + +### Get or Create a File + + +### Get or Create a Folder + + +## Read +### Reading from a File +The following example writes some text to a file and then reads it back. + + +### Reading/writing binary data from/to a File + + +### Getting the Known Folders +Each app has several well known folders. This is how to access them: + + +### Getting Folder Contents +Getting all files and folders within a folder: + + +### Enumerating Folder Contents +Getting all folder entities in array may be slow with large number of files. +Enumerating the folder entities would iterate the files one by one without blocking the UI. + + +### Getting Parent Folder + + +### Getting File Name and Extension + + +### Checking if a File Exists + + +### Checking if a Folder Exists + + +## Update +### Renaming a File + + +### Renaming a Folder + + +## Delete +### Removing a File +To 'delete', 'remove' or 'unlink' a file use the file's remove method: + + +### Removing a Folder + + +### Clearing the Contents of a Folder +The clear method removes all files within a folder. + diff --git a/apps/tests/fps-meter-tests.ts b/apps/tests/fps-meter-tests.ts index 1f45a8a99..85a328252 100644 --- a/apps/tests/fps-meter-tests.ts +++ b/apps/tests/fps-meter-tests.ts @@ -1,15 +1,9 @@ -// -// # Frames-per-second meter -// Logging frames-per-second statistics for your app requires the "fps-meter" module. -// ``` JavaScript +// >> fps-meter-require import fpsMeter = require("fps-meter"); -// ``` -// +// << fps-meter-require export var test_DummyTestForSnippetOnly0 = function () { - // - // ### Start and stop logging - // ``` JavaScript + // >> fps-meter-logging var callbackId = fpsMeter.addCallback(function (fps: number, minFps: number) { console.info("fps=" + fps + " minFps=" + minFps); }); @@ -17,6 +11,5 @@ export var test_DummyTestForSnippetOnly0 = function () { ////... fpsMeter.removeCallback(callbackId); fpsMeter.stop(); - // ``` - // + // << fps-meter-logging } \ No newline at end of file diff --git a/apps/tests/fps-meter.md b/apps/tests/fps-meter.md new file mode 100644 index 000000000..34d15a86f --- /dev/null +++ b/apps/tests/fps-meter.md @@ -0,0 +1,11 @@ +--- +nav-title: "fps-meter How-To" +title: "How-To" +description: "Examples for using fps-meter" +--- +# Frames-per-second meter +Logging frames-per-second statistics for your app requires the "fps-meter" module. + + +### Start and stop logging + diff --git a/apps/tests/http-tests.ts b/apps/tests/http-tests.ts index 76afefead..a649c62be 100644 --- a/apps/tests/http-tests.ts +++ b/apps/tests/http-tests.ts @@ -5,13 +5,9 @@ import types = require("utils/types"); import fs = require("file-system"); require("globals"); -// -// # Http module -// Using http methods requires to load "http" module. -// ``` JavaScript +// >> http-require // var http = require("http"); -// ``` -// +// << http-require export var test_getString_isDefined = function () { TKUnit.assert(typeof (http.getString) !== "undefined", "Method http.getString() should be defined!"); @@ -20,23 +16,20 @@ export var test_getString_isDefined = function () { export var test_getString = function (done: (err: Error, res?: string) => void) { var result; - // - // ### Get string from URL - // ``` JavaScript + // >> http-get-string http.getString("https://httpbin.org/get").then(function (r) { //// Argument (r) is string! - // + // >> (hide) result = r; done(null); - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << http-get-string }; export var test_getString_fail = function (done) { @@ -73,12 +66,10 @@ export var test_getJSON_isDefined = function () { export var test_getJSON = function (done) { var result; - // - // ### Get JSON from URL - // ``` JavaScript + // >> http-get-json http.getJSON("https://httpbin.org/get").then(function (r) { //// Argument (r) is JSON! - // + // >> (hide) //completed = true; result = r; try { @@ -89,16 +80,15 @@ export var test_getJSON = function (done) { done(e); } done(null); - // + // << (hide) }, function (e) { //// Argument (e) is Error! //console.log(e); - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << http-get-json }; export var test_getJSON_fail = function (done) { @@ -171,12 +161,10 @@ export var test_getImage_isDefined = function () { export var test_getImage = function (done) { var result; - // - // ### Get Image from URL - // ``` JavaScript + // >> http-get-image http.getImage("https://httpbin.org/image/png").then(function (r) { //// Argument (r) is Image! - // + // >> (hide) result = r; try { TKUnit.assert(result instanceof require("image-source").ImageSource, "Result from getImage() should be valid ImageSource object!"); @@ -185,15 +173,14 @@ export var test_getImage = function (done) { catch (err) { done(err); } - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << http-get-image }; export var test_getImage_fail = function (done) { @@ -233,12 +220,10 @@ export var test_getFile_isDefined = function () { export var test_getFile = function (done) { var result; - // - // ### Get File from URL. By default the file will be saved in Documents folder. - // ``` JavaScript + // >> http-get-urlfile http.getFile("https://raw.githubusercontent.com/NativeScript/NativeScript/master/apps/tests/logo.png").then(function (r) { //// Argument (r) is File! - // + // >> (hide) result = r; try { TKUnit.assert(result instanceof fs.File, "Result from getFile() should be valid File object!"); @@ -247,27 +232,24 @@ export var test_getFile = function (done) { catch (err) { done(err); } - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << http-get-urlfile }; export var test_getContentAsFile = function (done) { var result; - // - // ### Get content as File from URL. You can specify where the file should be saved. - // ``` JavaScript + // >> http-get-urlfile-content var filePath = fs.path.join(fs.knownFolders.documents().path, "test.png"); http.getFile("https://httpbin.org/image/png", filePath).then(function (r) { //// Argument (r) is File! - // + // >> (hide) result = r; try { TKUnit.assert(result instanceof fs.File, "Result from getFile() should be valid File object!"); @@ -276,15 +258,14 @@ export var test_getContentAsFile = function (done) { catch (err) { done(err); } - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << http-get-urlfile-content }; export var test_getFile_fail = function (done) { @@ -338,13 +319,11 @@ export var test_request_requestShouldTimeout = function (done) { export var test_request_responseStatusCodeShouldBeDefined = function (done) { var result: http.HttpResponse; - // - // ### Get response status code - // ``` JavaScript + // >> http-get-response http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) { //// Argument (response) is HttpResponse! var statusCode = response.statusCode; - // + // >> (hide) result = response; try { TKUnit.assert(typeof (result.statusCode) !== "undefined", "response.statusCode should be defined!"); @@ -353,29 +332,26 @@ export var test_request_responseStatusCodeShouldBeDefined = function (done) { catch (err) { done(err); } - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << http-get-response }; export var test_request_responseHeadersShouldBeDefined = function (done) { var result: http.HttpResponse; - // - // ### Get response headers - // ``` JavaScript + // >> http-get-response-headers http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) { //// Argument (response) is HttpResponse! //for (var header in response.headers) { // console.log(header + ":" + response.headers[header]); //} - // + // >> (hide) result = response; try { TKUnit.assert(typeof (result.headers) !== "undefined", "response.headers should be defined!"); @@ -384,30 +360,27 @@ export var test_request_responseHeadersShouldBeDefined = function (done) { catch (err) { done(err); } - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << http-get-response-headers }; export var test_request_responseContentShouldBeDefined = function (done) { var result: http.HttpResponse; - // - // ### Get response content - // ``` JavaScript + // >> http-get-response-content http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) { //// Argument (response) is HttpResponse! //// Content property of the response is HttpContent! var str = response.content.toString(); var obj = response.content.toJSON(); var img = response.content.toImage(); - // + // >> (hide) result = response; try { TKUnit.assert(typeof (result.content) !== "undefined", "response.content should be defined!"); @@ -416,15 +389,14 @@ export var test_request_responseContentShouldBeDefined = function (done) { catch (err) { done(err); } - // + // << (hide) }, function (e) { //// Argument (e) is Error! - // + // >> (hide) done(e); - // + // << (hide) }); - // ``` - // + // << http-get-response-content }; export var test_request_responseContentToStringShouldReturnString = function (done) { @@ -629,9 +601,7 @@ export var test_request_NonStringHeadersSentAndReceivedProperly = function (done }; export var test_request_jsonAsContentSentAndReceivedProperly = function (done) { - // - // ### Post JSON - // ``` JavaScript + // >> http-post-json var result; http.request({ @@ -641,7 +611,7 @@ export var test_request_jsonAsContentSentAndReceivedProperly = function (done) { content: JSON.stringify({ MyVariableOne: "ValueOne", MyVariableTwo: "ValueTwo" }) }).then(function (response) { // result = response.content.toJSON(); - // + // >> (hide) result = response.content.toJSON(); try { TKUnit.assert(result["json"]["MyVariableOne"] === "ValueOne" && result["json"]["MyVariableTwo"] === "ValueTwo", "Content not sent/received properly!"); @@ -650,14 +620,13 @@ export var test_request_jsonAsContentSentAndReceivedProperly = function (done) { catch (err) { done(err); } - // + // << (hide) // console.log(result); }, function (e) { - // + // >> (hide) done(e); - // + // << (hide) // console.log("Error occurred " + e); }); - // ``` - // + // << http-post-json }; \ No newline at end of file diff --git a/apps/tests/http.md b/apps/tests/http.md new file mode 100644 index 000000000..126037867 --- /dev/null +++ b/apps/tests/http.md @@ -0,0 +1,35 @@ +--- +nav-title: "http How-To" +title: "How-To" +description: "Examples for using http" +--- +# Http module +Using http methods requires to load "http" module. + + +### Get string from URL + + +### Get JSON from URL + + +### Get Image from URL + + +### Get File from URL. By default the file will be saved in Documents folder. + + +### Get content as File from URL. You can specify where the file should be saved. + + +### Get response status code + + +### Get response headers + + +### Get response content + + +### Post JSON + diff --git a/apps/tests/image-source-tests.ts b/apps/tests/image-source-tests.ts index 6fa2756c3..fed8c82b8 100644 --- a/apps/tests/image-source-tests.ts +++ b/apps/tests/image-source-tests.ts @@ -1,16 +1,10 @@ -// -// # Image source -// Using the image source requires the image-source module. -// ``` JavaScript -//var imageSource = require("image-source"); -// ``` -// The pre-required `imageSource` module is used throughout the following code snippets. -// We also use fs module defined as follows: -// ``` JavaScript -//var fs = require("file-system"); -// ``` -// ## Loading and saving images -// +// >> imagesource-require +// var imageSource = require("image-source"); +// << imagesource-require + +// >> imagesource-require-alt +// var fs = require("file-system"); +// << imagesource-require-alt import imageSource = require("image-source"); import fs = require("file-system"); @@ -24,13 +18,9 @@ var smallImagePath = fs.path.join(__dirname, "/small-image.png"); /* TODO: We need a way to programmatically add an image to resources and then load it from, otherwise we do not know if there is such resource in the target native app. export function testFromResource() { - // - // ### Load image using resource name - // This is similar to loading Bitmap from `R.drawable.logo` on Android or calling `[UIImage imageNamed@"logo"]` on iOS - // ``` JavaScript + // >> imagesource-resname var img = imageSource.fromResource("logo"); - // ``` - // + // << imagesource-resname TKUnit.assert(img.height > 0, "image.fromResource failed"); } */ @@ -38,13 +28,11 @@ export function testFromUrl(done) { //var completed; var result: imageSource.ImageSource; - // - // ### Load image from URL - // ``` JavaScript + // >> imagesource-load-url imageSource.fromUrl("https://www.google.com/images/errors/logo_sm_2.png") .then(function (res: imageSource.ImageSource) { //console.log("Image successfully loaded"); - // + // >> (hide) //completed = true; result = res; try { @@ -55,41 +43,34 @@ export function testFromUrl(done) { catch (e) { done(e); } - // + // << (hide) }, function (error) { //console.log("Error loading image: " + error); - // + // >> (hide) //completed = true; done(error); - // + // << (hide) }); - // ``` - // + // << imagesource-load-url } export function testSaveToFile() { - // - // ### Save image source to PNG or JPG file - // ``` JavaScript + // >> imagesource-save-to var img = imageSource.fromFile(imagePath); var folder = fs.knownFolders.documents(); var path = fs.path.join(folder.path, "Test.png"); var saved = img.saveToFile(path, enums.ImageFormat.png); - // ``` - // + // << imagesource-save-to TKUnit.assert(saved, "Image not saved to file"); TKUnit.assert(fs.File.exists(path), "Image not saved to file"); } export function testFromFile() { - // - // ### Load image from a local file - // ``` JavaScript + // >> imagesource-load-local var folder = fs.knownFolders.documents(); var path = fs.path.join(folder.path, "Test.png"); var img = imageSource.fromFile(path); - // ``` - // + // << imagesource-load-local TKUnit.assert(img.height > 0, "image.fromResource failed"); diff --git a/apps/tests/image-source.md b/apps/tests/image-source.md new file mode 100644 index 000000000..198a9a0f9 --- /dev/null +++ b/apps/tests/image-source.md @@ -0,0 +1,25 @@ +--- +nav-title: "image-source How-To" +title: "How-To" +description: "Examples for using image-source" +--- +# Image source +Using the image source requires the image-source module. + +The pre-required `imageSource` module is used throughout the following code snippets. +We also use fs module defined as follows: + + +## Loading and saving images +### Load image using resource name +This is similar to loading Bitmap from `R.drawable.logo` on Android or calling `[UIImage imageNamed@"logo"]` on iOS + + +### Load image from URL + + +### Save image source to PNG or JPG file + + +### Load image from a local file + diff --git a/apps/tests/location-tests.ts b/apps/tests/location-tests.ts index 8d4028461..1e7c71b5b 100644 --- a/apps/tests/location-tests.ts +++ b/apps/tests/location-tests.ts @@ -1,10 +1,6 @@ -// -// # Location -// Using the location requires the Location module. -// ``` JavaScript +// >> location-require import locationModule = require("location"); -// ``` -// +// << location-require import TKUnit = require("./TKUnit"); @@ -21,29 +17,20 @@ export function tearDown() { locationIsEnabled = undefined; } -// -// ## Other functions -// - export var testIsEnabled = function () { if (!locationIsEnabled) { console.log("Location service is not enabled!!!"); return; } - // - // ### Test are location services available for this device - // ``` JavaScript + // >> location-funcs //var LocationManager = require("location").LocationManager; var isEnabled = LocationManager.isEnabled(); - // ``` - // + // << location-funcs TKUnit.assert(isEnabled); }; export var testDistance = function () { - // - // ### Get distance between two locations - // ``` JavaScript + // >> location-distance //var Location = require("location").Location; var locSofia = new Location(); locSofia.longitude = 42.696552; @@ -52,15 +39,10 @@ export var testDistance = function () { locNewYork.longitude = 40.71448; locNewYork.latitude = -74.00598; var distance = LocationManager.distance(locSofia, locNewYork); - // ``` - // + // << location-distance TKUnit.assert((distance > 10780000) && (distance < 10860000), "invalid distance " + distance); }; -// -// ## Getting location -// - export var testLocation = function (done) { if (!locationIsEnabled) { done(null); @@ -68,15 +50,13 @@ export var testLocation = function (done) { var locationReceived; - // - // ### Receive continuous location updates - // ``` JavaScript + // >> location-updates //var LocationManager = require("location").LocationManager; var locationManager = new LocationManager(); locationManager.startLocationMonitoring(function (location) { //console.log('Location received: ' + location); - // + // >> (hide) locationReceived = true; locationManager.stopLocationMonitoring(); try { @@ -86,19 +66,18 @@ export var testLocation = function (done) { catch (e) { done(e); } - // + // << (hide) }, function (error) { //console.log('Location error received: ' + error); - // + // >> (hide) locationReceived = error; locationManager.stopLocationMonitoring(); done(error); - // + // << (hide) } ); - // ``` - // + // << location-updates //var isReady = function () { // return locationReceived; //} @@ -116,14 +95,11 @@ export var testLastKnownLocation = function () { } TKUnit.waitUntilReady(function () { return false; }, 1); // give it some time after the last test - // - // ### Get last known location - // ``` JavaScript - //var LocationManager = require("location").LocationManager; + // >> location-last-known + // var LocationManager = require("location").LocationManager; var locationManager = new LocationManager(); var lastKnownLocation = locationManager.lastKnownLocation; - // ``` - // + // << location-last-known TKUnit.assert((lastKnownLocation != null), "There is no last known location"); }; @@ -179,27 +155,21 @@ export var testSnippet = function (done) { return done(null); } 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 + // >> location-timeour // var locationModule = require("location"); //// options can also look like { maximumAge: 2000, timeout: 20 * 1000 } locationModule.getLocation({ maximumAge: 30000, timeout: 0 }).then(function (location) { //console.log('Location received: ' + location); - // + // >> (hide) locationReceived = true; done(null); - // + // << (hide) }, function (error) { //console.log('Location error received: ' + error); - // + // >> (hide) locationReceived = error; done(error); - // + // << (hide) }); - // ``` - // + // << location-timeour }; diff --git a/apps/tests/location.md b/apps/tests/location.md new file mode 100644 index 000000000..db66c21d9 --- /dev/null +++ b/apps/tests/location.md @@ -0,0 +1,27 @@ +--- +nav-title: "location How-To" +title: "How-To" +description: "Examples for using location" +--- +# Location +Using the location requires the Location module. + + +## Other functions +### Test are location services available for this device + + +### Get distance between two locations + + +## Getting location +### Receive continuous location updates + + +### Get last known location + + +### 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. + diff --git a/apps/tests/observable-array-tests.ts b/apps/tests/observable-array-tests.ts index e8306b0da..675ab0210 100644 --- a/apps/tests/observable-array-tests.ts +++ b/apps/tests/observable-array-tests.ts @@ -2,93 +2,70 @@ import TKUnit = require("./TKUnit"); import bindableModule = require("ui/core/bindable"); require("globals"); -// -// # Observable Array module -// ``` JavaScript +// >> observable-array-require import observableArrayModule = require("data/observable-array"); -// ``` -// +// << observable-array-require require("globals"); export var test_ObservableArray_shouldCopySourceArrayItems = function () { - // - // ### Create ObservableArray from array. - // ``` JavaScript + // >> observable-array-create var sa = [1, 2, 3]; var array = new observableArrayModule.ObservableArray(sa); - // ``` - // + // << observable-array-create TKUnit.assert(sa.length === array.length && array.length === 3, "ObservableArray should copy all source array items!"); }; export var test_ObservableArray_shouldCopyMultipleItemsAsSource = function () { - // - // ### Create ObservableArray from arguments. - // ``` JavaScript + // >> observable-array-arguments var array = new observableArrayModule.ObservableArray(1, 2, 3); - // ``` - // + // << observable-array-arguments TKUnit.assert(array.length === 3 && array.getItem(1) === 2, "ObservableArray should copy multiple items from source!"); }; export var test_ObservableArray_shouldCreateArrayFromSpecifiedLength = function () { - // - // ### Create ObservableArray with specific length. - // ``` JavaScript + // >> observable-array-length var array = new observableArrayModule.ObservableArray(100); - // ``` - // + // << observable-array-length TKUnit.assert(array.length === 100, "ObservableArray should create array from specified length!"); }; export var test_ObservableArray_shouldBeAbleToSetLength = function () { - // - // ### Set ObservableArray length to new value. - // ``` JavaScript + // >> observable-array-newvalue var array = new observableArrayModule.ObservableArray(100); - // + // >> (hide) TKUnit.assert(array.length === 100, "ObservableArray should create array from specified length!"); - // + // << (hide) array.length = 50; - // ``` - // + // << observable-array-newvalue TKUnit.assert(array.length === 50, "ObservableArray should respect new length!"); }; export var test_ObservableArray_getItemShouldReturnCorrectItem = function () { - // - // ### Get item at specified index using getItem(index) method. - // ``` JavaScript + // >> observable-array-getitem var array = new observableArrayModule.ObservableArray([1, 2, 3]); var firstItem = array.getItem(0); var secondItem = array.getItem(1); var thirdItem = array.getItem(2); - // ``` - // + // << observable-array-getitem TKUnit.assert(firstItem === 1 && secondItem === 2 && thirdItem === 3, "ObservableArray getItem() should return correct item!"); }; export var test_ObservableArray_setItemShouldSetCorrectItem = function () { - // - // ### Set item at specified index using setItem(index, item) method. - // ``` JavaScript + // >> observable-array-setitem var array = new observableArrayModule.ObservableArray([1, 2, 3]); array.setItem(1, 5); - // ``` - // + // << observable-array-setitem TKUnit.assert(array.getItem(1) === 5, "ObservableArray setItem() should set correct item!"); }; export var test_ObservableArray_setItemShouldRaiseCorrectEvent = function () { - // - // ### Set item at specified index using setItem(index, item) method and observe change event data. - // ``` JavaScript + // >> observable-array-eventdata var index: number; var action: string; var addedCount: number; @@ -102,8 +79,7 @@ export var test_ObservableArray_setItemShouldRaiseCorrectEvent = function () { removed = args.removed; // Array of removed items. In this case with single item (2). }); array.setItem(1, 5); - // ``` - // + // << observable-array-eventdata TKUnit.assertEqual(index, 1); TKUnit.assertEqual(action, observableArrayModule.ChangeType.Update); TKUnit.assertEqual(addedCount, 1); @@ -111,51 +87,39 @@ export var test_ObservableArray_setItemShouldRaiseCorrectEvent = function () { }; export var test_ObservableArray_concatShouldReturnNewArrayWithNewItemsAtTheEnd = function () { - // - // ### Use concat() method to combine ObservableArray with array. - // ``` JavaScript + // >> observable-array-combine var array = new observableArrayModule.ObservableArray([1, 2, 3]); var result = array.concat([4, 5, 6]); - // ``` - // + // << observable-array-combine TKUnit.assert(result.length === 6 && result[4] === 5, "ObservableArray concat() should add items at the end!"); }; export var test_ObservableArray_joinShouldReturnStringWithAllItemsSeparatedWithComma = function () { - // - // ### Use join() method to convert ObservableArray to comma separated string. - // ``` JavaScript + // >> observable-array-join var array = new observableArrayModule.ObservableArray([1, 2, 3]); var result = array.join(); - // ``` - // + // >> observable-array-join TKUnit.assert(result === "1,2,3", "ObservableArray join() should return string with all items separated with comma!"); }; export var test_ObservableArray_joinShouldReturnStringWithAllItemsSeparatedWithDot = function () { - // - // ### Use join(separator) method to convert ObservableArray to string separated with specified separator. - // ``` JavaScript + // >> observable-array-join-separator var array = new observableArrayModule.ObservableArray([1, 2, 3]); var result = array.join("."); - // ``` - // + // << observable-array-join-separator TKUnit.assert(result === "1.2.3", "ObservableArray join() should return string with all items separated with dot!"); }; export var test_ObservableArray_popShouldRemoveTheLastElement = function () { - // - // ### Use pop() method to remove the last element. - // ``` JavaScript + // >> observable-array-join-pop' var array = new observableArrayModule.ObservableArray([1, 2, 3]); - // + // >> (hide) var bindable = new bindableModule.Bindable(); bindable.set("testProperty", 0); bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); - // + // << (hide) var result = array.pop(); - // ``` - // + // << observable-array-join-pop' TKUnit.assert(result === 3 && array.length === 2, "ObservableArray pop() should remove last element!"); TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); }; @@ -163,13 +127,11 @@ export var test_ObservableArray_popShouldRemoveTheLastElement = function () { export var test_ObservableArray_popShouldRemoveTheLastElementAndRaiseChangeEventWithCorrectArgs = function () { var result: observableArrayModule.ChangedData; - // - // ### Handle "change" event to know more info about the change after calling pop() method. - // ``` JavaScript + // >> observable-array-join-change var array = new observableArrayModule.ObservableArray([1, 2, 3]); - // + // >> (hide) var index = array.length - 1; - // + // << (hide) array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. @@ -179,32 +141,28 @@ export var test_ObservableArray_popShouldRemoveTheLastElementAndRaiseChangeEvent //// args.removed.length is 1. //// args.addedCount is 0. - // + // >> (hide) result = args; - // + // << (hide) }); array.pop(); - // ``` - // + // << observable-array-join-change TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Delete && result.removed.length === 1 && result.index === index && result.addedCount === 0, "ObservableArray pop() should raise 'change' event with correct args!"); }; export var test_ObservableArray_pushShouldAppendNewElement = function () { - // - // ### Use push() method to add single element to the array. - // ``` JavaScript + // >> observable-array-push var array = new observableArrayModule.ObservableArray([1, 2, 3]); - // + // >> (hide) var bindable = new bindableModule.Bindable(); bindable.set("testProperty", 0); bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); - // + // << (hide) var result = array.push(4); - // ``` - // + // << observable-array-push TKUnit.assert(result === 4 && array.getItem(3) === 4, "ObservableArray push() should append new element!"); TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); }; @@ -212,9 +170,7 @@ export var test_ObservableArray_pushShouldAppendNewElement = function () { export var test_ObservableArray_pushShouldAppendNewElementAndRaiseChangeEventWithCorrectArgs = function () { var result: observableArrayModule.ChangedData; - // - // ### Handle "change" event to know more info about the change after calling push() method with single element. - // ``` JavaScript + // >> observable-array-change-push var array = new observableArrayModule.ObservableArray([1, 2, 3]); array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. @@ -224,32 +180,28 @@ export var test_ObservableArray_pushShouldAppendNewElementAndRaiseChangeEventWit //// args.removed.length is 0. //// args.addedCount is 1. - // + // >> (hide) result = args; - // + // << (hide) }); array.push(4); - // ``` - // + // << observable-array-change-push TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Add && result.removed.length === 0 && result.index === 3 && result.addedCount === 1, "ObservableArray push() should raise 'change' event with correct args!"); }; export var test_ObservableArray_pushShouldAppendNewElements = function () { - // - // ### Use push() method to add multiple elements to the array. - // ``` JavaScript + // >> observable-array-push-multiple var array = new observableArrayModule.ObservableArray([1, 2, 3]); - // + // >> (hide) var bindable = new bindableModule.Bindable(); bindable.set("testProperty", 0); bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); - // + // << (hide) var result = array.push(4, 5, 6); - // ``` - // + // << observable-array-push-multiple TKUnit.assert(result === 6 && array.getItem(5) === 6, "ObservableArray push() should append new elements!"); TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); }; @@ -257,9 +209,7 @@ export var test_ObservableArray_pushShouldAppendNewElements = function () { export var test_ObservableArray_pushShouldAppendNewElementsAndRaiseChangeEventWithCorrectArgs = function () { var result: observableArrayModule.ChangedData; - // - // ### Handle "change" event to know more info about the change after calling push() method with multiple elements. - // ``` JavaScript + // >> observable-array-push-multiple-info var array = new observableArrayModule.ObservableArray([1, 2, 3]); array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. @@ -269,32 +219,28 @@ export var test_ObservableArray_pushShouldAppendNewElementsAndRaiseChangeEventWi //// args.removed.length is 0. //// args.addedCount is equal to the number of added items. - // + // >> (hide) result = args; - // + // << (hide) }); array.push(4, 5, 6); - // ``` - // + // << observable-array-push-multiple-info TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Add && result.removed.length === 0 && result.index === 3 && result.addedCount === 3, "ObservableArray push() should raise 'change' event with correct args!"); }; export var test_ObservableArray_pushShouldAppendNewElementsFromSourceArray = function () { - // - // ### Use push() method to add multiple elements from source array to the ObservableArray. - // ``` JavaScript + // >> observable-array-push-source var array = new observableArrayModule.ObservableArray([1, 2, 3]); - // + // >> (hide) var bindable = new bindableModule.Bindable(); bindable.set("testProperty", 0); bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); - // + // << (hide) var result = array.push([4, 5, 6]); - // ``` - // + // << observable-array-push-source TKUnit.assert(result === 6 && array.getItem(5) === 6, "ObservableArray push() should append new elements from source array!"); TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); }; @@ -302,9 +248,7 @@ export var test_ObservableArray_pushShouldAppendNewElementsFromSourceArray = fun export var test_ObservableArray_pushShouldAppendNewElementsFromSourceArrayAndRaiseChangeEventWithCorrectArgs = function () { var result: observableArrayModule.ChangedData; - // - // ### Handle "change" event to know more info about the change after calling push() method with multiple elements from source array. - // ``` JavaScript + // >> observable-array-push-source-info var array = new observableArrayModule.ObservableArray([1, 2, 3]); array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. @@ -314,43 +258,36 @@ export var test_ObservableArray_pushShouldAppendNewElementsFromSourceArrayAndRai //// args.removed.length is 0. //// args.addedCount is equal to the number of added items. - // + // >> (hide) result = args; - // + // << (hide) }); array.push([4, 5, 6]); - // ``` - // + // << observable-array-push-source-info TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Add && result.removed.length === 0 && result.index === 3 && result.addedCount === 3, "ObservableArray push() should raise 'change' event with correct args!"); }; export var test_ObservableArray_reverseShouldReturnNewReversedArray = function () { - // - // ### Use reverse() method to reverse the elements order of the ObservableArray. - // ``` JavaScript + // >> observable-array-reverse var array = new observableArrayModule.ObservableArray([1, 2, 3]); var result = array.reverse(); - // ``` - // + // << observable-array-reverse TKUnit.assert(result.length === 3 && result[0] === 3, "ObservableArray reverse() should return new reversed array!"); }; export var test_ObservableArray_shiftShouldRemoveTheFirstElement = function () { - // - // ### Use shift() method to remove the first element of the array. - // ``` JavaScript + // >> observable-array-shift var array = new observableArrayModule.ObservableArray([1, 2, 3]); - // + // >> (hide) var bindable = new bindableModule.Bindable(); bindable.set("testProperty", 0); bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); - // + // << (hide) var result = array.shift(); - // ``` - // + // << observable-array-shift TKUnit.assert(result === 1 && array.length === 2, "ObservableArray shift() should remove first element!"); TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); }; @@ -358,9 +295,7 @@ export var test_ObservableArray_shiftShouldRemoveTheFirstElement = function () { export var test_ObservableArray_shiftShouldRemoveTheFirstElementAndRaiseChangeEventWithCorrectArgs = function () { var result: observableArrayModule.ChangedData; - // - // ### Handle "change" event to know more info about the change after calling shift() method. - // ``` JavaScript + // >> observable-array-shift-change var array = new observableArrayModule.ObservableArray([1, 2, 3]); array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { @@ -371,76 +306,60 @@ export var test_ObservableArray_shiftShouldRemoveTheFirstElementAndRaiseChangeEv //// args.removed.length is 1. //// args.addedCount is 0. - // + // >> (hide) result = args; - // + // << (hide) }); array.shift(); - // ``` - // + // << observable-array-shift-change TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Delete && result.removed.length === 1 && result.index === 0 && result.addedCount === 0, "ObservableArray shift() should raise 'change' event with correct args!"); }; export var test_ObservableArray_sliceShouldReturnSectionAsNewArray = function () { - // - // ### Use slice() method to return array with all ObservableArray elements. - // ``` JavaScript + // observable-array-slice var array = new observableArrayModule.ObservableArray([1, 2, 3]); var result = array.slice(); - // ``` - // + // << observable-array-slice TKUnit.assert(result[2] === 3 && result.length === 3, "ObservableArray slice() should return section!"); }; export var test_ObservableArray_sliceWithParamsShouldReturnSectionAsNewArray = function () { - // - // ### Use slice(star, end) method to return section of the array. - // ``` JavaScript + // >> observable-array-slice-args var array = new observableArrayModule.ObservableArray([1, 2, 3, 4, 5]); var result = array.slice(2, 4); - // ``` - // + // << observable-array-slice-args TKUnit.assert(result[1] === 4 && result.length === 2, "ObservableArray slice() should return section according to specified arguments!"); }; export var test_ObservableArray_sortShouldReturnNewSortedArray = function () { - // - // ### Use sort() method to sort the array. - // ``` JavaScript + // >> observable-array-sort var array = new observableArrayModule.ObservableArray([3, 2, 1]); var result = array.sort(); - // ``` - // + // << observable-array-sort TKUnit.assert(result[0] === 1 && result.length === 3, "ObservableArray sort() should return new sorted array!"); }; export var test_ObservableArray_sortShouldReturnNewSortedArrayAccordingSpecifiedOrder = function () { - // - // ### Use sort(compareFunction) method to sort the array with your own comparing logic. - // ``` JavaScript + // >> observable-array-sort-comparer var array = new observableArrayModule.ObservableArray([10, 100, 1]); var result = array.sort((a: number, b: number) => { return a - b; }); - // ``` - // + // << observable-array-sort-comparer TKUnit.assert(result[2] === 100 && result.length === 3, "ObservableArray sort() should return new sorted array according to specified order!"); }; export var test_ObservableArray_spliceShouldRemoveSpecifiedNumberOfElementsStartingFromSpecifiedIndex = function () { - // - // ### Use splice(start, deleteCount) method to delete elements in the array. - // ``` JavaScript + // >> observable-array-splice var array = new observableArrayModule.ObservableArray(["one", "two", "three"]); - // + // >> (hide) var bindable = new bindableModule.Bindable(); bindable.set("testProperty", 0); bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); - // + // << (hide) var result = array.splice(1, 2); - // ``` - // + // <, observable-array-splice TKUnit.assert(result.length === 2 && result[0] === "two" && array.length === 1 && array.getItem(0) === "one", "ObservableArray splice() should remove specified number of elements starting from specified index!"); TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); @@ -449,9 +368,7 @@ export var test_ObservableArray_spliceShouldRemoveSpecifiedNumberOfElementsStart export var test_ObservableArray_spliceShouldRemoveSpecifiedNumberOfElementsStartingFromSpecifiedIndexAndRaiseChangeEventWithCorrectArgs = function () { var result: observableArrayModule.ChangedData; - // - // ### Handle "change" event to know more info about the change after calling splice(start, deleteCount) method. - // ``` JavaScript + // >> observable-array-splice-change var array = new observableArrayModule.ObservableArray([1, 2, 3]); array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { @@ -462,27 +379,23 @@ export var test_ObservableArray_spliceShouldRemoveSpecifiedNumberOfElementsStart //// args.removed.length is equal to the number of deleted items. //// args.addedCount is 0. - // + // >> (hide) result = args; - // + // << (hide) }); array.splice(1, 2); - // ``` - // + // << observable-array-splice-change TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Splice && result.removed.length === 2 && result.index === 1 && result.addedCount === 0, "ObservableArray splice() should raise 'change' event with correct args!"); }; export var test_ObservableArray_spliceShouldInsertNewItemsInPlaceOfRemovedItemsStartingFromSpecifiedIndex = function () { - // - // ### Use splice(start, deleteCount, ...arguments) method to remove and insert elements in the array. - // ``` JavaScript + // >> observable-array-splice-args var array = new observableArrayModule.ObservableArray(["one", "two", "three"]); var result = array.splice(1, 2, "six", "seven"); - // ``` - // + // << observable-array-splice-args TKUnit.assert(result.length === 2 && result[0] === "two" && array.length === 3 && array.getItem(2) === "seven", "ObservableArray splice() should insert new items in place of removed!"); }; @@ -490,9 +403,7 @@ export var test_ObservableArray_spliceShouldInsertNewItemsInPlaceOfRemovedItemsS export var test_ObservableArray_spliceShouldRemoveAndInertSpecifiedNumberOfElementsStartingFromSpecifiedIndexAndRaiseChangeEventWithCorrectArgs = function () { var result: observableArrayModule.ChangedData; - // - // ### Handle "change" event to know more info about the change after calling splice(start, deleteCount, ...arguments) method. - // ``` JavaScript + // >> observable-array-splice-args-change var array = new observableArrayModule.ObservableArray(["one", "two", "three"]); array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { @@ -503,32 +414,28 @@ export var test_ObservableArray_spliceShouldRemoveAndInertSpecifiedNumberOfEleme //// args.removed.length is equal to the number of deleted items. //// args.addedCount is equal to the delta between number of inserted items and number of deleted items but not less than 0. - // + // >> (hide) result = args; - // + // << (hide) }); array.splice(1, 2, "six", "seven", "eight"); - // ``` - // + // << observable-array-splice-args-change TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Splice && result.removed.length === 2 && result.index === 1 && result.addedCount === 1, "ObservableArray splice() should raise 'change' event with correct args!"); }; export var test_ObservableArray_unshiftShouldInsertNewElementsFromTheStart = function () { - // - // ### Use unshift(item1, item2... itemN) method to insert elements from the start of the array. - // ``` JavaScript + // >> observable-array-unshift var array = new observableArrayModule.ObservableArray([1, 2, 3]); - // + // >> (hide) var bindable = new bindableModule.Bindable(); bindable.set("testProperty", 0); bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); - // + // << (hide) var result = array.unshift(4, 5); - // ``` - // + // << observable-array-unshift TKUnit.assert(array.getItem(0) === 4 && result === 5 && array.length === 5, "ObservableArray unshift() should insert new elements from the start!"); TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); @@ -537,9 +444,7 @@ export var test_ObservableArray_unshiftShouldInsertNewElementsFromTheStart = fun export var test_ObservableArray_unshiftShouldInsertNewElementsFromTheStartAndRaiseChangeEventWithCorrectArgs = function () { var result: observableArrayModule.ChangedData; - // - // ### Handle "change" event to know more info about the change after calling unshift(item1, item2... itemN) method. - // ``` JavaScript + // >> observable-array-unshift-change var array = new observableArrayModule.ObservableArray([1, 2, 3]); array.on(observableArrayModule.ObservableArray.changeEvent, (args: observableArrayModule.ChangedData) => { //// Argument (args) is ChangedData. @@ -549,60 +454,47 @@ export var test_ObservableArray_unshiftShouldInsertNewElementsFromTheStartAndRai //// args.removed.length is 0. //// args.addedCount is equal to the number of inserted items. - // + // >> (hide) result = args; - // + // << (hide) }); array.unshift(4, 5); - // ``` - // + // << observable-array-unshift-change TKUnit.assert(result.eventName === observableArrayModule.ObservableArray.changeEvent && result.action === observableArrayModule.ChangeType.Add && result.removed.length === 0 && result.index === 0 && result.addedCount === 2, "ObservableArray unshift() should raise 'change' event with correct args!"); }; export var test_ObservableArray_indexOfShouldReturnCorrectIndex = function () { - // - // ### Use indexOf(item) method to get the index of the desired item in the array. - // ``` JavaScript + // >> observable-array-indexof var array = new observableArrayModule.ObservableArray(["one", "two", "three"]); var result = array.indexOf("two"); - // ``` - // + // << observable-array-indexof TKUnit.assert(result === 1, "ObservableArray indexOf() should return correct index!"); }; export var test_ObservableArray_indexOfShouldReturnCorrectIndexStartingFrom = function () { - // - // ### Use indexOf(item, fromIndex) method to get the index of the desired item in the array starting from specified index. - // ``` JavaScript + // >> observable-array-indexof-args var array = new observableArrayModule.ObservableArray(["one", "two", "three"]); var result = array.indexOf("two", 2); - // ``` - // + // << observable-array-indexof-args TKUnit.assert(result === -1, "ObservableArray indexOf() should return correct index!"); }; export var test_ObservableArray_lastIndexOfShouldReturnCorrectIndex = function () { var array = new observableArrayModule.ObservableArray(["one", "two", "two", "three"]); - // - // ### Use lastIndexOf(item) method to get the last index of the desired item in the array. - // ``` JavaScript + // >> observable-array-lastindexof var result = array.lastIndexOf("two"); - // ``` - // + // << observable-array-lastindexof TKUnit.assert(result === 2, "ObservableArray lastIndexOf() should return correct index!"); }; export var test_ObservableArray_lastIndexOfShouldReturnCorrectIndexStartingFrom = function () { - // - // ### Use lastIndexOf(item, fromIndex) method to get the last index of the desired item in the array starting from specified index. - // ``` JavaScript + // >> observable-array-lastindexof-args var array = new observableArrayModule.ObservableArray(["one", "two", "two", "one", "three"]); var result = array.lastIndexOf("two", 1); - // ``` - // + // << observable-array-lastindexof-args TKUnit.assert(result === 1, "ObservableArray lastIndexOf() should return correct index!"); }; diff --git a/apps/tests/observable-array.md b/apps/tests/observable-array.md new file mode 100644 index 000000000..0d4554450 --- /dev/null +++ b/apps/tests/observable-array.md @@ -0,0 +1,112 @@ +--- +nav-title: "observable-array How-To" +title: "How-To" +description: "Examples for using observable-array" +--- +# Observable Array module + + +### Create ObservableArray from array. + + +### Create ObservableArray from arguments. + + +### Create ObservableArray with specific length. + + +### Set ObservableArray length to new value. + + +### Get item at specified index using getItem(index) method. + + +### Set item at specified index using setItem(index, item) method. + + +### Set item at specified index using setItem(index, item) method and observe change event data. + + +### Use concat() method to combine ObservableArray with array. + + +### Use join() method to convert ObservableArray to comma separated string. + + +### Use join(separator) method to convert ObservableArray to string separated with specified separator. + + +### Use pop() method to remove the last element. + + +### Handle "change" event to know more info about the change after calling pop() method. + + +### Use push() method to add single element to the array. + + +### Handle "change" event to know more info about the change after calling push() method with single element. + + +### Use push() method to add multiple elements to the array. + + +### Handle "change" event to know more info about the change after calling push() method with multiple elements. + + +### Use push() method to add multiple elements from source array to the ObservableArray. + + +### Handle "change" event to know more info about the change after calling push() method with multiple elements from source array. + + +### Use reverse() method to reverse the elements order of the ObservableArray. + + +### Use shift() method to remove the first element of the array. + + +### Handle "change" event to know more info about the change after calling shift() method. + + +### Use slice() method to return array with all ObservableArray elements. + + +### Use slice(star, end) method to return section of the array. + + +### Use sort() method to sort the array. + + +### Use sort(compareFunction) method to sort the array with your own comparing logic. + + +### Use splice(start, deleteCount) method to delete elements in the array. + + +### Handle "change" event to know more info about the change after calling splice(start, deleteCount) method. + + +### Use splice(start, deleteCount, ...arguments) method to remove and insert elements in the array. + + +### Handle "change" event to know more info about the change after calling splice(start, deleteCount, ...arguments) method. + + +### Use unshift(item1, item2... itemN) method to insert elements from the start of the array. + + +### Handle "change" event to know more info about the change after calling unshift(item1, item2... itemN) method. + + +### Use indexOf(item) method to get the index of the desired item in the array. + + +### Use indexOf(item, fromIndex) method to get the index of the desired item in the array starting from specified index. + + +### Use lastIndexOf(item) method to get the last index of the desired item in the array. + + +### Use lastIndexOf(item, fromIndex) method to get the last index of the desired item in the array starting from specified index. + diff --git a/apps/tests/observable-tests.ts b/apps/tests/observable-tests.ts index 8a02dd570..07e3521fb 100644 --- a/apps/tests/observable-tests.ts +++ b/apps/tests/observable-tests.ts @@ -1,10 +1,6 @@ -// -// # Observable -// Using Observable objects requires the "data/observable" module. -// ``` JavaScript +// >> observable-require import observable = require("data/observable"); -// ``` -// +// << observable-require import dependencyObservable = require("ui/core/dependency-observable"); import TKUnit = require("./TKUnit"); @@ -19,9 +15,7 @@ class TestObservable extends observable.Observable { } export var test_Observable_Constructor = function () { - // - // ### Creating an Observable - // ``` JavaScript + // >> observable-creating var json = { Name: "John", Age: 34, @@ -32,17 +26,14 @@ export var test_Observable_Constructor = function () { var age = person.get("Age"); var married = person.get("Married"); //// console.log(name + " " + age + " " + married); // Prints out "John 34 true" if uncommented. - // ``` - // + // << observable-creating TKUnit.assert(name === "John", "Expected name is John"); TKUnit.assert(age === 34, "Expected age is 34"); TKUnit.assert(married === true, "Expected married is true"); } export var tests_DummyTestForCodeSnippet = function () { - // - // ### Responding to property changes - // ``` JavaScript + // >> observable-property-change var person = new observable.Observable(); person.set("Name", "John"); person.set("Age", 34); @@ -55,8 +46,7 @@ export var tests_DummyTestForCodeSnippet = function () { //// If uncommented, the console.log above produces the following output: //// propertyChange Age 35 //// propertyChange Married false - // ``` - // + // << observable-property-change } export var test_Observable_Members = function () { diff --git a/apps/tests/observable.md b/apps/tests/observable.md new file mode 100644 index 000000000..262ded4f9 --- /dev/null +++ b/apps/tests/observable.md @@ -0,0 +1,14 @@ +--- +nav-title: "data/observable How-To" +title: "How-To" +description: "Examples for using data/observable" +--- +# Observable +Using Observable objects requires the "data/observable" module. + + +### Creating an Observable + + +### Responding to property changes + diff --git a/apps/tests/platform-tests.ts b/apps/tests/platform-tests.ts index 3f9e299ca..56cf6924d 100644 --- a/apps/tests/platform-tests.ts +++ b/apps/tests/platform-tests.ts @@ -1,14 +1,9 @@ import TKUnit = require("./TKUnit"); import app = require("application"); -//  -// # Platform -// Information about the current device and screen are defined in the platform module -// ### Declaring platform module to be available for further usage. -// ``` JavaScript +// >> platform-require import platformModule = require("platform"); -// ``` -//  +// << platform-require export function test_setTimeout_isDefined() { var expected; @@ -22,9 +17,7 @@ export function test_setTimeout_isDefined() { }; export function snippet_print_all() { - //  - // ### Getting information about the current device: - // ``` JavaScript + // >> platform-current console.log("Device model: " + platformModule.device.model); console.log("Device type: " + platformModule.device.deviceType); console.log("OS: " + platformModule.device.os); @@ -34,6 +27,5 @@ export function snippet_print_all() { console.log("Screen width: " + platformModule.screen.mainScreen.widthPixels); console.log("Screen height: " + platformModule.screen.mainScreen.heightPixels); console.log("Screen scale: " + platformModule.screen.mainScreen.scale); - // ``` - //  + // << platform-current }; diff --git a/apps/tests/platform.md b/apps/tests/platform.md new file mode 100644 index 000000000..d64cd1aec --- /dev/null +++ b/apps/tests/platform.md @@ -0,0 +1,12 @@ +--- +nav-title: "platform How-To" +title: "How-To" +description: "Examples for using platform" +--- +# Platform +Information about the current device and screen are defined in the platform module +### Declaring platform module to be available for further usage. + + +### Getting information about the current device: + diff --git a/apps/tests/text/formatted-string-tests.ts b/apps/tests/text/formatted-string-tests.ts index a614a6cfe..0558fa3e8 100644 --- a/apps/tests/text/formatted-string-tests.ts +++ b/apps/tests/text/formatted-string-tests.ts @@ -1,20 +1,14 @@ -// -// # Formatted String -// Using a formatted string requires loading formatted-string and span module. -// ``` JavaScript +// >> formatted-string-require import formattedStringModule = require("text/formatted-string"); import spanModule = require("text/span"); -// ``` -// +// << formatted-string-require import observable = require("data/observable"); import TKUnit = require("../TKUnit"); import LabelModule = require("ui/label"); export var test_FormattedString_RemovesEventListeners_for_spans = function () { - // - // ### How to set formatted text content for a label - // ``` JavaScript + // >> formatted-string-set var label = new LabelModule.Label(); var formattedString = new formattedStringModule.FormattedString(); var firstSpan = new spanModule.Span(); @@ -23,8 +17,7 @@ export var test_FormattedString_RemovesEventListeners_for_spans = function () { firstSpan.text = "LoremIpsum"; formattedString.spans.push(firstSpan); label.formattedText = formattedString; - // ``` - // + // << formatted-string-set TKUnit.assert(formattedString.spans.getItem(0).hasListeners(observable.Observable.propertyChangeEvent) === true, "Listener for spans collection change event is not attached!"); var removedSpan = formattedString.spans.pop(); diff --git a/apps/tests/text/formatted-string.md b/apps/tests/text/formatted-string.md new file mode 100644 index 000000000..bcb51f15a --- /dev/null +++ b/apps/tests/text/formatted-string.md @@ -0,0 +1,11 @@ +--- +nav-title: "Formatted String How-To" +title: "How-To" +description: "Examples for using Formatted String" +--- +# Formatted String +Using a formatted string requires loading formatted-string and span module. + + +### How to set formatted text content for a label + diff --git a/apps/tests/timer-tests.ts b/apps/tests/timer-tests.ts index f212e3f6f..5492454e7 100644 --- a/apps/tests/timer-tests.ts +++ b/apps/tests/timer-tests.ts @@ -2,15 +2,11 @@ import platform = require("platform"); var timer = require("timer/timer"); -// -// # Timer module -// ### How to require timer module -// ``` JavaScript +// >> timer-require // require("globals"); //// OR // var timer = require("timer"); -// ``` -// +// << timer-require export var test_setTimeout_isDefined = function () { TKUnit.assert(typeof (timer.setTimeout) !== "undefined", "Method timer.setTimeout() should be defined!"); @@ -32,16 +28,13 @@ export var test_setTimeout = function () { var completed: boolean; var isReady = function () { return completed; } - // - // ### Evaluates an expression after 0 milliseconds. - // ``` JavaScript + // >> timer-set-zero timer.setTimeout(function () { - // + // >> (hide) completed = true; - // + // << (hide) }); - // ``` - // + // << timer-set-zero TKUnit.waitUntilReady(isReady, 0.5); TKUnit.assert(completed, "Callback should be called!"); @@ -51,16 +44,13 @@ export var test_setTimeout_callbackCalledAfterSpecifiedTime = function () { var completed: boolean; var isReady = function () { return completed; } - // - // ### Evaluates an expression after a specified number of milliseconds. - // ``` JavaScript + // >> timer-set-fivehundred timer.setTimeout(function () { - // + // >> (hide) completed = true; - // + // << (hide) }, 500); - // ``` - // + // << timer-set-fivehundred TKUnit.waitUntilReady(isReady, 1); TKUnit.assert(completed, "Callback should be called after specified time!"); @@ -95,20 +85,17 @@ export var test_setTimeout_callbackShouldBeCleared = function () { var completed: boolean; var isReady = function () { return completed; } - // - // ### Cancels the evaluation with the clearTimeout method. - // ``` JavaScript + // >> timer-set-twothousands var id = timer.setTimeout(function () { - // + // >> (hide) completed = true; - // + // << (hide) }, 2000); //// Clear timeout with specified id. timer.clearTimeout(id); - // ``` - // + // << timer-set-twothousands TKUnit.waitUntilReady(isReady, 3); TKUnit.assert(!completed, "Callback should be cleared when clearTimeout() is executed for specified id!"); @@ -119,16 +106,13 @@ export var test_setInterval_callbackCalledDuringPeriod = function () { var expected = 4; var isReady = function () { return counter >= expected; } - // - // ### Evaluates an expression each time a specified number of milliseconds has elapsed. - // ``` JavaScript + // >> timer-set-expression timer.setInterval(function () { - // + // >> (hide) counter++; - // + // << (hide) }, 100); - // ``` - // + // << timer-set-expression TKUnit.waitUntilReady(isReady, 0.5); TKUnit.assert(isReady(), "Callback should be raised at least" + expected + "times! Callback raised " + counter + " times."); @@ -138,17 +122,14 @@ export var test_setInterval_callbackShouldBeCleared = function () { var counter = 0; var isReady = function () { return false; } - // - // ### Cancel the interval previously started using the setInterval method. - // ``` JavaScript + // >> timer-set-interval var id = timer.setInterval(function () { - // + // >> (hide) counter++; - // + // << (hide) timer.clearInterval(id); }, 100); - // ``` - // + // << timer-set-interval TKUnit.waitUntilReady(isReady, 0.5); TKUnit.assert(counter === 1, "Callback should be raised only once!"); diff --git a/apps/tests/timer.md b/apps/tests/timer.md new file mode 100644 index 000000000..1b474e178 --- /dev/null +++ b/apps/tests/timer.md @@ -0,0 +1,23 @@ +--- +nav-title: "timer How-To" +title: "How-To" +description: "Examples for using timer" +--- +# Timer module +### How to require timer module + + +### Evaluates an expression after 0 milliseconds. + + +### Evaluates an expression after a specified number of milliseconds. + + +### Cancels the evaluation with the clearTimeout method. + + +### Evaluates an expression each time a specified number of milliseconds has elapsed. + + +### Cancel the interval previously started using the setInterval method. + diff --git a/apps/tests/trace-tests.ts b/apps/tests/trace-tests.ts index 9bfe976be..d47e3fd66 100644 --- a/apps/tests/trace-tests.ts +++ b/apps/tests/trace-tests.ts @@ -1,25 +1,16 @@ -// -// # Trace -// Tracing information about your app requires the "trace" module. -// ``` JavaScript +// >> trace-require import trace = require("trace"); -// ``` -// +// << trace-require export var test_DummyTestForSnippetOnly0 = function () { - // - // ### Tracing all categories of events. - // ``` JavaScript + // >> trace-all-categories trace.setCategories(trace.categories.All); trace.enable(); - // ``` - // + // << trace-all-categories } export var test_DummyTestForSnippetOnly1 = function () { - // - // ### Tracing specific categories of events. - // ``` JavaScript + // >> trace-specific-categories trace.setCategories(trace.categories.concat( trace.categories.Binding , trace.categories.Debug @@ -31,17 +22,13 @@ export var test_DummyTestForSnippetOnly1 = function () { , trace.categories.VisualTreeEvents )); trace.enable(); - // ``` - // + // << trace-specific-categories } export var test_DummyTestForSnippetOnly2 = function () { - // - // ### Write your own trace message. - // ``` JavaScript + // >> trace-message trace.setCategories(trace.categories.Debug); trace.enable(); trace.write("My Debug Message", trace.categories.Debug); - // ``` - // + // << trace-message } \ No newline at end of file diff --git a/apps/tests/trace.md b/apps/tests/trace.md new file mode 100644 index 000000000..62554639c --- /dev/null +++ b/apps/tests/trace.md @@ -0,0 +1,17 @@ +--- +nav-title: "trace How-To" +title: "How-To" +description: "Examples for using trace" +--- +# Trace +Tracing information about your app requires the "trace" module. + + +### Tracing all categories of events. + + +### Tracing specific categories of events. + + +### Write your own trace message. + diff --git a/apps/tests/ui/action-bar/action-bar-tests-common.ts b/apps/tests/ui/action-bar/action-bar-tests-common.ts index 28b695332..aec620c54 100644 --- a/apps/tests/ui/action-bar/action-bar-tests-common.ts +++ b/apps/tests/ui/action-bar/action-bar-tests-common.ts @@ -8,151 +8,9 @@ import viewModule = require("ui/core/view"); import fs = require("file-system"); import { Observable } from "data/observable"; -// -// # ActionBar -// Using a ActionBar requires the action-bar module. -// ``` JavaScript +// >> actionbar-common-require import actionBarModule = require("ui/action-bar"); -// ``` -// -// ## Setting Title and Icon -//``` XML -// -// -// {%raw%}{%endraw%} -// -// ... -// -//``` -//The icon can only be set in Android platform. It is hidden by default, but you explicitly control its visibility with the `android.iconVisibility' property. -// -// -// ## Setting Custom Title View -//``` XML -// -// -// -// -// -//