mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup
This commit is contained in:
1420
apps/automated/app/ui/core/bindable/bindable-tests.ts
Normal file
1420
apps/automated/app/ui/core/bindable/bindable-tests.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
||||
import { Frame } from '@nativescript/core/ui/frame';
|
||||
import * as textFieldModule from '@nativescript/core/ui/text-field';
|
||||
import * as helper from '../../../ui-helper';
|
||||
|
||||
export var test_BindingExpressions_ArrayAccess = function () {
|
||||
navigateToPage('bindingExpressions_arrayAccess_testPage');
|
||||
assertElementString('textField1', 'bindings');
|
||||
assertElementString('textField2', '1');
|
||||
};
|
||||
|
||||
export var test_BindingExpressions_LogicalOperators = function () {
|
||||
navigateToPage('bindingExpressions_logicalOperators_testPage');
|
||||
assertElementString('textField1', 'true');
|
||||
assertElementString('textField2', 'false');
|
||||
assertElementString('textField3', 'true');
|
||||
};
|
||||
|
||||
export var test_BindingExpressions_UnaryOperators = function () {
|
||||
navigateToPage('bindingExpressions_unaryOperators_testPage');
|
||||
assertElementString('textField1', '5');
|
||||
assertElementString('textField2', '-5');
|
||||
assertElementString('textField3', '3');
|
||||
assertElementString('textField4', '-3');
|
||||
assertElementString('textField5', '1');
|
||||
assertElementString('textField6', '-1');
|
||||
assertElementValueIsNaN('textField7');
|
||||
assertElementValueIsNaN('textField8');
|
||||
};
|
||||
|
||||
export var test_BindingExpressions_BinaryOperators = function () {
|
||||
navigateToPage('bindingExpressions_binaryOperators_testPage');
|
||||
assertElementString('textField1', '1');
|
||||
assertElementString('textField2', '-1');
|
||||
assertElementString('textField3', '0');
|
||||
assertElementString('textField4', '0');
|
||||
assertElementString('textField5', 'Infinity');
|
||||
assertElementString('textField6', '0');
|
||||
assertElementValueIsNaN('textField7');
|
||||
};
|
||||
|
||||
export var test_BindingExpressions_ComparisonOperators = function () {
|
||||
navigateToPage('bindingExpressions_comparisonOperators_testPage');
|
||||
assertElementString('textField1', 'true');
|
||||
//assertElementString("textField2", "false");
|
||||
assertElementString('textField3', 'true');
|
||||
//assertElementString("textField4", "false");
|
||||
assertElementString('textField5', 'false');
|
||||
assertElementString('textField6', 'true');
|
||||
assertElementString('textField7', 'false');
|
||||
assertElementString('textField8', 'true');
|
||||
};
|
||||
|
||||
export var test_BindingExpressions_LogicalComparisonOperators = function () {
|
||||
navigateToPage('bindingExpressions_logicalComparisonOperators_testPage');
|
||||
assertElementString('textField1', 'false');
|
||||
assertElementString('textField2', 'true');
|
||||
assertElementString('textField3', 'Text');
|
||||
};
|
||||
|
||||
export var test_BindingExpressions_TernaryOperator = function () {
|
||||
navigateToPage('bindingExpressions_ternaryOperator_testPage');
|
||||
assertElementString('textField1', 'by Pratchett');
|
||||
};
|
||||
|
||||
export var test_BindingExpressions_GroupingParenthesis = function () {
|
||||
navigateToPage('bindingExpressions_groupingParenthesis_testPage');
|
||||
assertElementString('textField1', '21');
|
||||
assertElementString('textField2', '8');
|
||||
};
|
||||
|
||||
export var assertElementString = function (elementId: string, value: any) {
|
||||
var element: textFieldModule.TextField = <textFieldModule.TextField>Frame.topmost().currentPage.getViewById(elementId);
|
||||
if (element.text.toString() !== value) {
|
||||
throw new Error(' Actual: ' + element.text.toString() + ' Expected: ' + value);
|
||||
}
|
||||
};
|
||||
|
||||
export var assertElementValueIsNaN = function (elementId: string) {
|
||||
var element: textFieldModule.TextField = <textFieldModule.TextField>Frame.topmost().currentPage.getViewById(elementId);
|
||||
var value: any = element.text;
|
||||
if (isNaN(value) !== true) {
|
||||
throw new Error(' Actual: ' + value + ' is not NaN');
|
||||
}
|
||||
};
|
||||
|
||||
export var navigateToPage = function (pageName: string) {
|
||||
helper.navigateToModule('ui/test-pages/' + pageName);
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
import * as observableModule from '@nativescript/core/data/observable';
|
||||
import * as pageModule from '@nativescript/core/ui/page';
|
||||
|
||||
class MainViewModel extends observableModule.Observable {
|
||||
private _item: any;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.item = { Title: 'Alabala' };
|
||||
}
|
||||
|
||||
get item(): any {
|
||||
return this._item;
|
||||
}
|
||||
|
||||
set item(value: any) {
|
||||
if (this._item !== value) {
|
||||
this._item = value;
|
||||
this.notifyPropertyChanged('item', value);
|
||||
}
|
||||
}
|
||||
|
||||
notifyPropertyChanged(propertyName: string, value: any) {
|
||||
this.notify({ object: this, eventName: observableModule.Observable.propertyChangeEvent, propertyName: propertyName, value: value });
|
||||
}
|
||||
}
|
||||
|
||||
var viewModel = new MainViewModel();
|
||||
|
||||
export function pageLoaded(args: observableModule.EventData) {
|
||||
var page = <pageModule.Page>args.object;
|
||||
page.bindingContext = viewModel;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
|
||||
xmlns:g="components/grid-view/grid-view"
|
||||
loaded="pageLoaded">
|
||||
<StackLayout id="upperStack">
|
||||
<Label id="upperStackLabel" text="{{ item.Title }}" />
|
||||
<StackLayout id="firstStack" bindingContext="{{ item }}" orientation="horizontal">
|
||||
<Label id="labelText1" text="1" />
|
||||
<Label id="label1" text="{{ Title }}" />
|
||||
</StackLayout>
|
||||
<StackLayout id="secondStack" bindingContext="{{ item }}" orientation="horizontal">
|
||||
<Label id="labelText2" text="2" />
|
||||
<Label id="label2" text="{{ Title }}" />
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</Page>
|
||||
@@ -0,0 +1,15 @@
|
||||
import * as observable from '@nativescript/core/data/observable';
|
||||
import * as pageModule from '@nativescript/core/ui/page';
|
||||
|
||||
function loadViewModel() {
|
||||
viewModel.set('testProperty', 'Alabala');
|
||||
}
|
||||
|
||||
var viewModel = new observable.Observable();
|
||||
|
||||
loadViewModel();
|
||||
|
||||
export function pageLoaded(args: observable.EventData) {
|
||||
var page = <pageModule.Page>args.object;
|
||||
page.bindingContext = viewModel;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded">
|
||||
<StackLayout>
|
||||
<StackLayout>
|
||||
<Label id="testLabel" text="{{ testProperty }}" />
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</Page>
|
||||
@@ -0,0 +1,6 @@
|
||||
import * as pageModule from '@nativescript/core/ui/page';
|
||||
|
||||
export function pageNavigatedTo(args: pageModule.NavigatedData) {
|
||||
var page = <pageModule.Page>args.object;
|
||||
page.bindingContext = args.context;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<Page navigatedTo="pageNavigatedTo">
|
||||
<StackLayout>
|
||||
<TextField id="testTextField" text="{{ testProperty }}" />
|
||||
</StackLayout>
|
||||
</Page>
|
||||
Reference in New Issue
Block a user