mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
146 lines
6.1 KiB
TypeScript
146 lines
6.1 KiB
TypeScript
import TKUnit = require("../TKUnit");
|
|
import view = require("ui/core/view");
|
|
import builder = require("ui/builder");
|
|
import page = require("ui/page");
|
|
import switchModule = require("ui/switch");
|
|
import textFieldModule = require("ui/text-field");
|
|
import gridLayoutModule = require("ui/layouts/grid-layout");
|
|
import absoluteLayoutModule = require("ui/layouts/absolute-layout");
|
|
import types = require("utils/types");
|
|
import fs = require("file-system");
|
|
import fileSystemAccess = require("file-system/file-system-access");
|
|
import observable = require("data/observable");
|
|
|
|
export var test_load_IsDefined = function () {
|
|
TKUnit.assert(types.isFunction(builder.load), "ui/builder should have load method!");
|
|
};
|
|
|
|
export var test_parse_IsDefined = function () {
|
|
TKUnit.assert(types.isFunction(builder.parse), "ui/builder should have parse method!");
|
|
};
|
|
|
|
export var test_load_ShouldNotCrashWithInvalidFileName = function () {
|
|
var v = builder.load(fs.path.join(__dirname, "mainPage1.xml"));
|
|
|
|
TKUnit.assert(types.isUndefined(v), "Expected result: undefined; Actual result: " + v + ";");
|
|
};
|
|
|
|
export var test_load_ShouldNotCrashWithoutExports = function () {
|
|
var v = builder.load(fs.path.join(__dirname, "mainPage.xml"));
|
|
|
|
TKUnit.assert(v instanceof view.View, "Expected result: View; Actual result: " + v + ";");
|
|
};
|
|
|
|
export var test_parse_ShouldNotCrashWithoutExports = function () {
|
|
var fileAccess = new fileSystemAccess.FileSystemAccess();
|
|
|
|
var v: view.View;
|
|
fileAccess.readText(fs.path.join(__dirname, "mainPage.xml"), r => {
|
|
v = builder.parse(r);
|
|
});
|
|
|
|
TKUnit.assert(v instanceof view.View, "Expected result: View; Actual result: " + v + ";");
|
|
};
|
|
|
|
export var test_parse_ShouldNotCrashWithInvalidXml = function () {
|
|
var fileAccess = new fileSystemAccess.FileSystemAccess();
|
|
|
|
var v: view.View;
|
|
fileAccess.readText("<Page loaded='myLoaded'></Pa", r => {
|
|
v = builder.parse(r);
|
|
});
|
|
|
|
TKUnit.assert(types.isUndefined(v), "Expected result: undefined; Actual result: " + v + ";");
|
|
};
|
|
|
|
export var test_parse_ShouldFindEventHandlersInExports = function () {
|
|
var loaded;
|
|
var page = builder.parse("<Page loaded='myLoaded'></Page>", {
|
|
myLoaded: args => {
|
|
loaded = true;
|
|
}
|
|
});
|
|
|
|
page.onLoaded();
|
|
|
|
TKUnit.assert(loaded, "Parse should find event handlers in exports.");
|
|
};
|
|
|
|
export var test_parse_ShouldSetGridAttachedProperties = function () {
|
|
var p = <page.Page>builder.parse("<Page><GridLayout><Label row='1' col='2' rowSpan='3' colSpan='4' /></GridLayout></Page>");
|
|
var grid = <gridLayoutModule.GridLayout>p.content;
|
|
var child = grid.getChildAt(0);
|
|
|
|
var col = gridLayoutModule.GridLayout.getColumn(child);
|
|
TKUnit.assert(col === 2, "Expected result for grid column: 2; Actual result: " + col + ";");
|
|
|
|
var row = gridLayoutModule.GridLayout.getRow(child);
|
|
TKUnit.assert(row === 1, "Expected result for grid row: 1; Actual result: " + row + ";");
|
|
|
|
var colSpan = gridLayoutModule.GridLayout.getColumnSpan(child);
|
|
TKUnit.assert(colSpan === 4, "Expected result for grid column span: 4; Actual result: " + colSpan + ";");
|
|
|
|
var rowSpan = gridLayoutModule.GridLayout.getRowSpan(child);
|
|
TKUnit.assert(rowSpan === 3, "Expected result for grid row span: 3; Actual result: " + rowSpan + ";");
|
|
};
|
|
|
|
export var test_parse_ShouldSetCanvasAttachedProperties = function () {
|
|
var p = <page.Page>builder.parse("<Page><AbsoluteLayout><Label left='1' top='2' right='3' bottom='4' /></AbsoluteLayout></Page>");
|
|
var grid = <gridLayoutModule.GridLayout>p.content;
|
|
var child = grid.getChildAt(0);
|
|
|
|
var left = absoluteLayoutModule.AbsoluteLayout.getLeft(child);
|
|
TKUnit.assert(left === 1, "Expected result for canvas left: 1; Actual result: " + left + ";");
|
|
|
|
var top = absoluteLayoutModule.AbsoluteLayout.getTop(child);
|
|
TKUnit.assert(top === 2, "Expected result for canvas top: 2; Actual result: " + top + ";");
|
|
};
|
|
|
|
export var test_parse_ShouldParseNumberProperties = function () {
|
|
var p = <page.Page>builder.parse("<Page width='100' />");
|
|
|
|
TKUnit.assert(p.width === 100, "Expected result: 100; Actual result: " + p.width + "; type: " + typeof (p.width));
|
|
};
|
|
|
|
export var test_parse_ShouldParseBooleanProperties = function () {
|
|
var p = <page.Page>builder.parse("<Page><Switch checked='true' /></Page>");
|
|
var sw = <switchModule.Switch>p.content;
|
|
|
|
TKUnit.assert(sw.checked === true, "Expected result: true; Actual result: " + sw.checked + "; type: " + typeof (sw.checked));
|
|
};
|
|
|
|
export var test_parse_ShouldParseBooleanPropertiesIgnoreCase = function () {
|
|
var p = <page.Page>builder.parse("<Page><Switch checked='False' /></Page>");
|
|
var sw = <switchModule.Switch>p.content;
|
|
|
|
TKUnit.assert(sw.checked === false, "Expected result: false; Actual result: " + sw.checked + "; type: " + typeof (sw.checked));
|
|
};
|
|
|
|
export var test_parse_ShouldParseBooleanPropertiesIgnoreCaseInverted = function () {
|
|
var p = <page.Page>builder.parse("<Page><TextField editable='False' /></Page>");
|
|
var tf = <textFieldModule.TextField>p.content;
|
|
|
|
TKUnit.assert(tf.editable === false, "Expected result: false; Actual result: " + tf.editable + "; type: " + typeof (tf.editable));
|
|
};
|
|
|
|
export var test_parse_ShouldParseBindings = function () {
|
|
var p = <page.Page>builder.parse("<Page><Switch checked='{{ myProp }}' /></Page>");
|
|
p.bindingContext = { myProp: true };
|
|
var sw = <switchModule.Switch>p.content;
|
|
|
|
TKUnit.assert(sw.checked === true, "Expected result: true; Actual result: " + sw.checked + "; type: " + typeof (sw.checked));
|
|
};
|
|
|
|
export var test_parse_ShouldParseBindingsWithObservable = function () {
|
|
var p = <page.Page>builder.parse("<Page><Switch checked='{{ myProp }}' /></Page>");
|
|
var obj = new observable.Observable();
|
|
obj.set("myProp", true);
|
|
p.bindingContext = obj;
|
|
var sw = <switchModule.Switch>p.content;
|
|
|
|
TKUnit.assert(sw.checked === true, "Expected result: true; Actual result: " + sw.checked + "; type: " + typeof (sw.checked));
|
|
|
|
obj.set("myProp", false);
|
|
|
|
TKUnit.assert(sw.checked === false, "Expected result: false; Actual result: " + sw.checked + "; type: " + typeof (sw.checked));
|
|
}; |