mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 20:00:16 +08:00
chore: update tests app short imports
This commit is contained in:
@ -1,7 +1,4 @@
|
|||||||
// >> application-settings-require
|
var appSettings = require("tns-core-modules/application-settings");
|
||||||
var appSettings = require("application-settings");
|
|
||||||
// << application-settings-require
|
|
||||||
|
|
||||||
import * as TKUnit from "../TKUnit";
|
import * as TKUnit from "../TKUnit";
|
||||||
|
|
||||||
var stringKey: string = "stringKey";
|
var stringKey: string = "stringKey";
|
||||||
@ -16,61 +13,51 @@ export var testBoolean = function () {
|
|||||||
var boolValueBefore = appSettings.getBoolean(boolKey);
|
var boolValueBefore = appSettings.getBoolean(boolKey);
|
||||||
TKUnit.assert(false === boolValueBefore, "Cannot set boolean to false, currently it is: " + appSettings.getBoolean(boolKey));
|
TKUnit.assert(false === boolValueBefore, "Cannot set boolean to false, currently it is: " + appSettings.getBoolean(boolKey));
|
||||||
|
|
||||||
// >> application-settings-boolean
|
|
||||||
appSettings.setBoolean("boolKey", true);
|
appSettings.setBoolean("boolKey", true);
|
||||||
var boolValue = appSettings.getBoolean("boolKey", false);
|
var boolValue = appSettings.getBoolean("boolKey", false);
|
||||||
// << application-settings-boolean
|
|
||||||
TKUnit.assert(true === boolValue, "Cannot set boolean to true");
|
TKUnit.assert(true === boolValue, "Cannot set boolean to true");
|
||||||
|
|
||||||
TKUnit.assert(true === appSettings.getBoolean(boolKey), "Cannot set boolean to true (no default)");
|
TKUnit.assert(true === appSettings.getBoolean(boolKey), "Cannot set boolean to true (no default)");
|
||||||
};
|
};
|
||||||
|
|
||||||
export var testString = function () {
|
export var testString = function () {
|
||||||
// >> application-settings-string
|
|
||||||
appSettings.setString("stringKey", "String value");
|
appSettings.setString("stringKey", "String value");
|
||||||
var stringValue = appSettings.getString("stringKey");
|
var stringValue = appSettings.getString("stringKey");
|
||||||
// << application-settings-string
|
|
||||||
TKUnit.assert("String value" === stringValue, "Cannot set string value");
|
TKUnit.assert("String value" === stringValue, "Cannot set string value");
|
||||||
};
|
};
|
||||||
|
|
||||||
export var testNumber = function () {
|
export var testNumber = function () {
|
||||||
// >> application-settings-number
|
|
||||||
appSettings.setNumber("numberKey", 54.321);
|
appSettings.setNumber("numberKey", 54.321);
|
||||||
var value = parseFloat(appSettings.getNumber("numberKey").toFixed(3));
|
var value = parseFloat(appSettings.getNumber("numberKey").toFixed(3));
|
||||||
// << application-settings-number
|
|
||||||
TKUnit.assert(54.321 === value, "Cannot set number value 54.321 != " + value);
|
TKUnit.assert(54.321 === value, "Cannot set number value 54.321 != " + value);
|
||||||
};
|
};
|
||||||
|
|
||||||
export var testDefaults = function () {
|
export var testDefaults = function () {
|
||||||
// >> application-settings-notset
|
|
||||||
var defaultValue = appSettings.getString("noStringKey", "No string value");
|
var defaultValue = appSettings.getString("noStringKey", "No string value");
|
||||||
// will return "No string value" if there is no value for "noStringKey"
|
// 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("No string value" === defaultValue, "Bad default string value");
|
||||||
TKUnit.assert(true === appSettings.getBoolean(noBoolKey, true), "Bad default boolean 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");
|
TKUnit.assert(123.45 === appSettings.getNumber(noNumberKey, 123.45), "Bad default number value");
|
||||||
}
|
}
|
||||||
|
|
||||||
export var testDefaultsWithNoDefaultValueProvided = function () {
|
export var testDefaultsWithNoDefaultValueProvided = function () {
|
||||||
// >> application-settings-nodefault
|
|
||||||
var defaultValue = appSettings.getString("noStringKey");
|
var defaultValue = appSettings.getString("noStringKey");
|
||||||
// will return undefined if there is no value for "noStringKey"
|
// will return undefined if there is no value for "noStringKey"
|
||||||
// << application-settings-nodefault
|
|
||||||
TKUnit.assertEqual(defaultValue, undefined, "Default string value is not undefined");
|
TKUnit.assertEqual(defaultValue, undefined, "Default string value is not undefined");
|
||||||
|
|
||||||
TKUnit.assertEqual(appSettings.getBoolean(noBoolKey), undefined, "Default boolean value is not undefined");
|
TKUnit.assertEqual(appSettings.getBoolean(noBoolKey), undefined, "Default boolean value is not undefined");
|
||||||
TKUnit.assertEqual(appSettings.getNumber(noNumberKey), undefined, "Default number value is not undefined");
|
TKUnit.assertEqual(appSettings.getNumber(noNumberKey), undefined, "Default number value is not undefined");
|
||||||
};
|
};
|
||||||
|
|
||||||
// <snippet module="application-settings" title="application-settings">
|
|
||||||
// ## Other functions
|
|
||||||
// </snippet>
|
|
||||||
|
|
||||||
export var testHasKey = function () {
|
export var testHasKey = function () {
|
||||||
// >> application-settings-haskey
|
|
||||||
var hasKey = appSettings.hasKey("noBoolKey");
|
var hasKey = appSettings.hasKey("noBoolKey");
|
||||||
// will return false if there is no value for "noBoolKey"
|
// will return false if there is no value for "noBoolKey"
|
||||||
// << application-settings-haskey
|
|
||||||
TKUnit.assert(!hasKey, "There is a key: " + noBoolKey);
|
TKUnit.assert(!hasKey, "There is a key: " + noBoolKey);
|
||||||
TKUnit.assert(!appSettings.hasKey(noStringKey), "There is a key: " + noStringKey);
|
TKUnit.assert(!appSettings.hasKey(noStringKey), "There is a key: " + noStringKey);
|
||||||
TKUnit.assert(!appSettings.hasKey(noNumberKey), "There is a key: " + noNumberKey);
|
TKUnit.assert(!appSettings.hasKey(noNumberKey), "There is a key: " + noNumberKey);
|
||||||
@ -81,9 +68,8 @@ export var testHasKey = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testRemove = function () {
|
export var testRemove = function () {
|
||||||
// >> application-settings-removekey
|
|
||||||
appSettings.remove("boolKey");
|
appSettings.remove("boolKey");
|
||||||
// << application-settings-removekey
|
|
||||||
TKUnit.assert(!appSettings.hasKey(boolKey), "Failed to remove key: " + boolKey);
|
TKUnit.assert(!appSettings.hasKey(boolKey), "Failed to remove key: " + boolKey);
|
||||||
|
|
||||||
appSettings.remove(stringKey);
|
appSettings.remove(stringKey);
|
||||||
@ -94,9 +80,8 @@ export var testRemove = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testClear = function () {
|
export var testClear = function () {
|
||||||
// >> application-settings-clear
|
|
||||||
appSettings.clear();
|
appSettings.clear();
|
||||||
// << application-settings-clear
|
|
||||||
TKUnit.assert(!appSettings.hasKey(boolKey), "Failed to remove key: " + boolKey);
|
TKUnit.assert(!appSettings.hasKey(boolKey), "Failed to remove key: " + boolKey);
|
||||||
TKUnit.assert(!appSettings.hasKey(stringKey), "Failed to remove key: " + stringKey);
|
TKUnit.assert(!appSettings.hasKey(stringKey), "Failed to remove key: " + stringKey);
|
||||||
TKUnit.assert(!appSettings.hasKey(numberKey), "Failed to remove key: " + numberKey);
|
TKUnit.assert(!appSettings.hasKey(numberKey), "Failed to remove key: " + numberKey);
|
||||||
@ -104,10 +89,10 @@ export var testClear = function () {
|
|||||||
|
|
||||||
export var testFlush = function () {
|
export var testFlush = function () {
|
||||||
appSettings.setString(stringKey, "String value");
|
appSettings.setString(stringKey, "String value");
|
||||||
// >> application-settings-flush
|
|
||||||
var flushed = appSettings.flush();
|
var flushed = appSettings.flush();
|
||||||
// will return boolean indicating whether flush to disk was successful
|
// will return boolean indicating whether flush to disk was successful
|
||||||
// << application-settings-flush
|
|
||||||
TKUnit.assert(flushed, "Flush failed: " + flushed);
|
TKUnit.assert(flushed, "Flush failed: " + flushed);
|
||||||
TKUnit.assert(appSettings.hasKey(stringKey), "There is no key: " + stringKey);
|
TKUnit.assert(appSettings.hasKey(stringKey), "There is no key: " + stringKey);
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
import * as TKUnit from "../TKUnit";
|
import * as TKUnit from "../TKUnit";
|
||||||
import * as types from "tns-core-modules/utils/types";
|
import * as types from "tns-core-modules/utils/types";
|
||||||
|
|
||||||
// >> virtual-array-require
|
|
||||||
import * as virtualArrayModule from "tns-core-modules/data/virtual-array";
|
import * as virtualArrayModule from "tns-core-modules/data/virtual-array";
|
||||||
// << virtual-array-require
|
|
||||||
|
|
||||||
require("globals");
|
|
||||||
|
|
||||||
export var test_VirtualArray_shouldCreateArrayFromSpecifiedLength = function () {
|
export var test_VirtualArray_shouldCreateArrayFromSpecifiedLength = function () {
|
||||||
var array = new virtualArrayModule.VirtualArray<number>(100);
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
||||||
@ -20,11 +15,9 @@ export var test_VirtualArray_setItemShouldSetCorrectItem = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var test_VirtualArray_setItemShouldRaiseChangeEventWhenYouSetDifferentItem = function () {
|
export var test_VirtualArray_setItemShouldRaiseChangeEventWhenYouSetDifferentItem = function () {
|
||||||
// >> virtual-array-itemsloading
|
|
||||||
var array = new virtualArrayModule.VirtualArray<number>(100);
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
||||||
array.loadSize = 15;
|
array.loadSize = 15;
|
||||||
|
|
||||||
// >> (hide)
|
|
||||||
var result: virtualArrayModule.ChangedData<number>;
|
var result: virtualArrayModule.ChangedData<number>;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
|
||||||
@ -43,7 +36,6 @@ export var test_VirtualArray_setItemShouldRaiseChangeEventWhenYouSetDifferentIte
|
|||||||
|
|
||||||
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Update &&
|
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Update &&
|
||||||
result.removed.length === 1 && result.index === index && result.addedCount === 1, "VirtualArray<T> setItem() should raise 'change' event with correct args!");
|
result.removed.length === 1 && result.index === index && result.addedCount === 1, "VirtualArray<T> setItem() should raise 'change' event with correct args!");
|
||||||
// << (hide)
|
|
||||||
|
|
||||||
array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => {
|
array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => {
|
||||||
// Argument (args) is ItemsLoading.
|
// Argument (args) is ItemsLoading.
|
||||||
@ -64,18 +56,14 @@ export var test_VirtualArray_setItemShouldRaiseChangeEventWhenYouSetDifferentIte
|
|||||||
|
|
||||||
array.load(args.index, itemsToLoad);
|
array.load(args.index, itemsToLoad);
|
||||||
});
|
});
|
||||||
// << virtual-array-itemsloading
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export var test_VirtualArray_loadShouldRaiseChangeEventWithCorrectArgs = function () {
|
export var test_VirtualArray_loadShouldRaiseChangeEventWithCorrectArgs = function () {
|
||||||
// >> virtual-array-change
|
|
||||||
var array = new virtualArrayModule.VirtualArray<number>(100);
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
||||||
array.loadSize = 15;
|
array.loadSize = 15;
|
||||||
|
|
||||||
// >> (hide)
|
|
||||||
var result: virtualArrayModule.ChangedData<number>;
|
var result: virtualArrayModule.ChangedData<number>;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
// << (hide)
|
|
||||||
|
|
||||||
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
|
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
|
||||||
// Argument (args) is ChangedData<T>.
|
// Argument (args) is ChangedData<T>.
|
||||||
@ -83,15 +71,12 @@ export var test_VirtualArray_loadShouldRaiseChangeEventWithCorrectArgs = functio
|
|||||||
// args.action is "update".
|
// args.action is "update".
|
||||||
// args.removed.length and result.addedCount are equal to number of loaded items with load() method.
|
// args.removed.length and result.addedCount are equal to number of loaded items with load() method.
|
||||||
|
|
||||||
// >> (hide)
|
|
||||||
result = args;
|
result = args;
|
||||||
// << (hide)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var itemsToLoad = [0, 1, 2];
|
var itemsToLoad = [0, 1, 2];
|
||||||
|
|
||||||
array.load(index, itemsToLoad);
|
array.load(index, itemsToLoad);
|
||||||
// << virtual-array-change
|
|
||||||
|
|
||||||
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Update &&
|
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Update &&
|
||||||
result.removed.length === itemsToLoad.length && result.index === index && result.addedCount === itemsToLoad.length,
|
result.removed.length === itemsToLoad.length && result.index === index && result.addedCount === itemsToLoad.length,
|
||||||
@ -99,14 +84,11 @@ export var test_VirtualArray_loadShouldRaiseChangeEventWithCorrectArgs = functio
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var test_VirtualArray_lengthIncreaseShouldRaiseChangeEventWithCorrectArgs = function () {
|
export var test_VirtualArray_lengthIncreaseShouldRaiseChangeEventWithCorrectArgs = function () {
|
||||||
// >> virtual-array-lenght
|
|
||||||
var array = new virtualArrayModule.VirtualArray<number>(100);
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
||||||
array.loadSize = 15;
|
array.loadSize = 15;
|
||||||
|
|
||||||
// >> (hide)
|
|
||||||
var result: virtualArrayModule.ChangedData<number>;
|
var result: virtualArrayModule.ChangedData<number>;
|
||||||
var index = array.length;
|
var index = array.length;
|
||||||
// << (hide)
|
|
||||||
|
|
||||||
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
|
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
|
||||||
// Argument (args) is ChangedData<T>.
|
// Argument (args) is ChangedData<T>.
|
||||||
@ -114,13 +96,10 @@ export var test_VirtualArray_lengthIncreaseShouldRaiseChangeEventWithCorrectArgs
|
|||||||
// args.action is "add".
|
// args.action is "add".
|
||||||
// args.removed.length is 0, result.addedCount is equal to the delta between new and old "length" property values.
|
// args.removed.length is 0, result.addedCount is equal to the delta between new and old "length" property values.
|
||||||
|
|
||||||
// >> (hide)
|
|
||||||
result = args;
|
result = args;
|
||||||
// << (hide)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
array.length += array.loadSize;
|
array.length += array.loadSize;
|
||||||
// << virtual-array-lenght
|
|
||||||
|
|
||||||
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Add
|
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Add
|
||||||
&& result.index === index && result.addedCount === array.loadSize && result.removed.length === 0,
|
&& result.index === index && result.addedCount === array.loadSize && result.removed.length === 0,
|
||||||
@ -128,16 +107,11 @@ export var test_VirtualArray_lengthIncreaseShouldRaiseChangeEventWithCorrectArgs
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var test_VirtualArray_lengthDecreaseShouldRaiseChangeEventWithCorrectArgs = function () {
|
export var test_VirtualArray_lengthDecreaseShouldRaiseChangeEventWithCorrectArgs = function () {
|
||||||
// <snippet module="data/virtual-array" title="virtual-array">
|
|
||||||
// ### Handle "change" event when you increase "length" property.
|
|
||||||
// ``` JavaScript
|
|
||||||
var array = new virtualArrayModule.VirtualArray<number>(100);
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
||||||
array.loadSize = 15;
|
array.loadSize = 15;
|
||||||
|
|
||||||
// <hide>
|
|
||||||
var result: virtualArrayModule.ChangedData<number>;
|
var result: virtualArrayModule.ChangedData<number>;
|
||||||
var index = array.length;
|
var index = array.length;
|
||||||
// </hide>
|
|
||||||
|
|
||||||
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
|
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
|
||||||
// Argument (args) is ChangedData<T>.
|
// Argument (args) is ChangedData<T>.
|
||||||
@ -145,9 +119,7 @@ export var test_VirtualArray_lengthDecreaseShouldRaiseChangeEventWithCorrectArgs
|
|||||||
// args.action is "remove".
|
// args.action is "remove".
|
||||||
// result.addedCount is 0, args.removed.length is equal to the delta between new and old "length" property values.
|
// result.addedCount is 0, args.removed.length is equal to the delta between new and old "length" property values.
|
||||||
|
|
||||||
// <hide>
|
|
||||||
result = args;
|
result = args;
|
||||||
// </hide>
|
|
||||||
});
|
});
|
||||||
|
|
||||||
array.length -= array.loadSize;
|
array.length -= array.loadSize;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
require("globals");
|
|
||||||
import * as http from "tns-core-modules/http";
|
import * as http from "tns-core-modules/http";
|
||||||
|
|
||||||
declare var postMessage: any;
|
declare var postMessage: any;
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
/* tslint:disable:no-unused-variable */
|
import { ImageSource } from "tns-core-modules/image-source";
|
||||||
import * as TKUnit from "../TKUnit";
|
import * as TKUnit from "../TKUnit";
|
||||||
import * as http from "tns-core-modules/http";
|
import * as http from "tns-core-modules/http";
|
||||||
import * as fs from "tns-core-modules/file-system";
|
import * as fs from "tns-core-modules/file-system";
|
||||||
import { addHeader } from "tns-core-modules/http/http-request";
|
import { addHeader } from "tns-core-modules/http/http-request";
|
||||||
|
|
||||||
require("globals");
|
|
||||||
|
|
||||||
// >> http-require
|
|
||||||
// var http = require("http");
|
|
||||||
// << http-require
|
|
||||||
|
|
||||||
export var test_getString_isDefined = function () {
|
export var test_getString_isDefined = function () {
|
||||||
TKUnit.assert(typeof (http.getString) !== "undefined", "Method http.getString() should be defined!");
|
TKUnit.assert(typeof (http.getString) !== "undefined", "Method http.getString() should be defined!");
|
||||||
};
|
};
|
||||||
@ -17,20 +11,14 @@ export var test_getString_isDefined = function () {
|
|||||||
export var test_getString = function (done: (err: Error, res?: string) => void) {
|
export var test_getString = function (done: (err: Error, res?: string) => void) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
// >> http-get-string
|
|
||||||
http.getString("https://httpbin.org/get").then(function (r) {
|
http.getString("https://httpbin.org/get").then(function (r) {
|
||||||
//// Argument (r) is string!
|
//// Argument (r) is string!
|
||||||
// >> (hide)
|
|
||||||
result = r;
|
result = r;
|
||||||
done(null);
|
done(null);
|
||||||
// << (hide)
|
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
//// Argument (e) is Error!
|
//// Argument (e) is Error!
|
||||||
// >> (hide)
|
|
||||||
done(e);
|
done(e);
|
||||||
// << (hide)
|
|
||||||
});
|
});
|
||||||
// << http-get-string
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export var test_getString_fail = function (done) {
|
export var test_getString_fail = function (done) {
|
||||||
@ -67,10 +55,8 @@ export var test_getJSON_isDefined = function () {
|
|||||||
export var test_getJSON = function (done) {
|
export var test_getJSON = function (done) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
// >> http-get-json
|
|
||||||
http.getJSON("https://httpbin.org/get").then(function (r) {
|
http.getJSON("https://httpbin.org/get").then(function (r) {
|
||||||
//// Argument (r) is JSON!
|
//// Argument (r) is JSON!
|
||||||
// >> (hide)
|
|
||||||
//completed = true;
|
//completed = true;
|
||||||
result = r;
|
result = r;
|
||||||
try {
|
try {
|
||||||
@ -81,15 +67,11 @@ export var test_getJSON = function (done) {
|
|||||||
done(e);
|
done(e);
|
||||||
}
|
}
|
||||||
done(null);
|
done(null);
|
||||||
// << (hide)
|
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
//// Argument (e) is Error!
|
//// Argument (e) is Error!
|
||||||
//console.log(e);
|
//console.log(e);
|
||||||
// >> (hide)
|
|
||||||
done(e);
|
done(e);
|
||||||
// << (hide)
|
|
||||||
});
|
});
|
||||||
// << http-get-json
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export var test_getJSON_fail = function (done) {
|
export var test_getJSON_fail = function (done) {
|
||||||
@ -203,26 +185,20 @@ export var test_getImage_isDefined = function () {
|
|||||||
export var test_getImage = function (done) {
|
export var test_getImage = function (done) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
// >> http-get-image
|
|
||||||
http.getImage("https://httpbin.org/image/png").then((r) => {
|
http.getImage("https://httpbin.org/image/png").then((r) => {
|
||||||
// Argument (r) is ImageSource!
|
// Argument (r) is ImageSource!
|
||||||
// >> (hide)
|
|
||||||
result = r;
|
result = r;
|
||||||
try {
|
try {
|
||||||
TKUnit.assert(result instanceof require("image-source").ImageSource, "Result from getImage() should be valid ImageSource object!");
|
TKUnit.assert(result instanceof ImageSource, "Result from getImage() should be valid ImageSource object!");
|
||||||
done(null);
|
done(null);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
done(err);
|
done(err);
|
||||||
}
|
}
|
||||||
// << (hide)
|
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
// Argument (e) is Error!
|
// Argument (e) is Error!
|
||||||
// >> (hide)
|
|
||||||
done(err);
|
done(err);
|
||||||
// << (hide)
|
|
||||||
});
|
});
|
||||||
// << http-get-image
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export var test_getImage_fail = function (done) {
|
export var test_getImage_fail = function (done) {
|
||||||
@ -262,10 +238,8 @@ export var test_getFile_isDefined = function () {
|
|||||||
export var test_getFile = function (done) {
|
export var test_getFile = function (done) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
// >> http-get-urlfile
|
|
||||||
http.getFile("https://raw.githubusercontent.com/NativeScript/NativeScript/master/tests/app/logo.png").then(function (r) {
|
http.getFile("https://raw.githubusercontent.com/NativeScript/NativeScript/master/tests/app/logo.png").then(function (r) {
|
||||||
//// Argument (r) is File!
|
//// Argument (r) is File!
|
||||||
// >> (hide)
|
|
||||||
result = r;
|
result = r;
|
||||||
try {
|
try {
|
||||||
TKUnit.assert(result instanceof fs.File, "Result from getFile() should be valid File object!");
|
TKUnit.assert(result instanceof fs.File, "Result from getFile() should be valid File object!");
|
||||||
@ -274,24 +248,18 @@ export var test_getFile = function (done) {
|
|||||||
catch (err) {
|
catch (err) {
|
||||||
done(err);
|
done(err);
|
||||||
}
|
}
|
||||||
// << (hide)
|
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
//// Argument (e) is Error!
|
//// Argument (e) is Error!
|
||||||
// >> (hide)
|
|
||||||
done(e);
|
done(e);
|
||||||
// << (hide)
|
|
||||||
});
|
});
|
||||||
// << http-get-urlfile
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export var test_getContentAsFile = function (done) {
|
export var test_getContentAsFile = function (done) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
// >> http-get-urlfile-content
|
|
||||||
var filePath = fs.path.join(fs.knownFolders.documents().path, "test.png");
|
var filePath = fs.path.join(fs.knownFolders.documents().path, "test.png");
|
||||||
http.getFile("https://httpbin.org/image/png?testQuery=query&anotherParam=param", filePath).then(function (r) {
|
http.getFile("https://httpbin.org/image/png?testQuery=query&anotherParam=param", filePath).then(function (r) {
|
||||||
//// Argument (r) is File!
|
//// Argument (r) is File!
|
||||||
// >> (hide)
|
|
||||||
result = r;
|
result = r;
|
||||||
try {
|
try {
|
||||||
TKUnit.assert(result instanceof fs.File, "Result from getFile() should be valid File object!");
|
TKUnit.assert(result instanceof fs.File, "Result from getFile() should be valid File object!");
|
||||||
@ -300,14 +268,10 @@ export var test_getContentAsFile = function (done) {
|
|||||||
catch (err) {
|
catch (err) {
|
||||||
done(err);
|
done(err);
|
||||||
}
|
}
|
||||||
// << (hide)
|
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
//// Argument (e) is Error!
|
//// Argument (e) is Error!
|
||||||
// >> (hide)
|
|
||||||
done(e);
|
done(e);
|
||||||
// << (hide)
|
|
||||||
});
|
});
|
||||||
// << http-get-urlfile-content
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export var test_getFile_fail = function (done) {
|
export var test_getFile_fail = function (done) {
|
||||||
@ -361,11 +325,9 @@ export var test_request_requestShouldTimeout = function (done) {
|
|||||||
export var test_request_responseStatusCodeShouldBeDefined = function (done) {
|
export var test_request_responseStatusCodeShouldBeDefined = function (done) {
|
||||||
var result: http.HttpResponse;
|
var result: http.HttpResponse;
|
||||||
|
|
||||||
// >> http-get-response
|
|
||||||
http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) {
|
http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) {
|
||||||
//// Argument (response) is HttpResponse!
|
//// Argument (response) is HttpResponse!
|
||||||
var statusCode = response.statusCode;
|
var statusCode = response.statusCode;
|
||||||
// >> (hide)
|
|
||||||
result = response;
|
result = response;
|
||||||
try {
|
try {
|
||||||
TKUnit.assert(typeof (result.statusCode) !== "undefined", "response.statusCode should be defined!");
|
TKUnit.assert(typeof (result.statusCode) !== "undefined", "response.statusCode should be defined!");
|
||||||
@ -374,14 +336,10 @@ export var test_request_responseStatusCodeShouldBeDefined = function (done) {
|
|||||||
catch (err) {
|
catch (err) {
|
||||||
done(err);
|
done(err);
|
||||||
}
|
}
|
||||||
// << (hide)
|
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
//// Argument (e) is Error!
|
//// Argument (e) is Error!
|
||||||
// >> (hide)
|
|
||||||
done(e);
|
done(e);
|
||||||
// << (hide)
|
|
||||||
});
|
});
|
||||||
// << http-get-response
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export var test_headRequest_responseStatusCodeShouldBeDefined = function (done) {
|
export var test_headRequest_responseStatusCodeShouldBeDefined = function (done) {
|
||||||
@ -401,13 +359,11 @@ export var test_headRequest_responseStatusCodeShouldBeDefined = function (done)
|
|||||||
export var test_request_responseHeadersShouldBeDefined = function (done) {
|
export var test_request_responseHeadersShouldBeDefined = function (done) {
|
||||||
var result: http.HttpResponse;
|
var result: http.HttpResponse;
|
||||||
|
|
||||||
// >> http-get-response-headers
|
|
||||||
http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) {
|
http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) {
|
||||||
//// Argument (response) is HttpResponse!
|
//// Argument (response) is HttpResponse!
|
||||||
//for (var header in response.headers) {
|
//for (var header in response.headers) {
|
||||||
// console.log(header + ":" + response.headers[header]);
|
// console.log(header + ":" + response.headers[header]);
|
||||||
//}
|
//}
|
||||||
// >> (hide)
|
|
||||||
result = response;
|
result = response;
|
||||||
try {
|
try {
|
||||||
TKUnit.assert(typeof (result.headers) !== "undefined", "response.headers should be defined!");
|
TKUnit.assert(typeof (result.headers) !== "undefined", "response.headers should be defined!");
|
||||||
@ -416,27 +372,21 @@ export var test_request_responseHeadersShouldBeDefined = function (done) {
|
|||||||
catch (err) {
|
catch (err) {
|
||||||
done(err);
|
done(err);
|
||||||
}
|
}
|
||||||
// << (hide)
|
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
//// Argument (e) is Error!
|
//// Argument (e) is Error!
|
||||||
// >> (hide)
|
|
||||||
done(e);
|
done(e);
|
||||||
// << (hide)
|
|
||||||
});
|
});
|
||||||
// << http-get-response-headers
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export var test_request_responseContentShouldBeDefined = function (done) {
|
export var test_request_responseContentShouldBeDefined = function (done) {
|
||||||
var result: http.HttpResponse;
|
var result: http.HttpResponse;
|
||||||
|
|
||||||
// >> http-get-response-content
|
|
||||||
http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) {
|
http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) {
|
||||||
//// Argument (response) is HttpResponse!
|
//// Argument (response) is HttpResponse!
|
||||||
//// Content property of the response is HttpContent!
|
//// Content property of the response is HttpContent!
|
||||||
var str = response.content.toString();
|
var str = response.content.toString();
|
||||||
var obj = response.content.toJSON();
|
var obj = response.content.toJSON();
|
||||||
var img = response.content.toImage();
|
var img = response.content.toImage();
|
||||||
// >> (hide)
|
|
||||||
result = response;
|
result = response;
|
||||||
try {
|
try {
|
||||||
TKUnit.assert(typeof (result.content) !== "undefined", "response.content should be defined!");
|
TKUnit.assert(typeof (result.content) !== "undefined", "response.content should be defined!");
|
||||||
@ -445,14 +395,10 @@ export var test_request_responseContentShouldBeDefined = function (done) {
|
|||||||
catch (err) {
|
catch (err) {
|
||||||
done(err);
|
done(err);
|
||||||
}
|
}
|
||||||
// << (hide)
|
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
//// Argument (e) is Error!
|
//// Argument (e) is Error!
|
||||||
// >> (hide)
|
|
||||||
done(e);
|
done(e);
|
||||||
// << (hide)
|
|
||||||
});
|
});
|
||||||
// << http-get-response-content
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export var test_request_responseContentToStringShouldReturnString = function (done) {
|
export var test_request_responseContentToStringShouldReturnString = function (done) {
|
||||||
@ -496,7 +442,7 @@ export var test_request_responseContentToImageShouldReturnCorrectImage = functio
|
|||||||
response.content.toImage().then((source) => {
|
response.content.toImage().then((source) => {
|
||||||
result = source;
|
result = source;
|
||||||
try {
|
try {
|
||||||
TKUnit.assert(result instanceof require("image-source").ImageSource, "Result from toImage() should be valid promise of ImageSource object!");
|
TKUnit.assert(result instanceof ImageSource, "Result from toImage() should be valid promise of ImageSource object!");
|
||||||
done(null);
|
done(null);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
@ -685,7 +631,6 @@ export var test_request_jsonAsContentSentAndReceivedProperly = function (done) {
|
|||||||
content: JSON.stringify({ MyVariableOne: "ValueOne", MyVariableTwo: "ValueTwo" })
|
content: JSON.stringify({ MyVariableOne: "ValueOne", MyVariableTwo: "ValueTwo" })
|
||||||
}).then(function (response) {
|
}).then(function (response) {
|
||||||
// result = response.content.toJSON();
|
// result = response.content.toJSON();
|
||||||
// >> (hide)
|
|
||||||
result = response.content.toJSON();
|
result = response.content.toJSON();
|
||||||
try {
|
try {
|
||||||
TKUnit.assert(result["json"]["MyVariableOne"] === "ValueOne" && result["json"]["MyVariableTwo"] === "ValueTwo", "Content not sent/received properly!");
|
TKUnit.assert(result["json"]["MyVariableOne"] === "ValueOne" && result["json"]["MyVariableTwo"] === "ValueTwo", "Content not sent/received properly!");
|
||||||
@ -694,15 +639,11 @@ export var test_request_jsonAsContentSentAndReceivedProperly = function (done) {
|
|||||||
catch (err) {
|
catch (err) {
|
||||||
done(err);
|
done(err);
|
||||||
}
|
}
|
||||||
// << (hide)
|
|
||||||
// console.log(result);
|
// console.log(result);
|
||||||
}, function (e) {
|
}, function (e) {
|
||||||
// >> (hide)
|
|
||||||
done(e);
|
done(e);
|
||||||
// << (hide)
|
|
||||||
// console.log("Error occurred " + e);
|
// console.log("Error occurred " + e);
|
||||||
});
|
});
|
||||||
// << http-post-json
|
|
||||||
};
|
};
|
||||||
|
|
||||||
declare var Worker: any;
|
declare var Worker: any;
|
||||||
|
@ -2,12 +2,11 @@
|
|||||||
import * as imageSource from "tns-core-modules/image-source";
|
import * as imageSource from "tns-core-modules/image-source";
|
||||||
import * as gridModule from "tns-core-modules/ui/layouts/grid-layout";
|
import * as gridModule from "tns-core-modules/ui/layouts/grid-layout";
|
||||||
import * as enums from "tns-core-modules/ui/enums";
|
import * as enums from "tns-core-modules/ui/enums";
|
||||||
|
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
|
||||||
|
import { Label } from "tns-core-modules/ui/label";
|
||||||
|
import { Image } from "tns-core-modules/ui/image";
|
||||||
|
|
||||||
export function createPage() {
|
export function createPage() {
|
||||||
var StackLayout = require("ui/layouts/stack-layout").StackLayout;
|
|
||||||
var Label = require("ui/label").Label;
|
|
||||||
var Image = require("ui/image").Image;
|
|
||||||
|
|
||||||
var stack = new StackLayout();
|
var stack = new StackLayout();
|
||||||
var grid = new gridModule.GridLayout();
|
var grid = new gridModule.GridLayout();
|
||||||
stack.addChild(grid);
|
stack.addChild(grid);
|
||||||
@ -20,7 +19,7 @@ export function createPage() {
|
|||||||
var defaultImageSource = imageSource.fromFile(__dirname + "/test.png");
|
var defaultImageSource = imageSource.fromFile(__dirname + "/test.png");
|
||||||
|
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.source = defaultImageSource;
|
img.src = defaultImageSource;
|
||||||
|
|
||||||
img.width = 80;
|
img.width = 80;
|
||||||
img.height = 80;
|
img.height = 80;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
var observableModule = require("data/observable");
|
import { Observable } from "tns-core-modules/data/observable";
|
||||||
var vm = new observableModule.Observable();
|
|
||||||
|
var vm = new Observable();
|
||||||
|
|
||||||
export function onPageLoaded(args) {
|
export function onPageLoaded(args) {
|
||||||
var page = args.object;
|
var page = args.object;
|
||||||
vm.set("firstTitle", "fiiiirst");
|
vm.set("firstTitle", "fiiiirst");
|
||||||
|
Reference in New Issue
Block a user