Skip to content

Commit b4575e1

Browse files
author
Nedyalko Nikolov
committed
Fixed xml-declaration tests.
1 parent ae2012b commit b4575e1

File tree

14 files changed

+58
-67
lines changed

14 files changed

+58
-67
lines changed

tests/app/testRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ allTests["CONNECTIVITY"] = require("./connectivity-tests");
5656
// allTests["PROXY-VIEW-CONTAINER"] = require("./ui/proxy-view-container/proxy-view-container-tests")
5757
allTests["SCROLL-VIEW"] = require("./ui/scroll-view/scroll-view-tests");
5858
allTests["ACTION-BAR"] = require("./ui/action-bar/action-bar-tests");
59-
// allTests["XML-DECLARATION"] = require("./xml-declaration/xml-declaration-tests");
59+
allTests["XML-DECLARATION"] = require("./xml-declaration/xml-declaration-tests");
6060
allTests["DOCKLAYOUT"] = require("./ui/layouts/dock-layout-tests");
6161
allTests["WRAPLAYOUT"] = require("./ui/layouts/wrap-layout-tests");
6262
allTests["ABSOLUTELAYOUT"] = require("./ui/layouts/absolute-layout-tests");
Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Template} from "ui/core/view"
2-
import {Property, PropertyMetadataSettings} from "ui/core/dependency-observable"
1+
import { Template } from "ui/core/view"
2+
import { Property } from "ui/core/properties"
33
import * as proxy from "ui/core/proxy"
44
import { LayoutBase } from "ui/layouts/layout-base"
55
import { parse } from "ui/builder"
@@ -9,27 +9,17 @@ export module knownTemplates {
99
}
1010

1111
export class TemplateView extends LayoutBase {
12-
public static templateProperty = new Property(
13-
"template",
14-
"TemplateView",
15-
new proxy.PropertyMetadata(
16-
undefined,
17-
PropertyMetadataSettings.AffectsLayout,
18-
null
19-
)
20-
);
21-
22-
public static testEvent: string = "test";
23-
24-
get template(): string | Template {
25-
return this._getValue(TemplateView.templateProperty);
26-
}
27-
28-
set template(value: string | Template) {
29-
this._setValue(TemplateView.templateProperty, value);
30-
}
12+
public template: string;
13+
14+
public static testEvent: string = "test";
3115

3216
public parseTemplate() {
3317
this.addChild(parse(this.template));
3418
}
3519
}
20+
21+
export const templateProperty = new Property<TemplateView, string>({
22+
name: "template",
23+
affectsLayout: true
24+
});
25+
templateProperty.register(TemplateView);

tests/app/xml-declaration/xml-declaration-tests.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import * as platform from "platform";
2525
import * as gesturesModule from "ui/gestures";
2626
import * as segmentedBar from "ui/segmented-bar";
2727
import { Source } from "utils/debug";
28-
import { PercentLength } from "ui/core/view";
28+
import { PercentLength, Length } from "ui/core/view";
2929

3030
export function test_load_IsDefined() {
3131
TKUnit.assertTrue(types.isFunction(builder.load), "ui/builder should have load method!");
@@ -296,14 +296,15 @@ export function test_parse_ShouldSetGridAttachedProperties() {
296296

297297
export function test_parse_ShouldSetCanvasAttachedProperties() {
298298
var p = <Page>builder.parse("<Page><AbsoluteLayout><Label left='1' top='2' right='3' bottom='4' /></AbsoluteLayout></Page>");
299-
var grid = <gridLayoutModule.GridLayout>p.content;
300-
var child = grid.getChildAt(0);
299+
var absLayout = <absoluteLayoutModule.AbsoluteLayout>p.content;
300+
var child = absLayout.getChildAt(0);
301301

302302
var left = absoluteLayoutModule.AbsoluteLayout.getLeft(child);
303-
TKUnit.assertEqual(left, 1, "Expected result for canvas left: 1; Actual result: " + left + ";");
303+
304+
TKUnit.assert(Length.equals(left, Length.parse("1")), `Expected result for canvas left: 1; Actual result: ${(<any>left).value};`)
304305

305306
var top = absoluteLayoutModule.AbsoluteLayout.getTop(child);
306-
TKUnit.assertEqual(top, 2, "Expected result for canvas top: 2; Actual result: " + top + ";");
307+
TKUnit.assert(Length.equals(top, Length.parse("2")), `Expected result for canvas top: 2; Actual result: ${(<any>top).value};`)
307308
};
308309

309310
export function test_parse_ShouldParseNumberProperties() {
@@ -445,13 +446,13 @@ export function test_parse_ShouldParseBindingsToGesturesWithOn() {
445446
};
446447

447448
export function test_parse_ShouldParseSubProperties() {
448-
var p = <Page>builder.parse("<Page><Switch style.visibility='collapsed' checked='{{ myProp }}' /></Page>");
449+
var p = <Page>builder.parse("<Page><Switch style.visibility='collapse' checked='{{ myProp }}' /></Page>");
449450
var obj = new observable.Observable();
450451
obj.set("myProp", true);
451452
p.bindingContext = obj;
452453
var sw = <switchModule.Switch>p.content;
453454

454-
TKUnit.assert(sw.visibility === "collapse", "Expected result: collapsed; Actual result: " + sw.visibility + "; type: " + typeof (sw.visibility));
455+
TKUnit.assert(sw.visibility === "collapse", "Expected result: collapse; Actual result: " + sw.visibility + "; type: " + typeof (sw.visibility));
455456
};
456457

457458
export function test_parse_ShouldParseBindingToSpecialProperty() {
@@ -539,10 +540,10 @@ export function test_parse_ShouldParseCustomComponentWithXml() {
539540
};
540541

541542
export function test_parse_ShouldParseCustomComponentWithXml_WithAttributes() {
542-
var p = <Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:MyControl visibility="collapsed" /></Page>');
543+
var p = <Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:MyControl visibility="collapse" /></Page>');
543544
var panel = <stackLayoutModule.StackLayout>p.content;
544545

545-
TKUnit.assertEqual(panel.visibility, "collapsed", "panel.visibility");
546+
TKUnit.assertEqual(panel.visibility, "collapse", "panel.visibility");
546547
};
547548

548549
export function test_parse_ShouldParseCustomComponentWithXml_WithCustomAttributes() {
@@ -561,10 +562,10 @@ export function test_parse_ShouldParseCustomComponentWithXmlNoJS() {
561562
};
562563

563564
export function test_parse_ShouldParseCustomComponentWithXmlNoJS_WithAttributes() {
564-
var p = <Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:my-control-no-js visibility="collapsed" /></Page>');
565+
var p = <Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:my-control-no-js visibility="collapse" /></Page>');
565566
var panel = <stackLayoutModule.StackLayout>p.content;
566567

567-
TKUnit.assertEqual(panel.visibility, "collapsed", "panel.visibility");
568+
TKUnit.assertEqual(panel.visibility, "collapse", "panel.visibility");
568569
};
569570

570571
export function test_parse_ShouldParseCustomComponentWithXmlNoJS_WithCustomAttributes() {
@@ -613,13 +614,23 @@ export function test_parse_ShouldParseNestedListViewInListViewTemplate() {
613614
}
614615

615616
export function test_parse_ShouldEvaluateEventBindingExpressionInListViewTemplate() {
616-
var p = <Page>builder.parse('<Page xmlns="http://schemas.nativescript.org/tns.xsd"><ListView items="{{ items }}" itemLoading="{{ itemLoading }}"><ListView.itemTemplate><SegmentedBar items="{{ $parents[\'ListView\'].items }}" selectedIndexChanged="{{ $parents[\'ListView\'].changed }}" /></ListView.itemTemplate></ListView></Page>');
617+
var p = <Page>builder.parse('<Page xmlns="http://schemas.nativescript.org/tns.xsd"><ListView items="{{ items }}" itemLoading="{{ itemLoading }}"><ListView.itemTemplate><SegmentedBar items="{{ $parents[\'ListView\'].segmentedBarItems }}" selectedIndexChanged="{{ $parents[\'ListView\'].changed }}" /></ListView.itemTemplate></ListView></Page>');
617618

618619
function testAction(views: Array<viewModule.View>) {
619620
let ctrl: segmentedBar.SegmentedBar = null;
620621
let changed;
621622
let obj = new observable.Observable();
623+
624+
let firstItem = new segmentedBar.SegmentedBarItem();
625+
firstItem.title = "One";
626+
let secondItem = new segmentedBar.SegmentedBarItem();
627+
secondItem.title = "Two";
628+
let thirdItem = new segmentedBar.SegmentedBarItem();
629+
thirdItem.title = "Tree";
630+
let segmentedBarItems = [firstItem, secondItem, thirdItem];
631+
622632
obj.set("items", [1, 2, 3]);
633+
obj.set("segmentedBarItems", segmentedBarItems);
623634
obj.set("itemLoading", function (args: listViewModule.ItemEventData) {
624635
ctrl = <segmentedBar.SegmentedBar>args.view
625636
});

tns-core-modules/ui/core/bindable.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class Binding {
192192

193193
public loadedHandlerVisualTreeBinding(args) {
194194
let target = args.object;
195-
target.off(ViewBase.loadedEvent, this.loadedHandlerVisualTreeBinding, this);
195+
target.off("loaded", this.loadedHandlerVisualTreeBinding, this);
196196
if (!types.isNullOrUndefined(target.bindingContext)) {
197197
this.bind(target.bindingContext);
198198
}
@@ -288,8 +288,8 @@ export class Binding {
288288
currentObject = parentView.bindingContext;
289289
} else {
290290
let targetInstance = this.target.get();
291-
targetInstance.off(ViewBase.loadedEvent, this.loadedHandlerVisualTreeBinding, this);
292-
targetInstance.on(ViewBase.loadedEvent, this.loadedHandlerVisualTreeBinding, this);
291+
targetInstance.off("loaded", this.loadedHandlerVisualTreeBinding, this);
292+
targetInstance.on("loaded", this.loadedHandlerVisualTreeBinding, this);
293293
}
294294

295295
currentObjectChanged = true;

tns-core-modules/ui/core/properties.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> imp
362362
if (currentValue !== newValue) {
363363

364364
if (this.hasListeners(eventName)) {
365-
console.log("Notify " + eventName);
366365
this.notify({
367366
eventName: eventName,
368367
propertyName: name,

tns-core-modules/ui/gestures/gestures.ios.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GestureEventData, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from "ui/gestures";
2-
import { GesturesObserverBase, toString, TouchAction, GestureStateTypes, GestureTypes, SwipeDirection, View, EventData } from "./gestures-common";
2+
import { GesturesObserverBase, toString, TouchAction, GestureStateTypes, GestureTypes, SwipeDirection, View, EventData } from "./gestures-common";
33
import { ios } from "utils/utils";
44
import getter = ios.getter;
55

@@ -92,8 +92,8 @@ export class GesturesObserver extends GesturesObserverBase {
9292
this._detach();
9393
};
9494

95-
this.target.on(View.loadedEvent, this._onTargetLoaded);
96-
this.target.on(View.unloadedEvent, this._onTargetUnloaded);
95+
this.target.on("loaded", this._onTargetLoaded);
96+
this.target.on("unloaded", this._onTargetUnloaded);
9797

9898
if (this.target.isLoaded) {
9999
this._attach(this.target, type);
@@ -183,8 +183,8 @@ export class GesturesObserver extends GesturesObserverBase {
183183
this._detach();
184184

185185
if (this.target) {
186-
this.target.off(View.loadedEvent, this._onTargetLoaded);
187-
this.target.off(View.unloadedEvent, this._onTargetUnloaded);
186+
this.target.off("loaded", this._onTargetLoaded);
187+
this.target.off("unloaded", this._onTargetUnloaded);
188188

189189
this._onTargetLoaded = null;
190190
this._onTargetUnloaded = null;

tns-core-modules/ui/html-view/html-view.ios.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,3 @@ export class HtmlView extends HtmlViewBase {
6767
this._ios.attributedText = NSAttributedString.alloc().initWithDataOptionsDocumentAttributesError(nsData, <any>{ [NSDocumentTypeDocumentAttribute]: NSHTMLTextDocumentType }, null);
6868
}
6969
}
70-
71-
htmlProperty.register(HtmlView);
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
declare module "ui/layouts/absolute-layout" {
2-
import { LayoutBase, View, Property } from "ui/layouts/layout-base";
2+
import { LayoutBase, View, Property, Length } from "ui/layouts/layout-base";
33

44
/**
55
* A layout that lets you specify exact locations (left/top coordinates) of its children.
@@ -8,31 +8,31 @@
88
/**
99
* Gets the value of the Left property from a given View.
1010
*/
11-
static getLeft(view: View): number;
11+
static getLeft(view: View): Length;
1212

1313
/**
1414
* Sets the value of the Left property from a given View.
1515
*/
16-
static setLeft(view: View, value: number): void;
16+
static setLeft(view: View, value: Length): void;
1717

1818
/**
1919
* Gets the value of the Top property from a given View.
2020
*/
21-
static getTop(view: View): number;
21+
static getTop(view: View): Length;
2222

2323
/**
2424
* Sets the value of the Top property from a given View.
2525
*/
26-
static setTop(view: View, value: number): void;
26+
static setTop(view: View, value: Length): void;
2727
}
2828

2929
/**
3030
* Represents the observable property backing the left property.
3131
*/
32-
export const leftProperty: Property<View, number>;
32+
export const leftProperty: Property<View, Length>;
3333

3434
/**
3535
* Represents the observable property backing the top property.
3636
*/
37-
export const topProperty: Property<View, number>;
37+
export const topProperty: Property<View, Length>;
3838
}

tns-core-modules/ui/segmented-bar/segmented-bar-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export abstract class SegmentedBarBase extends View implements SegmentedBarDefin
4646
this.items = new Array<SegmentedBarItemBase>();
4747
}
4848
this.items.push(<SegmentedBarItemBase>value);
49+
selectedIndexProperty.coerce(this);
4950
}
5051
}
5152

tns-core-modules/ui/segmented-bar/segmented-bar.android.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ export class SegmentedBar extends SegmentedBarBase {
259259
if (newItems) {
260260
newItems.forEach((item, i, arr) => this.insertTab(item, i));
261261

262-
if (this.selectedIndex < 0) {
263-
this.selectedIndex = tabHost.getCurrentTab();
264-
}
262+
// if (this.selectedIndex < 0) {
263+
// this.selectedIndex = tabHost.getCurrentTab();
264+
// }
265265
}
266266
}
267267
}

tns-core-modules/ui/segmented-bar/segmented-bar.ios.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export class SegmentedBar extends SegmentedBarBase {
5757
segmentedControl.insertSegmentWithTitleAtIndexAnimated(title, index, false);
5858
})
5959

60-
if (this.selectedIndex < 0) {
61-
this.selectedIndex = segmentedControl.selectedSegmentIndex;
62-
}
60+
// if (this.selectedIndex < 0) {
61+
// this.selectedIndex = segmentedControl.selectedSegmentIndex;
62+
// }
6363
}
6464
}
6565

tns-core-modules/ui/tab-view/tab-view-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export class TabViewBase extends View implements TabViewDefinition, AddChildFrom
9191
}
9292
this.items.push(<TabViewItemBase>value);
9393
this._addView(value);
94+
selectedIndexProperty.coerce(this);
9495
}
9596
}
9697

tns-core-modules/ui/tab-view/tab-view.android.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,6 @@ export class TabView extends TabViewBase {
358358
const tv = tabLayout.getTextViewForItemAt(i);
359359
item.setNativeView(tv);
360360
});
361-
362-
let selectedIndex = this.selectedIndex;
363-
if (selectedIndex < 0) {
364-
this.selectedIndex = this._viewPager.getCurrentItem();
365-
}
366361
}
367362

368363
get [androidOffscreenTabLimitProperty.native](): number {

tns-core-modules/ui/tab-view/tab-view.ios.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,6 @@ export class TabView extends TabViewBase {
268268

269269
// When we set this._ios.viewControllers, someone is clearing the moreNavigationController.delegate, so we have to reassign it each time here.
270270
this._ios.moreNavigationController.delegate = this._moreNavigationControllerDelegate;
271-
272-
if (this.selectedIndex < 0) {
273-
this.selectedIndex = this._ios.selectedIndex;
274-
}
275271
}
276272

277273
private _getIconRenderingMode(): UIImageRenderingMode {

0 commit comments

Comments
 (0)