mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Tests and fix for loading custom components with no code-behind
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<StackLayout>
|
||||
<Label text="I'm all about taht XML, no JS" />
|
||||
</StackLayout>
|
||||
@@ -17,27 +17,27 @@ import listViewModule = require("ui/list-view");
|
||||
import helper = require("../ui/helper");
|
||||
import viewModule = require("ui/core/view");
|
||||
|
||||
export var test_load_IsDefined = function () {
|
||||
export function test_load_IsDefined() {
|
||||
TKUnit.assert(types.isFunction(builder.load), "ui/builder should have load method!");
|
||||
};
|
||||
|
||||
export var test_parse_IsDefined = function () {
|
||||
export function test_parse_IsDefined() {
|
||||
TKUnit.assert(types.isFunction(builder.parse), "ui/builder should have parse method!");
|
||||
};
|
||||
|
||||
export var test_load_ShouldNotCrashWithInvalidFileName = function () {
|
||||
export function test_load_ShouldNotCrashWithInvalidFileName() {
|
||||
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 () {
|
||||
export function test_load_ShouldNotCrashWithoutExports() {
|
||||
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 () {
|
||||
export function test_parse_ShouldNotCrashWithoutExports() {
|
||||
var fileAccess = new fileSystemAccess.FileSystemAccess();
|
||||
|
||||
var v: view.View;
|
||||
@@ -48,7 +48,7 @@ export var test_parse_ShouldNotCrashWithoutExports = function () {
|
||||
TKUnit.assert(v instanceof view.View, "Expected result: View; Actual result: " + v + ";");
|
||||
};
|
||||
|
||||
export var test_parse_ShouldNotCrashWithInvalidXml = function () {
|
||||
export function test_parse_ShouldNotCrashWithInvalidXml() {
|
||||
var fileAccess = new fileSystemAccess.FileSystemAccess();
|
||||
|
||||
var v: view.View;
|
||||
@@ -59,7 +59,7 @@ export var test_parse_ShouldNotCrashWithInvalidXml = function () {
|
||||
TKUnit.assert(types.isUndefined(v), "Expected result: undefined; Actual result: " + v + ";");
|
||||
};
|
||||
|
||||
export var test_parse_ShouldFindEventHandlersInExports = function () {
|
||||
export function test_parse_ShouldFindEventHandlersInExports() {
|
||||
var loaded;
|
||||
var page = builder.parse("<Page loaded='myLoaded'></Page>", {
|
||||
myLoaded: args => {
|
||||
@@ -71,7 +71,7 @@ export var test_parse_ShouldFindEventHandlersInExports = function () {
|
||||
TKUnit.assert(loaded, "Parse should find event handlers in exports.");
|
||||
};
|
||||
|
||||
export var test_parse_ShouldSetGridAttachedProperties = function () {
|
||||
export function test_parse_ShouldSetGridAttachedProperties() {
|
||||
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);
|
||||
@@ -89,7 +89,7 @@ export var test_parse_ShouldSetGridAttachedProperties = function () {
|
||||
TKUnit.assert(rowSpan === 3, "Expected result for grid row span: 3; Actual result: " + rowSpan + ";");
|
||||
};
|
||||
|
||||
export var test_parse_ShouldSetCanvasAttachedProperties = function () {
|
||||
export function test_parse_ShouldSetCanvasAttachedProperties() {
|
||||
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);
|
||||
@@ -101,34 +101,34 @@ export var test_parse_ShouldSetCanvasAttachedProperties = function () {
|
||||
TKUnit.assert(top === 2, "Expected result for canvas top: 2; Actual result: " + top + ";");
|
||||
};
|
||||
|
||||
export var test_parse_ShouldParseNumberProperties = function () {
|
||||
export function test_parse_ShouldParseNumberProperties() {
|
||||
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 () {
|
||||
export function test_parse_ShouldParseBooleanProperties() {
|
||||
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 () {
|
||||
export function test_parse_ShouldParseBooleanPropertiesIgnoreCase() {
|
||||
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 () {
|
||||
export function test_parse_ShouldParseBooleanPropertiesIgnoreCaseInverted() {
|
||||
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 () {
|
||||
export function test_parse_ShouldParseBindings() {
|
||||
var p = <page.Page>builder.parse("<Page><Switch checked='{{ myProp }}' /></Page>");
|
||||
p.bindingContext = { myProp: true };
|
||||
var sw = <switchModule.Switch>p.content;
|
||||
@@ -136,7 +136,7 @@ export var test_parse_ShouldParseBindings = function () {
|
||||
TKUnit.assert(sw.checked === true, "Expected result: true; Actual result: " + sw.checked + "; type: " + typeof (sw.checked));
|
||||
};
|
||||
|
||||
export var test_parse_ShouldParseBindingsWithObservable = function () {
|
||||
export function test_parse_ShouldParseBindingsWithObservable() {
|
||||
var p = <page.Page>builder.parse("<Page><Switch checked='{{ myProp }}' /></Page>");
|
||||
var obj = new observable.Observable();
|
||||
obj.set("myProp", true);
|
||||
@@ -150,7 +150,7 @@ export var test_parse_ShouldParseBindingsWithObservable = function () {
|
||||
TKUnit.assert(sw.checked === false, "Expected result: false; Actual result: " + sw.checked + "; type: " + typeof (sw.checked));
|
||||
};
|
||||
|
||||
export var test_parse_ShouldParseSubProperties = function () {
|
||||
export function test_parse_ShouldParseSubProperties() {
|
||||
var p = <page.Page>builder.parse("<Page><Switch style.visibility='collapsed' checked='{{ myProp }}' /></Page>");
|
||||
var obj = new observable.Observable();
|
||||
obj.set("myProp", true);
|
||||
@@ -160,14 +160,14 @@ export var test_parse_ShouldParseSubProperties = function () {
|
||||
TKUnit.assert(sw.visibility === "collapsed", "Expected result: collapsed; Actual result: " + sw.visibility + "; type: " + typeof (sw.visibility));
|
||||
};
|
||||
|
||||
export var test_parse_ShouldParseCustomComponentWithoutXml = function () {
|
||||
export function test_parse_ShouldParseCustomComponentWithoutXml() {
|
||||
var p = <page.Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodule"><customControls:MyControl /></Page>');
|
||||
var ctrl = p.content;
|
||||
|
||||
TKUnit.assert(ctrl instanceof myCustomControlWithoutXml.MyControl, "Expected result: custom control is defined!; Actual result: " + ctrl);
|
||||
};
|
||||
|
||||
export var test_parse_ShouldParseCustomComponentWitXml = function () {
|
||||
export function test_parse_ShouldParseCustomComponentWitXml() {
|
||||
var p = <page.Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:MyControl /></Page>');
|
||||
var panel = <stackLayoutModule.StackLayout>p.content;
|
||||
var lbl = <labelModule.Label>panel.getChildAt(0);
|
||||
@@ -175,11 +175,40 @@ export var test_parse_ShouldParseCustomComponentWitXml = function () {
|
||||
TKUnit.assert(lbl.text === "mymodulewithxml", "Expected result: 'mymodulewithxml'; Actual result: " + lbl);
|
||||
};
|
||||
|
||||
export var test_parse_ShouldParseCustomComponentWitXmlWithAttributes = function () {
|
||||
export function test_parse_ShouldParseCustomComponentWitXml_WithAttributes() {
|
||||
var p = <page.Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:MyControl visibility="collapsed" /></Page>');
|
||||
var panel = <stackLayoutModule.StackLayout>p.content;
|
||||
|
||||
TKUnit.assert(panel.visibility === "collapsed", "Expected result: 'collapsed'; Actual result: " + panel.visibility);
|
||||
TKUnit.assertEqual(panel.visibility, "collapsed", "panel.visibility");
|
||||
};
|
||||
|
||||
export function test_parse_ShouldParseCustomComponentWitXml_WithCustomAttributes() {
|
||||
var p = <page.Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:MyControl myProperty="myValue" /></Page>');
|
||||
var panel = <stackLayoutModule.StackLayout>p.content;
|
||||
|
||||
TKUnit.assertEqual(panel["myProperty"], "myValue", "customControl.myProperty");
|
||||
};
|
||||
|
||||
export function test_parse_ShouldParseCustomComponentWitXmlNoJS() {
|
||||
var p = <page.Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:my-control-no-js /></Page>');
|
||||
var panel = <stackLayoutModule.StackLayout>p.content;
|
||||
var lbl = <labelModule.Label>panel.getChildAt(0);
|
||||
|
||||
TKUnit.assert(lbl.text === "mymodulewithxml", "Expected result: 'mymodulewithxml'; Actual result: " + lbl);
|
||||
};
|
||||
|
||||
export function test_parse_ShouldParseCustomComponentWitXmlNoJS_WithAttributes() {
|
||||
var p = <page.Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:my-control-no-js visibility="collapsed" /></Page>');
|
||||
var panel = <stackLayoutModule.StackLayout>p.content;
|
||||
|
||||
TKUnit.assertEqual(panel.visibility, "collapsed", "panel.visibility");
|
||||
};
|
||||
|
||||
export function test_parse_ShouldParseCustomComponentWitXmlNoJS_WithCustomAttributes() {
|
||||
var p = <page.Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:my-control-no-js myProperty="myValue" /></Page>');
|
||||
var panel = <stackLayoutModule.StackLayout>p.content;
|
||||
|
||||
TKUnit.assertEqual(panel["myProperty"], "myValue", "customControl.myProperty");
|
||||
};
|
||||
|
||||
export function test_parse_ShouldParseCustomComponentWithoutXmlInListViewTemplate() {
|
||||
|
||||
Reference in New Issue
Block a user