mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-19 14:20:22 +08:00
Merge pull request #938 from NativeScript/hhristov/improving-tests-time
Add module duration
This commit is contained in:
@ -115,7 +115,7 @@ function runAsync(testInfo: TestInfoEntry, recursiveIndex: number, testTimeout?:
|
|||||||
runTests(testsQueue, recursiveIndex + 1);
|
runTests(testsQueue, recursiveIndex + 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setTimeout(checkFinished, 200);
|
setTimeout(checkFinished, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,8 +208,15 @@ export function assertNull(actual: any, message?: string) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function assertAreClose(actual: number, expected: number, delta: number, message?: string) {
|
export function areClose(actual: number, expected: number, delta: number): boolean {
|
||||||
if (isNaN(actual) || Math.abs(actual - expected) > delta) {
|
if (isNaN(actual) || Math.abs(actual - expected) > delta) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
export function assertAreClose(actual: number, expected: number, delta: number, message?: string) {
|
||||||
|
if (!areClose(actual, expected, delta)) {
|
||||||
throw new Error(message + " Numbers are not close enough. Actual: " + actual + " Expected: " + expected + " Delta: " + delta);
|
throw new Error(message + " Numbers are not close enough. Actual: " + actual + " Expected: " + expected + " Delta: " + delta);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import TKUnit = require("../TKUnit");
|
import testModule = require("../ui-test");
|
||||||
|
import TKUnit = require("../TKUnit");
|
||||||
import viewModule = require("ui/core/view");
|
import viewModule = require("ui/core/view");
|
||||||
import labelModule = require("ui/label");
|
import labelModule = require("ui/label");
|
||||||
import helper = require("../ui/helper");
|
import helper = require("../ui/helper");
|
||||||
@ -23,63 +24,83 @@ import absoluteLayoutModule = require("ui/layouts/absolute-layout");
|
|||||||
//```
|
//```
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
export var testAll = function () {
|
export class AbsoluteLayoutTest extends testModule.UITest<absoluteLayoutModule.AbsoluteLayout> {
|
||||||
// <snippet module="ui/layouts/absolute-layout" title="absolute-layout">
|
|
||||||
// ## Creating and populating a AbsoluteLayout with children
|
|
||||||
// ``` JavaScript
|
|
||||||
var absoluteLayout = new absoluteLayoutModule.AbsoluteLayout();
|
|
||||||
absoluteLayout.width = 230;
|
|
||||||
absoluteLayout.height = 230;
|
|
||||||
absoluteLayout.style.backgroundColor = new colorModule.Color("LightGray");
|
|
||||||
var label = new labelModule.Label();
|
|
||||||
//// In absolute layout place of an UI element is determined by 4 parameters : left, top, width and height.
|
|
||||||
absoluteLayoutModule.AbsoluteLayout.setLeft(label, 10);
|
|
||||||
absoluteLayoutModule.AbsoluteLayout.setTop(label, 10);
|
|
||||||
label.width = 100;
|
|
||||||
label.height = 100;
|
|
||||||
label.text = "LT";
|
|
||||||
label.id = "LT";
|
|
||||||
label.style.backgroundColor = new colorModule.Color("Red");
|
|
||||||
absoluteLayout.addChild(label);
|
|
||||||
// ```
|
|
||||||
// </snippet>
|
|
||||||
|
|
||||||
helper.buildUIAndRunTest(absoluteLayout, function (views: Array<viewModule.View>) {
|
public create(): absoluteLayoutModule.AbsoluteLayout {
|
||||||
TKUnit.waitUntilReady(function isReady() {
|
return new absoluteLayoutModule.AbsoluteLayout();
|
||||||
return absoluteLayout.isLayoutValid;
|
}
|
||||||
}, 1);
|
|
||||||
|
|
||||||
var actualValue = viewModule.getViewById(absoluteLayout, "LT")._getCurrentLayoutBounds();
|
public snippet() {
|
||||||
var width = actualValue.right - actualValue.left;
|
|
||||||
var height = actualValue.bottom - actualValue.top;
|
// <snippet module="ui/layouts/absolute-layout" title="absolute-layout">
|
||||||
|
// ## Creating and populating a AbsoluteLayout with children
|
||||||
|
// ``` JavaScript
|
||||||
|
var absoluteLayout = new absoluteLayoutModule.AbsoluteLayout();
|
||||||
|
absoluteLayout.width = 230;
|
||||||
|
absoluteLayout.height = 230;
|
||||||
|
absoluteLayout.style.backgroundColor = new colorModule.Color("LightGray");
|
||||||
|
var label = new labelModule.Label();
|
||||||
|
//// In absolute layout place of an UI element is determined by 4 parameters : left, top, width and height.
|
||||||
|
absoluteLayoutModule.AbsoluteLayout.setLeft(label, 10);
|
||||||
|
absoluteLayoutModule.AbsoluteLayout.setTop(label, 10);
|
||||||
|
label.width = 100;
|
||||||
|
label.height = 100;
|
||||||
|
label.text = "LT";
|
||||||
|
label.id = "LT";
|
||||||
|
label.style.backgroundColor = new colorModule.Color("Red");
|
||||||
|
absoluteLayout.addChild(label);
|
||||||
|
// ```
|
||||||
|
// </snippet>
|
||||||
|
}
|
||||||
|
|
||||||
|
public testAll() {
|
||||||
|
|
||||||
|
let absoluteLayout = this.testView;
|
||||||
|
absoluteLayout.width = 230;
|
||||||
|
absoluteLayout.height = 230;
|
||||||
|
absoluteLayout.style.backgroundColor = new colorModule.Color("LightGray");
|
||||||
|
let label = new labelModule.Label();
|
||||||
|
|
||||||
|
absoluteLayoutModule.AbsoluteLayout.setLeft(label, 10);
|
||||||
|
absoluteLayoutModule.AbsoluteLayout.setTop(label, 10);
|
||||||
|
label.width = 100;
|
||||||
|
label.height = 100;
|
||||||
|
label.text = "LT";
|
||||||
|
label.style.backgroundColor = new colorModule.Color("Red");
|
||||||
|
absoluteLayout.addChild(label);
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
let actualValue = label._getCurrentLayoutBounds();
|
||||||
|
let width = actualValue.right - actualValue.left;
|
||||||
|
let height = actualValue.bottom - actualValue.top;
|
||||||
TKUnit.assertEqual(actualValue.left, layoutHelper.dip(10), "ActualLeft");
|
TKUnit.assertEqual(actualValue.left, layoutHelper.dip(10), "ActualLeft");
|
||||||
TKUnit.assertEqual(actualValue.top, layoutHelper.dip(10), "ActualTop");
|
TKUnit.assertEqual(actualValue.top, layoutHelper.dip(10), "ActualTop");
|
||||||
TKUnit.assertEqual(width, layoutHelper.dip(100), "ActualWidth");
|
TKUnit.assertEqual(width, layoutHelper.dip(100), "ActualWidth");
|
||||||
TKUnit.assertEqual(height, layoutHelper.dip(100), "Actualheight");
|
TKUnit.assertEqual(height, layoutHelper.dip(100), "Actualheight");
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function test_padding() {
|
public test_padding() {
|
||||||
var absoluteLayout = new absoluteLayoutModule.AbsoluteLayout();
|
let absoluteLayout = this.testView;
|
||||||
absoluteLayout.width = 200;
|
absoluteLayout.width = 200;
|
||||||
absoluteLayout.height = 200;
|
absoluteLayout.height = 200;
|
||||||
absoluteLayout.paddingLeft = 5;
|
absoluteLayout.paddingLeft = 5;
|
||||||
absoluteLayout.paddingTop = 15;
|
absoluteLayout.paddingTop = 15;
|
||||||
|
|
||||||
// Left Top
|
// Left Top
|
||||||
var btn = new layoutHelper.MyButton();
|
let btn = new layoutHelper.MyButton();
|
||||||
btn.width = 100;
|
btn.width = 100;
|
||||||
btn.height = 100;
|
btn.height = 100;
|
||||||
absoluteLayoutModule.AbsoluteLayout.setLeft(btn, 20);
|
absoluteLayoutModule.AbsoluteLayout.setLeft(btn, 20);
|
||||||
absoluteLayoutModule.AbsoluteLayout.setTop(btn, 20);
|
absoluteLayoutModule.AbsoluteLayout.setTop(btn, 20);
|
||||||
absoluteLayout.addChild(btn);
|
absoluteLayout.addChild(btn);
|
||||||
|
|
||||||
helper.buildUIAndRunTest(absoluteLayout, function (views: Array<viewModule.View>) {
|
|
||||||
TKUnit.waitUntilReady(function isReady() {
|
|
||||||
return absoluteLayout.isLayoutValid;
|
|
||||||
}, 1);
|
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
layoutHelper.assertMeasure(btn, 100, 100);
|
layoutHelper.assertMeasure(btn, 100, 100);
|
||||||
layoutHelper.assertLayout(btn, 25, 35, 100, 100);
|
layoutHelper.assertLayout(btn, 25, 35, 100, 100);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createTestCase(): AbsoluteLayoutTest {
|
||||||
|
return new AbsoluteLayoutTest();
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import {DockLayout} from "ui/layouts/dock-layout";
|
|||||||
import TKUnit = require("../TKUnit");
|
import TKUnit = require("../TKUnit");
|
||||||
import helper = require("./layout-helper");
|
import helper = require("./layout-helper");
|
||||||
import navHelper = require("../ui/helper");
|
import navHelper = require("../ui/helper");
|
||||||
|
import testModule = require("../ui-test");
|
||||||
|
|
||||||
// <snippet module="ui/layouts/dock-layout" title="dock-layout">
|
// <snippet module="ui/layouts/dock-layout" title="dock-layout">
|
||||||
// # DockLayout
|
// # DockLayout
|
||||||
@ -16,11 +17,11 @@ import dockModule = require("ui/layouts/dock-layout");
|
|||||||
//```XML
|
//```XML
|
||||||
//<Page>
|
//<Page>
|
||||||
// <DockLayout stretchLastChild="true" >
|
// <DockLayout stretchLastChild="true" >
|
||||||
// <Button dock="left" text = "left" style ="background-color: red; margin: 5;"/ >/ >
|
// <Button dock="left" text="left" style="background-color: red; margin: 5;"/ >/ >
|
||||||
// <Button dock="top" text = "top" style ="background-color: lightblue; margin: 5;"/ >
|
// <Button dock="top" text="top" style="background-color: lightblue; margin: 5;"/ >
|
||||||
// <Button dock="right" text = "right" style ="background-color: lightgreen; margin: 5;"/ >
|
// <Button dock="right" text="right" style="background-color: lightgreen; margin: 5;"/ >
|
||||||
// <Button dock="bottom" text = "bottom" style ="background-color: lightpink; margin: 5;"/ >
|
// <Button dock="bottom" text="bottom" style="background-color: lightpink; margin: 5;"/ >
|
||||||
// <Button text="fill" style ="background-color: wheat; margin: 5;"/ >
|
// <Button text="fill" style="background-color: wheat; margin: 5;"/ >
|
||||||
// </DockLayout >
|
// </DockLayout >
|
||||||
//</Page>
|
//</Page>
|
||||||
//```
|
//```
|
||||||
@ -32,184 +33,164 @@ import enums = require("ui/enums");
|
|||||||
// ```
|
// ```
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
var testPage: pageModule.Page;
|
export class DockLayoutTest extends testModule.UITest<DockLayout> {
|
||||||
var rootLayout: DockLayout;
|
|
||||||
var tmp: button.Button;
|
|
||||||
|
|
||||||
export function setUpModule() {
|
public create(): DockLayout {
|
||||||
var pageFactory = function () {
|
let rootLayout = new DockLayout();
|
||||||
testPage = new pageModule.Page();
|
rootLayout.height = 300;
|
||||||
tmp = new button.Button();
|
rootLayout.width = 300;
|
||||||
tmp.text = "Loading test";
|
return rootLayout;
|
||||||
testPage.content = tmp;
|
}
|
||||||
return testPage;
|
|
||||||
};
|
|
||||||
|
|
||||||
navHelper.navigate(pageFactory);
|
public test_stretchLastChild_DefaultValue() {
|
||||||
|
TKUnit.assertEqual(this.testView.stretchLastChild, true, "Default stretchLastChild.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_dock_DefaultValue() {
|
||||||
|
var testBtn = new button.Button();
|
||||||
|
var value = dockModule.DockLayout.getDock(testBtn);
|
||||||
|
TKUnit.assertEqual(value, enums.Dock.left, "Default dock value.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_setInvalidDock_Throws() {
|
||||||
|
var testBtn = new button.Button();
|
||||||
|
|
||||||
|
TKUnit.assertThrows(() => {
|
||||||
|
dockModule.DockLayout.setDock(testBtn, "invalid");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_dock_left() {
|
||||||
|
var testBtn = new helper.MyButton();
|
||||||
|
testBtn.width = 20;
|
||||||
|
this.testView.stretchLastChild = false;
|
||||||
|
this.testView.addChild(testBtn);
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
helper.assertLayout(testBtn, 0, 0, 20, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_dock_right() {
|
||||||
|
var testBtn = new helper.MyButton();
|
||||||
|
testBtn.width = 20;
|
||||||
|
dockModule.DockLayout.setDock(testBtn, enums.Dock.right);
|
||||||
|
this.testView.stretchLastChild = false;
|
||||||
|
this.testView.addChild(testBtn);
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
helper.assertLayout(testBtn, 280, 0, 20, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_dock_top() {
|
||||||
|
var testBtn = new helper.MyButton();
|
||||||
|
testBtn.height = 20;
|
||||||
|
dockModule.DockLayout.setDock(testBtn, enums.Dock.top);
|
||||||
|
this.testView.stretchLastChild = false;
|
||||||
|
this.testView.addChild(testBtn);
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
helper.assertLayout(testBtn, 0, 0, 300, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_dock_button() {
|
||||||
|
var testBtn = new helper.MyButton();
|
||||||
|
testBtn.height = 20;
|
||||||
|
dockModule.DockLayout.setDock(testBtn, enums.Dock.bottom);
|
||||||
|
this.testView.stretchLastChild = false;
|
||||||
|
this.testView.addChild(testBtn);
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
helper.assertLayout(testBtn, 0, 280, 300, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_dock_left_stretched() {
|
||||||
|
var testBtn = new helper.MyButton();
|
||||||
|
this.testView.addChild(testBtn);
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
helper.assertLayout(testBtn, 0, 0, 300, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_dock_left_top_righ_bottom_fill() {
|
||||||
|
var testBtnLeft = new helper.MyButton();
|
||||||
|
testBtnLeft.width = 20;
|
||||||
|
this.testView.addChild(testBtnLeft);
|
||||||
|
|
||||||
|
var testBtnTop = new helper.MyButton();
|
||||||
|
testBtnTop.height = 20;
|
||||||
|
dockModule.DockLayout.setDock(testBtnTop, enums.Dock.top);
|
||||||
|
this.testView.addChild(testBtnTop);
|
||||||
|
|
||||||
|
var testBtnRight = new helper.MyButton();
|
||||||
|
testBtnRight.width = 20;
|
||||||
|
dockModule.DockLayout.setDock(testBtnRight, enums.Dock.right);
|
||||||
|
this.testView.addChild(testBtnRight);
|
||||||
|
|
||||||
|
var testBtnBottom = new helper.MyButton();
|
||||||
|
testBtnBottom.height = 20;
|
||||||
|
dockModule.DockLayout.setDock(testBtnBottom, enums.Dock.bottom);
|
||||||
|
this.testView.addChild(testBtnBottom);
|
||||||
|
|
||||||
|
var testBtnFill = new helper.MyButton();
|
||||||
|
dockModule.DockLayout.setDock(testBtnFill, enums.Dock.bottom);
|
||||||
|
this.testView.addChild(testBtnFill);
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
helper.assertLayout(testBtnLeft, 0, 0, 20, 300, "Left button");
|
||||||
|
helper.assertLayout(testBtnTop, 20, 0, 280, 20, "Top button");
|
||||||
|
helper.assertLayout(testBtnRight, 280, 20, 20, 280, "Right button");
|
||||||
|
helper.assertLayout(testBtnBottom, 20, 280, 260, 20, "Bottom button");
|
||||||
|
helper.assertLayout(testBtnFill, 20, 20, 260, 260, "Fill button");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_padding() {
|
||||||
|
var testBtn = new helper.MyButton();
|
||||||
|
this.testView.addChild(testBtn);
|
||||||
|
this.testView.paddingLeft = 10;
|
||||||
|
this.testView.paddingTop = 20;
|
||||||
|
this.testView.paddingRight = 30;
|
||||||
|
this.testView.paddingBottom = 40;
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
helper.assertMeasure(testBtn, 260, 240);
|
||||||
|
helper.assertLayout(testBtn, 10, 20, 260, 240);
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_codesnippets() {
|
||||||
|
// <snippet module="ui/layouts/dock-layout" title="dock-layout">
|
||||||
|
// ## Create DockLayout
|
||||||
|
// ``` JavaScript
|
||||||
|
var dockLayout = new dockModule.DockLayout();
|
||||||
|
// ```
|
||||||
|
|
||||||
|
// ## Add child view to layout
|
||||||
|
// ``` JavaScript
|
||||||
|
var btn = new button.Button();
|
||||||
|
dockLayout.addChild(btn);
|
||||||
|
// ```
|
||||||
|
|
||||||
|
// ## Remove child view from layout
|
||||||
|
// ``` JavaScript
|
||||||
|
dockLayout.removeChild(btn);
|
||||||
|
// ```
|
||||||
|
|
||||||
|
// ## Setting the dock proeprty
|
||||||
|
// ``` JavaScript
|
||||||
|
var btnDockedToRight = new button.Button();
|
||||||
|
dockModule.DockLayout.setDock(btnDockedToRight, enums.Dock.right);
|
||||||
|
dockLayout.addChild(btnDockedToRight);
|
||||||
|
// ```
|
||||||
|
// </snippet>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tearDownModule() {
|
export function createTestCase(): DockLayoutTest {
|
||||||
navHelper.goBack();
|
return new DockLayoutTest();
|
||||||
testPage = null;
|
|
||||||
rootLayout = null;
|
|
||||||
tmp = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setUp() {
|
|
||||||
rootLayout = new DockLayout();
|
|
||||||
rootLayout.height = 300;
|
|
||||||
rootLayout.width = 300;
|
|
||||||
testPage.content = rootLayout;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function tearDown() {
|
|
||||||
testPage.content = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_stretchLastChild_DefaultValue() {
|
|
||||||
TKUnit.assertEqual(rootLayout.stretchLastChild, true, "Default stretchLastChild.");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_dock_DefaultValue() {
|
|
||||||
var testBtn = new button.Button();
|
|
||||||
var value = dockModule.DockLayout.getDock(testBtn);
|
|
||||||
TKUnit.assertEqual(value, enums.Dock.left, "Default dock value.");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_setInvalidDock_Throws() {
|
|
||||||
var testBtn = new button.Button();
|
|
||||||
|
|
||||||
TKUnit.assertThrows(() => {
|
|
||||||
dockModule.DockLayout.setDock(testBtn, "invalid");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_dock_left() {
|
|
||||||
var testBtn = new helper.MyButton();
|
|
||||||
testBtn.width = 20;
|
|
||||||
rootLayout.stretchLastChild = false;
|
|
||||||
rootLayout.addChild(testBtn);
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => { return rootLayout.isLayoutValid; });
|
|
||||||
|
|
||||||
helper.assertLayout(testBtn, 0, 0, 20, 300);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_dock_right() {
|
|
||||||
var testBtn = new helper.MyButton();
|
|
||||||
testBtn.width = 20;
|
|
||||||
dockModule.DockLayout.setDock(testBtn, enums.Dock.right);
|
|
||||||
rootLayout.stretchLastChild = false;
|
|
||||||
rootLayout.addChild(testBtn);
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => { return rootLayout.isLayoutValid; });
|
|
||||||
|
|
||||||
helper.assertLayout(testBtn, 280, 0, 20, 300);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_dock_top() {
|
|
||||||
var testBtn = new helper.MyButton();
|
|
||||||
testBtn.height = 20;
|
|
||||||
dockModule.DockLayout.setDock(testBtn, enums.Dock.top);
|
|
||||||
rootLayout.stretchLastChild = false;
|
|
||||||
rootLayout.addChild(testBtn);
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => { return rootLayout.isLayoutValid; });
|
|
||||||
|
|
||||||
helper.assertLayout(testBtn, 0, 0, 300, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_dock_button() {
|
|
||||||
var testBtn = new helper.MyButton();
|
|
||||||
testBtn.height = 20;
|
|
||||||
dockModule.DockLayout.setDock(testBtn, enums.Dock.bottom);
|
|
||||||
rootLayout.stretchLastChild = false;
|
|
||||||
rootLayout.addChild(testBtn);
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => { return rootLayout.isLayoutValid; });
|
|
||||||
|
|
||||||
helper.assertLayout(testBtn, 0, 280, 300, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_dock_left_stretched() {
|
|
||||||
var testBtn = new helper.MyButton();
|
|
||||||
rootLayout.addChild(testBtn);
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => { return rootLayout.isLayoutValid; });
|
|
||||||
|
|
||||||
helper.assertLayout(testBtn, 0, 0, 300, 300);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_dock_left_top_righ_bottom_fill() {
|
|
||||||
var testBtnLeft = new helper.MyButton();
|
|
||||||
testBtnLeft.width = 20;
|
|
||||||
rootLayout.addChild(testBtnLeft);
|
|
||||||
|
|
||||||
var testBtnTop = new helper.MyButton();
|
|
||||||
testBtnTop.height = 20;
|
|
||||||
dockModule.DockLayout.setDock(testBtnTop, enums.Dock.top);
|
|
||||||
rootLayout.addChild(testBtnTop);
|
|
||||||
|
|
||||||
var testBtnRight = new helper.MyButton();
|
|
||||||
testBtnRight.width = 20;
|
|
||||||
dockModule.DockLayout.setDock(testBtnRight, enums.Dock.right);
|
|
||||||
rootLayout.addChild(testBtnRight);
|
|
||||||
|
|
||||||
var testBtnBottom = new helper.MyButton();
|
|
||||||
testBtnBottom.height = 20;
|
|
||||||
dockModule.DockLayout.setDock(testBtnBottom, enums.Dock.bottom);
|
|
||||||
rootLayout.addChild(testBtnBottom);
|
|
||||||
|
|
||||||
var testBtnFill = new helper.MyButton();
|
|
||||||
dockModule.DockLayout.setDock(testBtnFill, enums.Dock.bottom);
|
|
||||||
rootLayout.addChild(testBtnFill);
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => { return rootLayout.isLayoutValid; });
|
|
||||||
|
|
||||||
helper.assertLayout(testBtnLeft, 0, 0, 20, 300, "Left button");
|
|
||||||
helper.assertLayout(testBtnTop, 20, 0, 280, 20, "Top button");
|
|
||||||
helper.assertLayout(testBtnRight, 280, 20, 20, 280, "Right button");
|
|
||||||
helper.assertLayout(testBtnBottom, 20, 280, 260, 20, "Bottom button");
|
|
||||||
helper.assertLayout(testBtnFill, 20, 20, 260, 260, "Fill button");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_padding() {
|
|
||||||
var testBtn = new helper.MyButton();
|
|
||||||
rootLayout.addChild(testBtn);
|
|
||||||
rootLayout.paddingLeft = 10;
|
|
||||||
rootLayout.paddingTop = 20;
|
|
||||||
rootLayout.paddingRight = 30;
|
|
||||||
rootLayout.paddingBottom = 40;
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => { return rootLayout.isLayoutValid; });
|
|
||||||
|
|
||||||
helper.assertMeasure(testBtn, 260, 240);
|
|
||||||
helper.assertLayout(testBtn, 10, 20, 260, 240);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_codesnippets() {
|
|
||||||
// <snippet module="ui/layouts/dock-layout" title="dock-layout">
|
|
||||||
// ## Create DockLayout
|
|
||||||
// ``` JavaScript
|
|
||||||
var dockLayout = new dockModule.DockLayout();
|
|
||||||
// ```
|
|
||||||
|
|
||||||
// ## Add child view to layout
|
|
||||||
// ``` JavaScript
|
|
||||||
var btn = new button.Button();
|
|
||||||
dockLayout.addChild(btn);
|
|
||||||
// ```
|
|
||||||
|
|
||||||
// ## Remove child view from layout
|
|
||||||
// ``` JavaScript
|
|
||||||
dockLayout.removeChild(btn);
|
|
||||||
// ```
|
|
||||||
|
|
||||||
// ## Setting the dock proeprty
|
|
||||||
// ``` JavaScript
|
|
||||||
var btnDockedToRight = new button.Button();
|
|
||||||
dockModule.DockLayout.setDock(btnDockedToRight, enums.Dock.right);
|
|
||||||
dockLayout.addChild(btnDockedToRight);
|
|
||||||
// ```
|
|
||||||
// </snippet>
|
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@ -6,241 +6,205 @@ import helper = require("./layout-helper");
|
|||||||
import navHelper = require("../ui/helper");
|
import navHelper = require("../ui/helper");
|
||||||
import enums = require("ui/enums");
|
import enums = require("ui/enums");
|
||||||
import utils = require("utils/utils");
|
import utils = require("utils/utils");
|
||||||
|
import testModule = require("../ui-test");
|
||||||
|
|
||||||
var ASYNC = 2;
|
export class StackLayoutTest extends testModule.UITest<StackLayout> {
|
||||||
|
|
||||||
var tmp: Button;
|
private rootLayout: helper.MyStackLayout;
|
||||||
var newPage: Page;
|
private btn1: helper.MyButton;
|
||||||
var rootLayout: helper.MyStackLayout;
|
private btn2: helper.MyButton;
|
||||||
var btn1: helper.MyButton;
|
|
||||||
var btn2: helper.MyButton;
|
|
||||||
|
|
||||||
export function setUpModule() {
|
public create(): StackLayout {
|
||||||
var pageFactory = function () {
|
this.rootLayout = new helper.MyStackLayout();
|
||||||
newPage = new Page();
|
this.btn1 = new helper.MyButton();
|
||||||
tmp = new Button();
|
this.btn1.text = "btn1";
|
||||||
tmp.text = "Loading test";
|
this.rootLayout.addChild(this.btn1);
|
||||||
newPage.content = tmp;
|
this.btn2 = new helper.MyButton();
|
||||||
return newPage;
|
this.btn2.text = "btn2";
|
||||||
};
|
this.rootLayout.addChild(this.btn2);
|
||||||
|
return this.rootLayout;
|
||||||
|
}
|
||||||
|
|
||||||
navHelper.navigate(pageFactory);
|
public test_orientation_DefaultValue() {
|
||||||
|
TKUnit.assertEqual(this.rootLayout.orientation, enums.Orientation.vertical, "Default orientation should be Vertical.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_SetWrongOrientation_ShouldThrowError() {
|
||||||
|
TKUnit.assertThrows(() => { this.rootLayout.orientation = "not_valid"; },
|
||||||
|
"Setting invalid value for orientation should throw exception.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_Orientation_Change() {
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
var arrangeCount = this.rootLayout.arrangeCount;
|
||||||
|
TKUnit.assert(this.rootLayout.orientation === enums.Orientation.vertical, "Default orientation should be Vertical.");
|
||||||
|
|
||||||
|
this.rootLayout.orientation = enums.Orientation.horizontal;
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
TKUnit.assertEqual(this.rootLayout.measureCount, 2, "Orientation change should invalidate measure.");
|
||||||
|
TKUnit.assertEqual(this.rootLayout.arrangeCount, 2, "Orientation change should invalidate arrange.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_ShouldMeasureWith_AtMost_OnVertical() {
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
TKUnit.assertEqual(this.rootLayout.orientation, enums.Orientation.vertical, "StackLayout should be vertical.");
|
||||||
|
TKUnit.assert(this.rootLayout.measured, "Layout should be measured.");
|
||||||
|
TKUnit.assert(this.rootLayout.arranged, "Layout should be arranged.");
|
||||||
|
|
||||||
|
var specs = this.btn1._getCurrentMeasureSpecs();
|
||||||
|
|
||||||
|
TKUnit.assertEqual(utils.layout.getMeasureSpecMode(specs.heightMeasureSpec), utils.layout.AT_MOST, "Layout should measure child with AT_MOST Height in vertical orientation.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_ShouldMeasureWith_AtMost_OnHorizontal() {
|
||||||
|
|
||||||
|
this.rootLayout.orientation = enums.Orientation.horizontal;
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
TKUnit.assert(this.rootLayout.measured, "Layout should be measured.");
|
||||||
|
TKUnit.assert(this.rootLayout.arranged, "Layout should be arranged.");
|
||||||
|
|
||||||
|
var specs = this.btn1._getCurrentMeasureSpecs();
|
||||||
|
|
||||||
|
TKUnit.assertEqual(utils.layout.getMeasureSpecMode(specs.widthMeasureSpec), utils.layout.AT_MOST, "Layout should measure child with AT_MOST Width in horizontal orientation.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_DesiredSize_Vertical() {
|
||||||
|
|
||||||
|
this.rootLayout.verticalAlignment = enums.VerticalAlignment.top;
|
||||||
|
this.rootLayout.horizontalAlignment = enums.HorizontalAlignment.left;
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
TKUnit.assertEqual(this.rootLayout.getMeasuredWidth(), Math.max(this.btn1.getMeasuredWidth(), this.btn2.getMeasuredWidth()), "Layout getMeasuredWidth should be Max of children getMeasuredWidth");
|
||||||
|
TKUnit.assertEqual(this.rootLayout.getMeasuredHeight(), (this.btn1.getMeasuredHeight() + this.btn2.getMeasuredHeight()), "Layout getMeasuredHeight should be Sum of children getMeasuredHeight");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_DesiredSize_Horizontal() {
|
||||||
|
|
||||||
|
this.rootLayout.horizontalAlignment = enums.HorizontalAlignment.left;
|
||||||
|
this.rootLayout.verticalAlignment = enums.VerticalAlignment.top;
|
||||||
|
this.rootLayout.orientation = enums.Orientation.horizontal;
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
TKUnit.assertEqual(this.rootLayout.getMeasuredWidth(), (this.btn1.getMeasuredWidth() + this.btn2.getMeasuredWidth()), "Layout getMeasuredWidth should be Sum of children getMeasuredWidth");
|
||||||
|
TKUnit.assertEqual(this.rootLayout.getMeasuredHeight(), Math.max(this.btn1.getMeasuredHeight(), this.btn2.getMeasuredHeight()), "Layout getMeasuredHeight should be Max of children getMeasuredHeight");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_Padding_Vertical() {
|
||||||
|
this.rootLayout.width = 300;
|
||||||
|
this.rootLayout.height = 300;
|
||||||
|
|
||||||
|
this.rootLayout.paddingLeft = 10;
|
||||||
|
this.rootLayout.paddingTop = 20;
|
||||||
|
this.rootLayout.paddingRight = 30;
|
||||||
|
this.rootLayout.paddingBottom = 40;
|
||||||
|
|
||||||
|
this.btn1.height = 50;
|
||||||
|
this.btn2.height = 50;
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
helper.assertMeasure(this.btn1, 260, 50);
|
||||||
|
helper.assertMeasure(this.btn2, 260, 50);
|
||||||
|
|
||||||
|
helper.assertLayout(this.btn1, 10, 20, 260, 50, "btn1");
|
||||||
|
helper.assertLayout(this.btn2, 10, 70, 260, 50, "btn2");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_Padding_Horizontal() {
|
||||||
|
this.rootLayout.width = 300;
|
||||||
|
this.rootLayout.height = 300;
|
||||||
|
this.rootLayout.orientation = enums.Orientation.horizontal;
|
||||||
|
|
||||||
|
this.rootLayout.paddingLeft = 10;
|
||||||
|
this.rootLayout.paddingTop = 20;
|
||||||
|
this.rootLayout.paddingRight = 30;
|
||||||
|
this.rootLayout.paddingBottom = 40;
|
||||||
|
|
||||||
|
this.btn1.width = 50;
|
||||||
|
this.btn2.width = 50;
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
helper.assertMeasure(this.btn1, 50, 240);
|
||||||
|
helper.assertMeasure(this.btn2, 50, 240);
|
||||||
|
|
||||||
|
helper.assertLayout(this.btn1, 10, 20, 50, 240, "btn1");
|
||||||
|
helper.assertLayout(this.btn2, 60, 20, 50, 240, "btn2");
|
||||||
|
}
|
||||||
|
|
||||||
|
private assertChildTexts(expected, layout, message) {
|
||||||
|
let texts: Array<string> = [];
|
||||||
|
layout._eachChildView((child: { text: string }) => texts.push(child.text));
|
||||||
|
TKUnit.assertEqual(expected, texts.join('|'), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_insertChildAtPosition() {
|
||||||
|
this.assertChildTexts("btn1|btn2", this.rootLayout, "initial 2 buttons");
|
||||||
|
|
||||||
|
let newChild = new Button();
|
||||||
|
newChild.text = 'in-between';
|
||||||
|
this.rootLayout.insertChild(newChild, 1);
|
||||||
|
|
||||||
|
this.assertChildTexts("btn1|in-between|btn2", this.rootLayout, "button inserted at correct location");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_getChildIndex() {
|
||||||
|
let lastChildIndex = this.rootLayout.getChildrenCount() - 1;
|
||||||
|
let lastButton = <Button>this.rootLayout.getChildAt(lastChildIndex);
|
||||||
|
TKUnit.assertEqual("btn2", lastButton.text);
|
||||||
|
TKUnit.assertEqual(lastChildIndex, this.rootLayout.getChildIndex(lastButton));
|
||||||
|
|
||||||
|
let nonChild = new Button();
|
||||||
|
TKUnit.assertEqual(-1, this.rootLayout.getChildIndex(nonChild));
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_codesnippets() {
|
||||||
|
// <snippet module="ui/layouts/stack-layout" title="stack-layout">
|
||||||
|
// ### import StackLayout and Button classes
|
||||||
|
// var StackLayout = require("ui/layouts/stack-layout").StackLayout;
|
||||||
|
// var Button = require("ui/button").Button;
|
||||||
|
// ### Create StackLayout
|
||||||
|
// ``` JavaScript
|
||||||
|
var stackLayout = new StackLayout();
|
||||||
|
// ```
|
||||||
|
|
||||||
|
// ### Declaring a StackLayout.
|
||||||
|
//```XML
|
||||||
|
// <Page>
|
||||||
|
// <StackLayout orientation="horizontal">
|
||||||
|
// <Label text="This is Label 1" />
|
||||||
|
// </StackLayout>
|
||||||
|
// </Page>
|
||||||
|
//```
|
||||||
|
// </snippet>
|
||||||
|
|
||||||
|
// ### Add child view to layout
|
||||||
|
// ``` JavaScript
|
||||||
|
var btn = new Button();
|
||||||
|
stackLayout.addChild(btn);
|
||||||
|
// ```
|
||||||
|
|
||||||
|
// ### Remove child view from layout
|
||||||
|
// ``` JavaScript
|
||||||
|
stackLayout.removeChild(btn);
|
||||||
|
// ```
|
||||||
|
|
||||||
|
// ### Change layout orientation to Horizontal
|
||||||
|
// ``` JavaScript
|
||||||
|
stackLayout.orientation = enums.Orientation.horizontal;
|
||||||
|
// ```
|
||||||
|
|
||||||
|
// </snippet>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tearDownModule() {
|
export function createTestCase(): StackLayoutTest {
|
||||||
navHelper.goBack();
|
return new StackLayoutTest();
|
||||||
tmp = null;
|
|
||||||
newPage = null;
|
|
||||||
rootLayout = null;
|
|
||||||
btn1 = null;
|
|
||||||
btn2 = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setUp() {
|
|
||||||
rootLayout = new helper.MyStackLayout();
|
|
||||||
btn1 = new helper.MyButton();
|
|
||||||
btn1.text = "btn1";
|
|
||||||
rootLayout.addChild(btn1);
|
|
||||||
btn2 = new helper.MyButton();
|
|
||||||
btn2.text = "btn2";
|
|
||||||
rootLayout.addChild(btn2);
|
|
||||||
newPage.content = rootLayout;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function tearDown() {
|
|
||||||
newPage.content = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_orientation_DefaultValue() {
|
|
||||||
TKUnit.assertEqual(rootLayout.orientation, enums.Orientation.vertical, "Default orientation should be Vertical.");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_SetWrongOrientation_ShouldThrowError() {
|
|
||||||
TKUnit.assertThrows(() => { rootLayout.orientation = "not_valid"; },
|
|
||||||
"Setting invalid value for orientation should throw exception.");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_Orientation_Change() {
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return rootLayout.arranged;
|
|
||||||
}, ASYNC);
|
|
||||||
|
|
||||||
var arrangeCount = rootLayout.arrangeCount;
|
|
||||||
TKUnit.assert(rootLayout.orientation === enums.Orientation.vertical, "Default orientation should be Vertical.");
|
|
||||||
|
|
||||||
rootLayout.orientation = enums.Orientation.horizontal;
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return rootLayout.arrangeCount > arrangeCount;
|
|
||||||
}, ASYNC);
|
|
||||||
|
|
||||||
TKUnit.assertEqual(rootLayout.measureCount, 2, "Orientation change should invalidate measure.");
|
|
||||||
TKUnit.assertEqual(rootLayout.arrangeCount, 2, "Orientation change should invalidate arrange.");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_ShouldMeasureWith_AtMost_OnVertical() {
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return btn1.isLayoutValid;
|
|
||||||
}, ASYNC);
|
|
||||||
|
|
||||||
TKUnit.assertEqual(rootLayout.orientation, enums.Orientation.vertical, "StackLayout should be vertical.");
|
|
||||||
TKUnit.assert(rootLayout.measured, "Layout should be measured.");
|
|
||||||
TKUnit.assert(rootLayout.arranged, "Layout should be arranged.");
|
|
||||||
|
|
||||||
var specs = btn1._getCurrentMeasureSpecs();
|
|
||||||
|
|
||||||
TKUnit.assertEqual(utils.layout.getMeasureSpecMode(specs.heightMeasureSpec), utils.layout.AT_MOST, "Layout should measure child with AT_MOST Height in vertical orientation.");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_ShouldMeasureWith_AtMost_OnHorizontal() {
|
|
||||||
|
|
||||||
rootLayout.orientation = enums.Orientation.horizontal;
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return btn1.arranged;
|
|
||||||
}, ASYNC);
|
|
||||||
|
|
||||||
TKUnit.assert(rootLayout.measured, "Layout should be measured.");
|
|
||||||
TKUnit.assert(rootLayout.arranged, "Layout should be arranged.");
|
|
||||||
|
|
||||||
var specs = btn1._getCurrentMeasureSpecs();
|
|
||||||
|
|
||||||
TKUnit.assertEqual(utils.layout.getMeasureSpecMode(specs.widthMeasureSpec), utils.layout.AT_MOST, "Layout should measure child with AT_MOST Width in horizontal orientation.");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_DesiredSize_Vertical() {
|
|
||||||
|
|
||||||
rootLayout.verticalAlignment = enums.VerticalAlignment.top;
|
|
||||||
rootLayout.horizontalAlignment = enums.HorizontalAlignment.left;
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return btn2.arranged;
|
|
||||||
}, ASYNC);
|
|
||||||
|
|
||||||
TKUnit.assertEqual(rootLayout.getMeasuredWidth(), Math.max(btn1.getMeasuredWidth(), btn2.getMeasuredWidth()), "Layout getMeasuredWidth should be Max of children getMeasuredWidth");
|
|
||||||
TKUnit.assertEqual(rootLayout.getMeasuredHeight(), (btn1.getMeasuredHeight() + btn2.getMeasuredHeight()), "Layout getMeasuredHeight should be Sum of children getMeasuredHeight");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_DesiredSize_Horizontal() {
|
|
||||||
|
|
||||||
rootLayout.horizontalAlignment = enums.HorizontalAlignment.left;
|
|
||||||
rootLayout.verticalAlignment = enums.VerticalAlignment.top;
|
|
||||||
rootLayout.orientation = enums.Orientation.horizontal;
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return btn2.arranged;
|
|
||||||
}, ASYNC);
|
|
||||||
|
|
||||||
TKUnit.assertEqual(rootLayout.getMeasuredWidth(), (btn1.getMeasuredWidth() + btn2.getMeasuredWidth()), "Layout getMeasuredWidth should be Sum of children getMeasuredWidth");
|
|
||||||
TKUnit.assertEqual(rootLayout.getMeasuredHeight(), Math.max(btn1.getMeasuredHeight(), btn2.getMeasuredHeight()), "Layout getMeasuredHeight should be Max of children getMeasuredHeight");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_Padding_Vertical() {
|
|
||||||
rootLayout.width = 300;
|
|
||||||
rootLayout.height = 300;
|
|
||||||
|
|
||||||
rootLayout.paddingLeft = 10;
|
|
||||||
rootLayout.paddingTop = 20;
|
|
||||||
rootLayout.paddingRight = 30;
|
|
||||||
rootLayout.paddingBottom = 40;
|
|
||||||
|
|
||||||
btn1.height = 50;
|
|
||||||
btn2.height = 50;
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return btn2.arranged;
|
|
||||||
}, ASYNC);
|
|
||||||
|
|
||||||
helper.assertMeasure(btn1, 260, 50);
|
|
||||||
helper.assertMeasure(btn2, 260, 50);
|
|
||||||
|
|
||||||
helper.assertLayout(btn1, 10, 20, 260, 50, "btn1");
|
|
||||||
helper.assertLayout(btn2, 10, 70, 260, 50, "btn2");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_Padding_Horizontal() {
|
|
||||||
rootLayout.width = 300;
|
|
||||||
rootLayout.height = 300;
|
|
||||||
rootLayout.orientation = enums.Orientation.horizontal;
|
|
||||||
|
|
||||||
rootLayout.paddingLeft = 10;
|
|
||||||
rootLayout.paddingTop = 20;
|
|
||||||
rootLayout.paddingRight = 30;
|
|
||||||
rootLayout.paddingBottom = 40;
|
|
||||||
|
|
||||||
btn1.width = 50;
|
|
||||||
btn2.width = 50;
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return btn2.arranged;
|
|
||||||
}, ASYNC);
|
|
||||||
|
|
||||||
helper.assertMeasure(btn1, 50, 240);
|
|
||||||
helper.assertMeasure(btn2, 50, 240);
|
|
||||||
|
|
||||||
helper.assertLayout(btn1, 10, 20, 50, 240, "btn1");
|
|
||||||
helper.assertLayout(btn2, 60, 20, 50, 240, "btn2");
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertChildTexts(expected, layout, message) {
|
|
||||||
let texts: Array<string> = [];
|
|
||||||
layout._eachChildView((child: {text: string}) => texts.push(child.text));
|
|
||||||
TKUnit.assertEqual(expected, texts.join('|'), message);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_insertChildAtPosition() {
|
|
||||||
assertChildTexts("btn1|btn2", rootLayout, "initial 2 buttons");
|
|
||||||
|
|
||||||
let newChild = new Button();
|
|
||||||
newChild.text = 'in-between';
|
|
||||||
rootLayout.insertChild(newChild, 1);
|
|
||||||
|
|
||||||
assertChildTexts("btn1|in-between|btn2", rootLayout, "button inserted at correct location");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_getChildIndex() {
|
|
||||||
let lastChildIndex = rootLayout.getChildrenCount() - 1;
|
|
||||||
let lastButton = <Button>rootLayout.getChildAt(lastChildIndex);
|
|
||||||
TKUnit.assertEqual("btn2", lastButton.text);
|
|
||||||
TKUnit.assertEqual(lastChildIndex, rootLayout.getChildIndex(lastButton));
|
|
||||||
|
|
||||||
let nonChild = new Button();
|
|
||||||
TKUnit.assertEqual(-1, rootLayout.getChildIndex(nonChild));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_codesnippets() {
|
|
||||||
// <snippet module="ui/layouts/stack-layout" title="stack-layout">
|
|
||||||
// ### Create StackLayout
|
|
||||||
// ``` JavaScript
|
|
||||||
var stackLayout = new StackLayout();
|
|
||||||
// ```
|
|
||||||
|
|
||||||
// ### Declaring a StackLayout.
|
|
||||||
//```XML
|
|
||||||
// <Page>
|
|
||||||
// <StackLayout orientation="horizontal">
|
|
||||||
// <Label text="This is Label 1" />
|
|
||||||
// </StackLayout>
|
|
||||||
// </Page>
|
|
||||||
//```
|
|
||||||
// </snippet>
|
|
||||||
|
|
||||||
// ### Add child view to layout
|
|
||||||
// ``` JavaScript
|
|
||||||
var btn = new Button();
|
|
||||||
stackLayout.addChild(btn);
|
|
||||||
// ```
|
|
||||||
|
|
||||||
// ### Remove child view from layout
|
|
||||||
// ``` JavaScript
|
|
||||||
stackLayout.removeChild(btn);
|
|
||||||
// ```
|
|
||||||
|
|
||||||
// ### Change layout orientation to Horizontal
|
|
||||||
// ``` JavaScript
|
|
||||||
stackLayout.orientation = enums.Orientation.horizontal;
|
|
||||||
// ```
|
|
||||||
|
|
||||||
// </snippet>
|
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ import viewModule = require("ui/core/view");
|
|||||||
import labelModule = require("ui/label");
|
import labelModule = require("ui/label");
|
||||||
import helper = require("../ui/helper");
|
import helper = require("../ui/helper");
|
||||||
import layoutHelper = require("./layout-helper");
|
import layoutHelper = require("./layout-helper");
|
||||||
|
import testModule = require("../ui-test");
|
||||||
|
|
||||||
// <snippet module="ui/layouts/wrap-layout" title="WrapLayout">
|
// <snippet module="ui/layouts/wrap-layout" title="WrapLayout">
|
||||||
// # WrapLayout
|
// # WrapLayout
|
||||||
@ -17,220 +18,174 @@ import enums = require("ui/enums");
|
|||||||
// ```
|
// ```
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
var _createWrapLayoutFunc = function (childCount: number, childWidth?: number, childHeight?: number): wrapLayoutModule.WrapLayout {
|
export class WrapLayoutTest extends testModule.UITest<wrapLayoutModule.WrapLayout> {
|
||||||
// <snippet module="ui/layouts/wrap-layout" title="WrapLayout">
|
|
||||||
// ## Creating a WrapLayout
|
|
||||||
// ``` JavaScript
|
|
||||||
var wrapLayout = new wrapLayoutModule.WrapLayout();
|
|
||||||
// ```
|
|
||||||
// </snippet>
|
|
||||||
|
|
||||||
// ### Declaring a WrapLayout.
|
public create(): wrapLayoutModule.WrapLayout {
|
||||||
//```XML
|
// <snippet module="ui/layouts/wrap-layout" title="WrapLayout">
|
||||||
// <Page>
|
// ## Creating a WrapLayout
|
||||||
// <WrapLayout>
|
// ``` JavaScript
|
||||||
// <Label text="This is Label 1" />
|
var wrapLayout = new wrapLayoutModule.WrapLayout();
|
||||||
// <Label text="This is Label 2" />
|
// ```
|
||||||
// <Label text="This is Label 3" />
|
// </snippet>
|
||||||
// <Label text="This is Label 4" />
|
|
||||||
// </WrapLayout>
|
|
||||||
// </Page>
|
|
||||||
//```
|
|
||||||
// </snippet>
|
|
||||||
|
|
||||||
wrapLayout.width = 200;
|
// ### Declaring a WrapLayout.
|
||||||
wrapLayout.height = 200;
|
//```XML
|
||||||
|
// <Page>
|
||||||
|
// <WrapLayout>
|
||||||
|
// <Label text="This is Label 1" />
|
||||||
|
// <Label text="This is Label 2" />
|
||||||
|
// <Label text="This is Label 3" />
|
||||||
|
// <Label text="This is Label 4" />
|
||||||
|
// </WrapLayout>
|
||||||
|
// </Page>
|
||||||
|
//```
|
||||||
|
// </snippet>
|
||||||
|
|
||||||
var label;
|
wrapLayout.width = 200;
|
||||||
var i;
|
wrapLayout.height = 200;
|
||||||
for (i = 0; i < childCount; i++) {
|
|
||||||
label = new labelModule.Label();
|
|
||||||
label.text = "" + i;
|
|
||||||
label.id = "" + i;
|
|
||||||
|
|
||||||
label.width = childWidth || 100;
|
var label;
|
||||||
label.height = childHeight || 100;
|
var i;
|
||||||
wrapLayout.addChild(label);
|
for (i = 0; i < 2; i++) {
|
||||||
|
label = new labelModule.Label();
|
||||||
|
label.text = "" + i;
|
||||||
|
label.id = "" + i;
|
||||||
|
|
||||||
|
label.width = 100;
|
||||||
|
label.height = 100;
|
||||||
|
wrapLayout.addChild(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrapLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrapLayout;
|
public testHorizontalOrientation() {
|
||||||
}
|
|
||||||
|
|
||||||
export function testHorizontalOrientation() {
|
this.testView.orientation = enums.Orientation.horizontal;
|
||||||
var wrapLayout = _createWrapLayoutFunc(2);
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
wrapLayout.orientation = enums.Orientation.horizontal;
|
|
||||||
helper.buildUIAndRunTest(wrapLayout, function (views: Array<viewModule.View>) {
|
|
||||||
TKUnit.waitUntilReady(function isReady() {
|
|
||||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
|
||||||
}, 1);
|
|
||||||
|
|
||||||
var actualValue = wrapLayout.getChildAt(0)._getCurrentLayoutBounds();
|
let actualValue = this.testView.getChildAt(0)._getCurrentLayoutBounds();
|
||||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 0");
|
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 0");
|
||||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 0");
|
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 0");
|
||||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 0");
|
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 0");
|
||||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 0");
|
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 0");
|
||||||
|
|
||||||
actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds();
|
actualValue = this.testView.getChildAt(1)._getCurrentLayoutBounds();
|
||||||
TKUnit.assertEqual(actualValue.left, layoutHelper.dip(100), "ActualLeft on Index 1");
|
TKUnit.assertEqual(actualValue.left, layoutHelper.dip(100), "ActualLeft on Index 1");
|
||||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 1");
|
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 1");
|
||||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(200), "ActualRight on Index 1");
|
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(200), "ActualRight on Index 1");
|
||||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 1");
|
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 1");
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function testVerticalOrientation() {
|
public testVerticalOrientation() {
|
||||||
var wrapLayout = _createWrapLayoutFunc(2);
|
var wrapLayout = this.testView;
|
||||||
// <snippet module="ui/layouts/wrap-layout" title="WrapLayout">
|
// <snippet module="ui/layouts/wrap-layout" title="WrapLayout">
|
||||||
// ## Setting the orientation of a wrap-layout.
|
// ## Setting the orientation of a wrap-layout.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
wrapLayout.orientation = enums.Orientation.vertical;
|
|
||||||
// ```
|
|
||||||
// </snippet>
|
|
||||||
helper.buildUIAndRunTest(wrapLayout, function (views: Array<viewModule.View>) {
|
|
||||||
TKUnit.waitUntilReady(function isReady() {
|
|
||||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
|
||||||
}, 1);
|
|
||||||
|
|
||||||
var actualValue = viewModule.getViewById(wrapLayout, "0")._getCurrentLayoutBounds();
|
|
||||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 0");
|
|
||||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 0");
|
|
||||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 0");
|
|
||||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 0");
|
|
||||||
|
|
||||||
actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds();
|
|
||||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 1");
|
|
||||||
TKUnit.assertEqual(actualValue.top, layoutHelper.dip(100), "ActualTop on Index 1");
|
|
||||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 1");
|
|
||||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(200), "ActualBottom on Index 1");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function testChangeOrientation() {
|
|
||||||
var wrapLayout = _createWrapLayoutFunc(2);
|
|
||||||
wrapLayout.orientation = enums.Orientation.horizontal;
|
|
||||||
helper.buildUIAndRunTest(wrapLayout, function (views: Array<viewModule.View>) {
|
|
||||||
wrapLayout.orientation = enums.Orientation.vertical;
|
wrapLayout.orientation = enums.Orientation.vertical;
|
||||||
|
// ```
|
||||||
|
// </snippet>
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => {
|
let actualValue = this.testView.getChildAt(0)._getCurrentLayoutBounds();
|
||||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
|
||||||
});
|
|
||||||
|
|
||||||
var actualValue = viewModule.getViewById(wrapLayout, "0")._getCurrentLayoutBounds();
|
|
||||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 0");
|
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 0");
|
||||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 0");
|
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 0");
|
||||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 0");
|
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 0");
|
||||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 0");
|
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 0");
|
||||||
|
|
||||||
actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds();
|
actualValue = this.testView.getChildAt(1)._getCurrentLayoutBounds();
|
||||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 1");
|
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 1");
|
||||||
TKUnit.assertEqual(actualValue.top, layoutHelper.dip(100), "ActualTop on Index 1");
|
TKUnit.assertEqual(actualValue.top, layoutHelper.dip(100), "ActualTop on Index 1");
|
||||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 1");
|
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 1");
|
||||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(200), "ActualBottom on Index 1");
|
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(200), "ActualBottom on Index 1");
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function testItemWidth() {
|
public testChangeOrientation() {
|
||||||
var wrapLayout = _createWrapLayoutFunc(2);
|
this.testView.orientation = enums.Orientation.horizontal;
|
||||||
wrapLayout.itemWidth = 50;
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
helper.buildUIAndRunTest(wrapLayout, function (views: Array<viewModule.View>) {
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
TKUnit.waitUntilReady(function isReady() {
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
|
||||||
}, 1);
|
|
||||||
|
|
||||||
var actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds().left;
|
let actualValue = this.testView.getChildAt(0)._getCurrentLayoutBounds();
|
||||||
|
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 0");
|
||||||
|
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 0");
|
||||||
|
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 0");
|
||||||
|
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 0");
|
||||||
|
|
||||||
|
actualValue = this.testView.getChildAt(1)._getCurrentLayoutBounds();
|
||||||
|
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 1");
|
||||||
|
TKUnit.assertEqual(actualValue.top, layoutHelper.dip(100), "ActualTop on Index 1");
|
||||||
|
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 1");
|
||||||
|
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(200), "ActualBottom on Index 1");
|
||||||
|
}
|
||||||
|
|
||||||
|
public testItemWidth() {
|
||||||
|
this.testView.itemWidth = 50;
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
let actualValue = this.testView.getChildAt(1)._getCurrentLayoutBounds().left;
|
||||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualLeft on Index 1");
|
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualLeft on Index 1");
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function testChangeItemWidth() {
|
public testChangeItemWidth() {
|
||||||
var wrapLayout = _createWrapLayoutFunc(2);
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
helper.buildUIAndRunTest(wrapLayout, function (views: Array<viewModule.View>) {
|
this.testView.itemWidth = 50;
|
||||||
TKUnit.waitUntilReady(() => {
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
|
||||||
});
|
|
||||||
|
|
||||||
wrapLayout.itemWidth = 50;
|
let actualValue = this.testView.getChildAt(1)._getCurrentLayoutBounds().left;
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => {
|
|
||||||
return wrapLayout.isLayoutValid;
|
|
||||||
});
|
|
||||||
|
|
||||||
var actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds().left;
|
|
||||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualLeft on Index 1");
|
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualLeft on Index 1");
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function testItemHeight() {
|
public testItemHeight() {
|
||||||
var wrapLayout = _createWrapLayoutFunc(2);
|
this.testView.itemHeight = 50;
|
||||||
wrapLayout.itemHeight = 50;
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
wrapLayout.orientation = enums.Orientation.vertical;
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
helper.buildUIAndRunTest(wrapLayout, function (views: Array<viewModule.View>) {
|
|
||||||
TKUnit.waitUntilReady(function isReady() {
|
|
||||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
|
||||||
}, 1);
|
|
||||||
|
|
||||||
var actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds().top;
|
let actualValue = this.testView.getChildAt(1)._getCurrentLayoutBounds().top;
|
||||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualTop on Index 1");
|
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualTop on Index 1");
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function testChangeItemHeight() {
|
public testChangeItemHeight() {
|
||||||
var wrapLayout = _createWrapLayoutFunc(2);
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
wrapLayout.orientation = enums.Orientation.vertical;
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
helper.buildUIAndRunTest(wrapLayout, function (views: Array<viewModule.View>) {
|
this.testView.itemHeight = 50;
|
||||||
TKUnit.waitUntilReady(() => {
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
|
||||||
});
|
|
||||||
|
|
||||||
wrapLayout.itemHeight = 50;
|
let actualValue = this.testView.getChildAt(1)._getCurrentLayoutBounds().top;
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => {
|
|
||||||
return wrapLayout.isLayoutValid;
|
|
||||||
});
|
|
||||||
|
|
||||||
var actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds().top;
|
|
||||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualTop on Index 1");
|
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualTop on Index 1");
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function testPaddingLeftAndTop() {
|
public testPaddingLeftAndTop() {
|
||||||
var wrapLayout = new wrapLayoutModule.WrapLayout();
|
this.testView.removeChildren();
|
||||||
wrapLayout.paddingLeft = 20;
|
this.testView.paddingLeft = 20;
|
||||||
wrapLayout.paddingTop = 30;
|
this.testView.paddingTop = 30;
|
||||||
|
|
||||||
var btn = new layoutHelper.MyButton();
|
var btn = new layoutHelper.MyButton();
|
||||||
btn.width = 50;
|
btn.width = 50;
|
||||||
btn.height = 50;
|
btn.height = 50;
|
||||||
wrapLayout.addChild(btn);
|
this.testView.addChild(btn);
|
||||||
|
|
||||||
helper.buildUIAndRunTest(wrapLayout, function (views: Array<viewModule.View>) {
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
TKUnit.waitUntilReady(() => {
|
|
||||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
|
||||||
});
|
|
||||||
|
|
||||||
layoutHelper.assertLayout(btn, 20, 30, 50, 50);
|
layoutHelper.assertLayout(btn, 20, 30, 50, 50);
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function testPaddingRight() {
|
public testPaddingRight() {
|
||||||
var wrapLayout = new wrapLayoutModule.WrapLayout();
|
this.testView.removeChildren();
|
||||||
wrapLayout.paddingRight = 30;
|
this.testView.paddingRight = 30;
|
||||||
wrapLayout.width = 200;
|
this.testView.width = 200;
|
||||||
|
|
||||||
var btn1 = new layoutHelper.MyButton();
|
var btn1 = new layoutHelper.MyButton();
|
||||||
wrapLayout.addChild(btn1);
|
this.testView.addChild(btn1);
|
||||||
btn1.width = 100;
|
btn1.width = 100;
|
||||||
btn1.height = 50;
|
btn1.height = 50;
|
||||||
|
|
||||||
var btn2 = new layoutHelper.MyButton();
|
var btn2 = new layoutHelper.MyButton();
|
||||||
btn2.width = 80;
|
btn2.width = 80;
|
||||||
btn2.height = 50;
|
btn2.height = 50;
|
||||||
wrapLayout.addChild(btn2);
|
this.testView.addChild(btn2);
|
||||||
|
|
||||||
helper.buildUIAndRunTest(wrapLayout, function (views: Array<viewModule.View>) {
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
TKUnit.waitUntilReady(() => {
|
|
||||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
|
||||||
});
|
|
||||||
|
|
||||||
layoutHelper.assertMeasure(btn1, 100, 50);
|
layoutHelper.assertMeasure(btn1, 100, 50);
|
||||||
layoutHelper.assertMeasure(btn2, 80, 50);
|
layoutHelper.assertMeasure(btn2, 80, 50);
|
||||||
@ -239,29 +194,25 @@ export function testPaddingRight() {
|
|||||||
// because for the padding (200 - 100 - 30) = 70 button wants 80
|
// because for the padding (200 - 100 - 30) = 70 button wants 80
|
||||||
layoutHelper.assertLayout(btn1, 0, 0, 100, 50, "button1");
|
layoutHelper.assertLayout(btn1, 0, 0, 100, 50, "button1");
|
||||||
layoutHelper.assertLayout(btn2, 0, 50, 80, 50, "button2");
|
layoutHelper.assertLayout(btn2, 0, 50, 80, 50, "button2");
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function testPaddingBottom() {
|
public testPaddingBottom() {
|
||||||
var wrapLayout = new wrapLayoutModule.WrapLayout();
|
this.testView.removeChildren();
|
||||||
wrapLayout.paddingBottom = 30;
|
this.testView.paddingBottom = 30;
|
||||||
wrapLayout.height = 200;
|
this.testView.height = 200;
|
||||||
wrapLayout.orientation = enums.Orientation.vertical;
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
|
|
||||||
var btn1 = new layoutHelper.MyButton();
|
var btn1 = new layoutHelper.MyButton();
|
||||||
wrapLayout.addChild(btn1);
|
this.testView.addChild(btn1);
|
||||||
btn1.width = 50;
|
btn1.width = 50;
|
||||||
btn1.height = 100;
|
btn1.height = 100;
|
||||||
|
|
||||||
var btn2 = new layoutHelper.MyButton();
|
var btn2 = new layoutHelper.MyButton();
|
||||||
btn2.width = 50;
|
btn2.width = 50;
|
||||||
btn2.height = 80;
|
btn2.height = 80;
|
||||||
wrapLayout.addChild(btn2);
|
this.testView.addChild(btn2);
|
||||||
|
|
||||||
helper.buildUIAndRunTest(wrapLayout, function (views: Array<viewModule.View>) {
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
TKUnit.waitUntilReady(() => {
|
|
||||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
|
||||||
});
|
|
||||||
|
|
||||||
layoutHelper.assertMeasure(btn1, 50, 100);
|
layoutHelper.assertMeasure(btn1, 50, 100);
|
||||||
layoutHelper.assertMeasure(btn2, 50, 80);
|
layoutHelper.assertMeasure(btn2, 50, 80);
|
||||||
@ -270,5 +221,9 @@ export function testPaddingBottom() {
|
|||||||
// because of the padding (200 - 100 - 30) = 70 button wants 80
|
// because of the padding (200 - 100 - 30) = 70 button wants 80
|
||||||
layoutHelper.assertLayout(btn1, 0, 0, 50, 100, "button1");
|
layoutHelper.assertLayout(btn1, 0, 0, 50, 100, "button1");
|
||||||
layoutHelper.assertLayout(btn2, 50, 0, 50, 80, "button2");
|
layoutHelper.assertLayout(btn2, 50, 0, 50, 80, "button2");
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createTestCase(): WrapLayoutTest {
|
||||||
|
return new WrapLayoutTest();
|
||||||
}
|
}
|
@ -128,6 +128,27 @@ function printRunTestStats() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function time(): number {
|
||||||
|
if (global.android) {
|
||||||
|
return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return CACurrentMediaTime() * 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startLog(): void {
|
||||||
|
let testsName: string = this.name;
|
||||||
|
TKUnit.write("START " + testsName + " TESTS.", trace.messageType.info);
|
||||||
|
this.start = time();
|
||||||
|
}
|
||||||
|
|
||||||
|
function log(): void {
|
||||||
|
let testsName: string = this.name;
|
||||||
|
let duration = time() - this.start;
|
||||||
|
TKUnit.write(testsName + " COMPLETED for " + duration, trace.messageType.info);
|
||||||
|
}
|
||||||
|
|
||||||
export var runAll = function (moduleName?: string) {
|
export var runAll = function (moduleName?: string) {
|
||||||
if (running) {
|
if (running) {
|
||||||
// TODO: We may schedule pending run requests
|
// TODO: We may schedule pending run requests
|
||||||
@ -143,19 +164,18 @@ export var runAll = function (moduleName?: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var testModule = allTests[name];
|
var testModule = allTests[name];
|
||||||
//var moduleStart = function (moduleName) {
|
|
||||||
// return function () {
|
|
||||||
// TKUnit.write("--- " + moduleName + " TESTS BEGIN ---", trace.messageType.info);
|
|
||||||
// }
|
|
||||||
//};
|
|
||||||
//testsQueue.push(new TestInfo(moduleStart(name)));
|
|
||||||
|
|
||||||
var test = testModule.createTestCase ? testModule.createTestCase() : testModule;
|
var test = testModule.createTestCase ? testModule.createTestCase() : testModule;
|
||||||
|
test.name = name;
|
||||||
|
|
||||||
|
|
||||||
|
testsQueue.push(new TestInfo(startLog, test));
|
||||||
|
|
||||||
if (test.setUpModule) {
|
if (test.setUpModule) {
|
||||||
testsQueue.push(new TestInfo(test.setUpModule, test));
|
testsQueue.push(new TestInfo(test.setUpModule, test));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (var testName in test) {
|
for (var testName in test) {
|
||||||
var testFunction = test[testName];
|
var testFunction = test[testName];
|
||||||
if ((typeof (testFunction) === "function") && (testName.substring(0, 4) == "test")) {
|
if ((typeof (testFunction) === "function") && (testName.substring(0, 4) == "test")) {
|
||||||
@ -172,13 +192,7 @@ export var runAll = function (moduleName?: string) {
|
|||||||
if (test.tearDownModule) {
|
if (test.tearDownModule) {
|
||||||
testsQueue.push(new TestInfo(test.tearDownModule, test));
|
testsQueue.push(new TestInfo(test.tearDownModule, test));
|
||||||
}
|
}
|
||||||
|
testsQueue.push(new TestInfo(log, test));
|
||||||
//var moduleEnd = function (moduleName) {
|
|
||||||
// return function () {
|
|
||||||
// TKUnit.write("--- " + moduleName + " TESTS COMPLETE --- ", trace.messageType.info);
|
|
||||||
// };
|
|
||||||
//}
|
|
||||||
//testsQueue.push(new TestInfo(moduleEnd(name)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
testsQueue.push(new TestInfo(printRunTestStats));
|
testsQueue.push(new TestInfo(printRunTestStats));
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import pageModule = require("ui/page");
|
import {Page} from "ui/page";
|
||||||
import navHelper = require("./ui/helper");
|
import {View} from "ui/core/view";
|
||||||
import viewModule = require("ui/core/view");
|
|
||||||
import trace = require("trace");
|
import trace = require("trace");
|
||||||
|
import navHelper = require("./ui/helper");
|
||||||
import TKUnit = require("./TKUnit");
|
import TKUnit = require("./TKUnit");
|
||||||
|
|
||||||
export class UITest<T extends viewModule.View> implements trace.TraceWriter {
|
export class UITest<T extends View> implements trace.TraceWriter {
|
||||||
|
|
||||||
private _testPage: pageModule.Page;
|
private _testPage: Page;
|
||||||
private _testView: T;
|
private _testView: T;
|
||||||
private _errorMessage;
|
private _errorMessage;
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ export class UITest<T extends viewModule.View> implements trace.TraceWriter {
|
|||||||
return this._errorMessage;
|
return this._errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get testPage(): pageModule.Page {
|
public get testPage(): Page {
|
||||||
return this._testPage;
|
return this._testPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ export class UITest<T extends viewModule.View> implements trace.TraceWriter {
|
|||||||
public setUpModule(): void {
|
public setUpModule(): void {
|
||||||
|
|
||||||
var pageFactory = () => {
|
var pageFactory = () => {
|
||||||
var page = new pageModule.Page();
|
var page = new Page();
|
||||||
this._testPage = page;
|
this._testPage = page;
|
||||||
return page;
|
return page;
|
||||||
};
|
};
|
||||||
@ -67,6 +67,7 @@ export class UITest<T extends viewModule.View> implements trace.TraceWriter {
|
|||||||
this._testPage.content = null;
|
this._testPage.content = null;
|
||||||
this._testPage.bindingContext = null;
|
this._testPage.bindingContext = null;
|
||||||
this._testPage.css = "";
|
this._testPage.css = "";
|
||||||
|
this._testView = null;
|
||||||
this._errorMessage = undefined;
|
this._errorMessage = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +78,6 @@ export class UITest<T extends viewModule.View> implements trace.TraceWriter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createTestCase(): UITest<viewModule.View> {
|
export function createTestCase(): UITest<View> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
@ -5,6 +5,7 @@ import buttonModule = require("ui/button");
|
|||||||
import page = require("ui/page");
|
import page = require("ui/page");
|
||||||
import button = require("ui/button");
|
import button = require("ui/button");
|
||||||
import enums = require("ui/enums");
|
import enums = require("ui/enums");
|
||||||
|
import testModule = require("../../ui-test");
|
||||||
|
|
||||||
// <snippet module="ui/scroll-view" title="scroll-view">
|
// <snippet module="ui/scroll-view" title="scroll-view">
|
||||||
// # ScrollView
|
// # ScrollView
|
||||||
@ -24,278 +25,248 @@ import scrollViewModule = require("ui/scroll-view");
|
|||||||
|
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
var ASYNC = 5;
|
class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||||
var tmp: buttonModule.Button;
|
public create(): scrollViewModule.ScrollView {
|
||||||
var newPage: page.Page;
|
return new scrollViewModule.ScrollView();
|
||||||
|
|
||||||
// <snippet module="ui/scroll-view" title="scroll-view">
|
|
||||||
// ### Creating a ScrollView
|
|
||||||
// ``` JavaScript
|
|
||||||
var scrollView = new scrollViewModule.ScrollView();
|
|
||||||
// ```
|
|
||||||
// </snippet>
|
|
||||||
|
|
||||||
export function setUpModule() {
|
|
||||||
var pageFactory = function (): page.Page {
|
|
||||||
newPage = new page.Page();
|
|
||||||
tmp = new buttonModule.Button();
|
|
||||||
tmp.text = "Loading test";
|
|
||||||
newPage.content = tmp;
|
|
||||||
return newPage;
|
|
||||||
};
|
|
||||||
|
|
||||||
helper.navigate(pageFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function tearDownModule() {
|
|
||||||
helper.goBack();
|
|
||||||
tmp = null;
|
|
||||||
newPage = null;
|
|
||||||
scrollView = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setUp() {
|
|
||||||
scrollView = new scrollViewModule.ScrollView();
|
|
||||||
newPage.content = scrollView;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function tearDown() {
|
|
||||||
newPage.content = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
function waitForLayout() {
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return scrollView.content.isLayoutValid;
|
|
||||||
}, ASYNC);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_default_TNS_values() {
|
|
||||||
TKUnit.assertEqual(scrollView.orientation, enums.Orientation.vertical, "Default scrollView.orientation");
|
|
||||||
TKUnit.assertEqual(scrollView.verticalOffset, 0, "Default scrollView.verticalOffset");
|
|
||||||
TKUnit.assertEqual(scrollView.horizontalOffset, 0, "Default scrollView.horizontalOffset");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_vertical_oriantation_creates_correct_native_view() {
|
|
||||||
scrollView.orientation = enums.Orientation.vertical;
|
|
||||||
|
|
||||||
if (app.android) {
|
|
||||||
TKUnit.assert(scrollView.android instanceof android.widget.ScrollView, "android property is android.widget.ScrollView");
|
|
||||||
}
|
}
|
||||||
else if (app.ios) {
|
|
||||||
TKUnit.assert(scrollView.ios instanceof UIScrollView, "ios property is UIScrollView");
|
public test_snippets() {
|
||||||
|
// <snippet module="ui/scroll-view" title="scroll-view">
|
||||||
|
// ### Creating a ScrollView
|
||||||
|
// ``` JavaScript
|
||||||
|
var scrollView = new scrollViewModule.ScrollView();
|
||||||
|
// ```
|
||||||
|
// </snippet>
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_default_TNS_values() {
|
||||||
|
TKUnit.assertEqual(this.testView.orientation, enums.Orientation.vertical, "Default this.testView.orientation");
|
||||||
|
TKUnit.assertEqual(this.testView.verticalOffset, 0, "Default this.testView.verticalOffset");
|
||||||
|
TKUnit.assertEqual(this.testView.horizontalOffset, 0, "Default this.testView.horizontalOffset");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_vertical_oriantation_creates_correct_native_view() {
|
||||||
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
|
|
||||||
|
if (app.android) {
|
||||||
|
TKUnit.assert(this.testView.android instanceof org.nativescript.widgets.VerticalScrollView, "android property should be instanceof org.nativescript.widgets.VerticalScrollView");
|
||||||
|
}
|
||||||
|
else if (app.ios) {
|
||||||
|
TKUnit.assert(this.testView.ios instanceof UIScrollView, "ios property is UIScrollView");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_horizontal_oriantation_creates_correct_native_view() {
|
||||||
|
this.testView.orientation = enums.Orientation.horizontal;
|
||||||
|
|
||||||
|
if (app.android) {
|
||||||
|
TKUnit.assert(this.testView.android instanceof org.nativescript.widgets.HorizontalScrollView, "android property should be instanceof org.nativescript.widgets.HorizontalScrollView");
|
||||||
|
}
|
||||||
|
else if (app.ios) {
|
||||||
|
TKUnit.assert(this.testView.ios instanceof UIScrollView, "ios property is UIScrollView");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_scrollabeHeight_vertical_orientation_when_content_is_small() {
|
||||||
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
|
this.testView.width = 200;
|
||||||
|
this.testView.height = 300;
|
||||||
|
|
||||||
|
let btn = new button.Button();
|
||||||
|
btn.text = "test";
|
||||||
|
btn.height = 100;
|
||||||
|
this.testView.content = btn;
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
TKUnit.assertEqual(this.testView.scrollableHeight, 0, "this.testView.scrollableHeight");
|
||||||
|
TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_scrollabeHeight_vertical_orientation_when_content_is_big() {
|
||||||
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
|
|
||||||
|
this.testView.width = 200;
|
||||||
|
this.testView.height = 300;
|
||||||
|
|
||||||
|
let btn = new button.Button();
|
||||||
|
btn.text = "test";
|
||||||
|
btn.height = 500;
|
||||||
|
this.testView.content = btn;
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
TKUnit.assertAreClose(this.testView.scrollableHeight, 200, 0.4, "this.testView.scrollableHeight");
|
||||||
|
TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_scrollabeWidth_horizontal_orientation_when_content_is_small() {
|
||||||
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
|
this.testView.width = 200;
|
||||||
|
this.testView.height = 300;
|
||||||
|
|
||||||
|
let btn = new button.Button();
|
||||||
|
btn.text = "test";
|
||||||
|
btn.width = 100;
|
||||||
|
this.testView.content = btn;
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
TKUnit.assertEqual(this.testView.scrollableHeight, 0, "this.testView.scrollableHeight");
|
||||||
|
TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_scrollabeWidth_horizontal_orientation_when_content_is_big() {
|
||||||
|
this.testView.orientation = enums.Orientation.horizontal;
|
||||||
|
|
||||||
|
this.testView.width = 200;
|
||||||
|
this.testView.height = 300;
|
||||||
|
|
||||||
|
let btn = new button.Button();
|
||||||
|
btn.text = "test";
|
||||||
|
btn.width = 500;
|
||||||
|
this.testView.content = btn;
|
||||||
|
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
TKUnit.assertEqual(this.testView.scrollableHeight, 0, "this.testView.scrollableHeight");
|
||||||
|
TKUnit.assertAreClose(this.testView.scrollableWidth, 300, 0.4, "this.testView.scrollableWidth");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_scrollToVerticalOffset_no_animation() {
|
||||||
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
|
|
||||||
|
this.testView.width = 200;
|
||||||
|
this.testView.height = 300;
|
||||||
|
|
||||||
|
let btn = new button.Button();
|
||||||
|
btn.text = "test";
|
||||||
|
btn.height = 500;
|
||||||
|
this.testView.content = btn;
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
TKUnit.assertEqual(this.testView.verticalOffset, 0, "this.testView.verticalOffset");
|
||||||
|
this.testView.scrollToVerticalOffset(100, false);
|
||||||
|
TKUnit.assertAreClose(this.testView.verticalOffset, 100, 0.1, "this.testView.verticalOffset");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_scrollToVerticalOffset_with_animation() {
|
||||||
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
|
|
||||||
|
this.testView.width = 200;
|
||||||
|
this.testView.height = 300;
|
||||||
|
|
||||||
|
let btn = new button.Button();
|
||||||
|
btn.text = "test";
|
||||||
|
btn.height = 500;
|
||||||
|
this.testView.content = btn;
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
TKUnit.assertEqual(this.testView.verticalOffset, 0, "this.testView.verticalOffset");
|
||||||
|
this.testView.scrollToVerticalOffset(100, true);
|
||||||
|
|
||||||
|
// No synchronous change.
|
||||||
|
TKUnit.assertEqual(this.testView.verticalOffset, 0, "this.testView.verticalOffset");
|
||||||
|
|
||||||
|
TKUnit.waitUntilReady(() => { return TKUnit.areClose(this.testView.verticalOffset, 100, 0.1); });
|
||||||
|
|
||||||
|
// The scrolling animation should be finished by now
|
||||||
|
TKUnit.assertAreClose(this.testView.verticalOffset, 100, 0.1, "this.testView.verticalOffset");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_scrollToHorizontalOffset_no_animation() {
|
||||||
|
this.testView.orientation = enums.Orientation.horizontal;
|
||||||
|
|
||||||
|
this.testView.width = 200;
|
||||||
|
this.testView.height = 300;
|
||||||
|
|
||||||
|
let btn = new button.Button();
|
||||||
|
btn.text = "test";
|
||||||
|
btn.width = 500;
|
||||||
|
this.testView.content = btn;
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
TKUnit.assertEqual(this.testView.horizontalOffset, 0, "this.testView.horizontalOffset");
|
||||||
|
this.testView.scrollToHorizontalOffset(100, false);
|
||||||
|
TKUnit.assertAreClose(this.testView.horizontalOffset, 100, 0.1, "this.testView.horizontalOffset");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_scrollToHorizontalOffset_with_animation() {
|
||||||
|
this.testView.orientation = enums.Orientation.horizontal;
|
||||||
|
|
||||||
|
this.testView.width = 200;
|
||||||
|
this.testView.height = 300;
|
||||||
|
|
||||||
|
let btn = new button.Button();
|
||||||
|
btn.text = "test";
|
||||||
|
btn.width = 500;
|
||||||
|
this.testView.content = btn;
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
TKUnit.assertEqual(this.testView.horizontalOffset, 0, "this.testView.horizontalOffset");
|
||||||
|
this.testView.scrollToHorizontalOffset(100, true);
|
||||||
|
|
||||||
|
// No synchronous change.
|
||||||
|
TKUnit.assertEqual(this.testView.horizontalOffset, 0, "this.testView.horizontalOffset");
|
||||||
|
|
||||||
|
TKUnit.waitUntilReady(() => { return TKUnit.areClose(this.testView.horizontalOffset, 100, 0.1); });
|
||||||
|
|
||||||
|
// The scrolling animation should be finished by now
|
||||||
|
TKUnit.assertAreClose(this.testView.horizontalOffset, 100, 0.1, "this.testView.horizontalOffset");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_scrollView_persistsState_vertical() {
|
||||||
|
this.testView.orientation = enums.Orientation.vertical;
|
||||||
|
|
||||||
|
this.testView.width = 200;
|
||||||
|
this.testView.height = 300;
|
||||||
|
|
||||||
|
var btn = new button.Button();
|
||||||
|
btn.text = "test";
|
||||||
|
btn.height = 500;
|
||||||
|
this.testView.content = btn;
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
this.testView.scrollToVerticalOffset(100, false);
|
||||||
|
|
||||||
|
TKUnit.assertAreClose(this.testView.verticalOffset, 100, 0.1, "this.testView.verticalOffset before navigation");
|
||||||
|
|
||||||
|
helper.do_PageTest_WithButton((t) => {
|
||||||
|
// Just navigate forward and back.
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for the page to reload.
|
||||||
|
TKUnit.waitUntilReady(() => { return TKUnit.areClose(this.testView.verticalOffset, 100, 0.1); });
|
||||||
|
|
||||||
|
// Check verticalOffset after navigation
|
||||||
|
TKUnit.assertAreClose(this.testView.verticalOffset, 100, 0.1, "this.testView.verticalOffset after navigation");
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_scrollView_persistsState_horizontal() {
|
||||||
|
this.testView.orientation = enums.Orientation.horizontal;
|
||||||
|
|
||||||
|
this.testView.width = 200;
|
||||||
|
this.testView.height = 300;
|
||||||
|
|
||||||
|
var btn = new button.Button();
|
||||||
|
btn.text = "test";
|
||||||
|
btn.width = 500;
|
||||||
|
this.testView.content = btn;
|
||||||
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
|
||||||
|
this.testView.scrollToHorizontalOffset(100, false);
|
||||||
|
|
||||||
|
TKUnit.assertAreClose(this.testView.horizontalOffset, 100, 0.1, "this.testView.horizontalOffset before navigation");
|
||||||
|
|
||||||
|
helper.do_PageTest_WithButton((t) => {
|
||||||
|
// Just navigate forward and back.
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for the page to reload.
|
||||||
|
TKUnit.waitUntilReady(() => { return TKUnit.areClose(this.testView.horizontalOffset, 100, 0.1); });
|
||||||
|
|
||||||
|
// Check verticalOffset after navigation
|
||||||
|
TKUnit.assertAreClose(this.testView.horizontalOffset, 100, 0.1, "this.testView.horizontalOffset after navigation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function test_horizontal_oriantation_creates_correct_native_view() {
|
export function createTestCase(): ScrollLayoutTest {
|
||||||
scrollView.orientation = enums.Orientation.horizontal;
|
return new ScrollLayoutTest();
|
||||||
|
|
||||||
if (app.android) {
|
|
||||||
TKUnit.assert(scrollView.android instanceof android.widget.HorizontalScrollView, "android property is android.widget.HorizontalScrollView");
|
|
||||||
}
|
|
||||||
else if (app.ios) {
|
|
||||||
TKUnit.assert(scrollView.ios instanceof UIScrollView, "ios property is UIScrollView");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_scrollabeHeight_vertical_orientation_when_content_is_small() {
|
|
||||||
scrollView.orientation = enums.Orientation.vertical;
|
|
||||||
scrollView.width = 200;
|
|
||||||
scrollView.height = 300;
|
|
||||||
|
|
||||||
var btn = new button.Button();
|
|
||||||
btn.text = "test";
|
|
||||||
btn.height = 100;
|
|
||||||
scrollView.content = btn;
|
|
||||||
|
|
||||||
waitForLayout();
|
|
||||||
TKUnit.assertEqual(scrollView.scrollableHeight, 0, "scrollView.scrollableHeight");
|
|
||||||
TKUnit.assertEqual(scrollView.scrollableWidth, 0, "scrollView.scrollableWidth");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_scrollabeHeight_vertical_orientation_when_content_is_big() {
|
|
||||||
scrollView.orientation = enums.Orientation.vertical;
|
|
||||||
|
|
||||||
scrollView.width = 200;
|
|
||||||
scrollView.height = 300;
|
|
||||||
|
|
||||||
var btn = new button.Button();
|
|
||||||
btn.text = "test";
|
|
||||||
btn.height = 500;
|
|
||||||
scrollView.content = btn;
|
|
||||||
|
|
||||||
waitForLayout();
|
|
||||||
TKUnit.assertAreClose(scrollView.scrollableHeight, 200, 0.4, "scrollView.scrollableHeight");
|
|
||||||
TKUnit.assertEqual(scrollView.scrollableWidth, 0, "scrollView.scrollableWidth");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_scrollabeWidth_horizontal_orientation_when_content_is_small() {
|
|
||||||
scrollView.orientation = enums.Orientation.vertical;
|
|
||||||
scrollView.width = 200;
|
|
||||||
scrollView.height = 300;
|
|
||||||
|
|
||||||
var btn = new button.Button();
|
|
||||||
btn.text = "test";
|
|
||||||
btn.width = 100;
|
|
||||||
scrollView.content = btn;
|
|
||||||
|
|
||||||
waitForLayout();
|
|
||||||
TKUnit.assertEqual(scrollView.scrollableHeight, 0, "scrollView.scrollableHeight");
|
|
||||||
TKUnit.assertEqual(scrollView.scrollableWidth, 0, "scrollView.scrollableWidth");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_scrollabeWidth_horizontal_orientation_when_content_is_big() {
|
|
||||||
scrollView.orientation = enums.Orientation.horizontal;
|
|
||||||
|
|
||||||
scrollView.width = 200;
|
|
||||||
scrollView.height = 300;
|
|
||||||
|
|
||||||
var btn = new button.Button();
|
|
||||||
btn.text = "test";
|
|
||||||
btn.width = 500;
|
|
||||||
scrollView.content = btn;
|
|
||||||
|
|
||||||
waitForLayout();
|
|
||||||
TKUnit.assertEqual(scrollView.scrollableHeight, 0, "scrollView.scrollableHeight");
|
|
||||||
TKUnit.assertAreClose(scrollView.scrollableWidth, 300, 0.4, "scrollView.scrollableWidth");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_scrollToVerticalOffset_no_animation() {
|
|
||||||
scrollView.orientation = enums.Orientation.vertical;
|
|
||||||
|
|
||||||
scrollView.width = 200;
|
|
||||||
scrollView.height = 300;
|
|
||||||
|
|
||||||
var btn = new button.Button();
|
|
||||||
btn.text = "test";
|
|
||||||
btn.height = 500;
|
|
||||||
scrollView.content = btn;
|
|
||||||
waitForLayout();
|
|
||||||
|
|
||||||
TKUnit.assertEqual(scrollView.verticalOffset, 0, "scrollView.verticalOffset");
|
|
||||||
scrollView.scrollToVerticalOffset(100, false);
|
|
||||||
TKUnit.assertAreClose(scrollView.verticalOffset, 100, 0.1, "scrollView.verticalOffset");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_scrollToVerticalOffset_with_animation() {
|
|
||||||
scrollView.orientation = enums.Orientation.vertical;
|
|
||||||
|
|
||||||
scrollView.width = 200;
|
|
||||||
scrollView.height = 300;
|
|
||||||
|
|
||||||
var btn = new button.Button();
|
|
||||||
btn.text = "test";
|
|
||||||
btn.height = 500;
|
|
||||||
scrollView.content = btn;
|
|
||||||
waitForLayout();
|
|
||||||
|
|
||||||
TKUnit.assertEqual(scrollView.verticalOffset, 0, "scrollView.verticalOffset");
|
|
||||||
scrollView.scrollToVerticalOffset(100, true);
|
|
||||||
|
|
||||||
// No synchronous change.
|
|
||||||
TKUnit.assertEqual(scrollView.verticalOffset, 0, "scrollView.verticalOffset");
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => { return scrollView.verticalOffset === 100 }, ASYNC);
|
|
||||||
|
|
||||||
// The scrolling animation should be finished by now
|
|
||||||
TKUnit.assertAreClose(scrollView.verticalOffset, 100, 0.1, "scrollView.verticalOffset");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_scrollToHorizontalOffset_no_animation() {
|
|
||||||
scrollView.orientation = enums.Orientation.horizontal;
|
|
||||||
|
|
||||||
scrollView.width = 200;
|
|
||||||
scrollView.height = 300;
|
|
||||||
|
|
||||||
var btn = new button.Button();
|
|
||||||
btn.text = "test";
|
|
||||||
btn.width = 500;
|
|
||||||
scrollView.content = btn;
|
|
||||||
waitForLayout();
|
|
||||||
|
|
||||||
TKUnit.assertEqual(scrollView.horizontalOffset, 0, "scrollView.horizontalOffset");
|
|
||||||
scrollView.scrollToHorizontalOffset(100, false);
|
|
||||||
TKUnit.assertAreClose(scrollView.horizontalOffset, 100, 0.1, "scrollView.horizontalOffset");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_scrollToHorizontalOffset_with_animation() {
|
|
||||||
scrollView.orientation = enums.Orientation.horizontal;
|
|
||||||
|
|
||||||
scrollView.width = 200;
|
|
||||||
scrollView.height = 300;
|
|
||||||
|
|
||||||
var btn = new button.Button();
|
|
||||||
btn.text = "test";
|
|
||||||
btn.width = 500;
|
|
||||||
scrollView.content = btn;
|
|
||||||
waitForLayout();
|
|
||||||
|
|
||||||
TKUnit.assertEqual(scrollView.horizontalOffset, 0, "scrollView.horizontalOffset");
|
|
||||||
scrollView.scrollToHorizontalOffset(100, true);
|
|
||||||
|
|
||||||
// No synchronous change.
|
|
||||||
TKUnit.assertEqual(scrollView.horizontalOffset, 0, "scrollView.horizontalOffset");
|
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => { return scrollView.horizontalOffset === 100 }, ASYNC);
|
|
||||||
|
|
||||||
// The scrolling animation should be finished by now
|
|
||||||
TKUnit.assertAreClose(scrollView.horizontalOffset, 100, 0.1, "scrollView.horizontalOffset");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_scrollView_persistsState_vertical() {
|
|
||||||
scrollView.orientation = enums.Orientation.vertical;
|
|
||||||
|
|
||||||
scrollView.width = 200;
|
|
||||||
scrollView.height = 300;
|
|
||||||
|
|
||||||
var btn = new button.Button();
|
|
||||||
btn.text = "test";
|
|
||||||
btn.height = 500;
|
|
||||||
scrollView.content = btn;
|
|
||||||
waitForLayout();
|
|
||||||
|
|
||||||
scrollView.scrollToVerticalOffset(100, false);
|
|
||||||
|
|
||||||
TKUnit.assertAreClose(scrollView.verticalOffset, 100, 0.1, "scrollView.verticalOffset before navigation");
|
|
||||||
|
|
||||||
helper.do_PageTest_WithButton((t) => {
|
|
||||||
// Just navigate forward and back.
|
|
||||||
});
|
|
||||||
|
|
||||||
// Wait for the page to reload.
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return Math.abs(scrollView.verticalOffset - 100) < 0.1;
|
|
||||||
}, ASYNC);
|
|
||||||
|
|
||||||
// Check verticalOffset after navigation
|
|
||||||
TKUnit.assertAreClose(scrollView.verticalOffset, 100, 0.1, "scrollView.verticalOffset after navigation");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_scrollView_persistsState_horizontal() {
|
|
||||||
scrollView.orientation = enums.Orientation.horizontal;
|
|
||||||
|
|
||||||
scrollView.width = 200;
|
|
||||||
scrollView.height = 300;
|
|
||||||
|
|
||||||
var btn = new button.Button();
|
|
||||||
btn.text = "test";
|
|
||||||
btn.width = 500;
|
|
||||||
scrollView.content = btn;
|
|
||||||
waitForLayout();
|
|
||||||
|
|
||||||
scrollView.scrollToHorizontalOffset(100, false);
|
|
||||||
|
|
||||||
TKUnit.assertAreClose(scrollView.horizontalOffset, 100, 0.1, "scrollView.horizontalOffset before navigation");
|
|
||||||
|
|
||||||
helper.do_PageTest_WithButton((t) => {
|
|
||||||
// Just navigate forward and back.
|
|
||||||
});
|
|
||||||
|
|
||||||
// Wait for the page to reload.
|
|
||||||
TKUnit.waitUntilReady(function () {
|
|
||||||
return Math.abs(scrollView.horizontalOffset - 100) < 0.1;
|
|
||||||
}, ASYNC);
|
|
||||||
|
|
||||||
// Check verticalOffset after navigation
|
|
||||||
TKUnit.assertAreClose(scrollView.horizontalOffset, 100, 0.1, "scrollView.horizontalOffset after navigation");
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import TKUnit = require("../../TKUnit");
|
import TKUnit = require("../../TKUnit");
|
||||||
import helper = require("../helper");
|
import helper = require("../helper");
|
||||||
import page = require("ui/page");
|
import page = require("ui/page");
|
||||||
|
import testModule = require("../../ui-test");
|
||||||
|
|
||||||
// <snippet module="ui/web-view" title="WebView">
|
// <snippet module="ui/web-view" title="WebView">
|
||||||
// # WebView
|
// # WebView
|
||||||
@ -20,230 +21,174 @@ import webViewModule = require("ui/web-view");
|
|||||||
|
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
var _createWebViewFunc = function (): webViewModule.WebView {
|
export class WebViewTest extends testModule.UITest<webViewModule.WebView> {
|
||||||
// <snippet module="ui/web-view" title="WebView">
|
|
||||||
// ### Creating a WebView
|
|
||||||
// ``` JavaScript
|
|
||||||
var webView = new webViewModule.WebView();
|
|
||||||
// ```
|
|
||||||
// </snippet>
|
|
||||||
return webView;
|
|
||||||
}
|
|
||||||
|
|
||||||
function prepare(): webViewModule.WebView {
|
public create(): webViewModule.WebView {
|
||||||
var newPage: page.Page;
|
// <snippet module="ui/web-view" title="WebView">
|
||||||
var webView = _createWebViewFunc();
|
// ### Creating a WebView
|
||||||
var pageFactory = function (): page.Page {
|
// ``` JavaScript
|
||||||
newPage = new page.Page();
|
let webView = new webViewModule.WebView();
|
||||||
newPage.content = webView;
|
// ```
|
||||||
return newPage;
|
// </snippet>
|
||||||
};
|
return webView;
|
||||||
|
|
||||||
helper.navigate(pageFactory);
|
|
||||||
|
|
||||||
return webView;
|
|
||||||
}
|
|
||||||
|
|
||||||
export var testLoadExistingUrl = function () {
|
|
||||||
var webView = prepare();
|
|
||||||
|
|
||||||
var testFinished = false;
|
|
||||||
var actualUrl;
|
|
||||||
var actualError;
|
|
||||||
|
|
||||||
// <snippet module="ui/web-view" title="WebView">
|
|
||||||
// ### Using WebView
|
|
||||||
// ``` JavaScript
|
|
||||||
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
|
||||||
// <hide>
|
|
||||||
actualUrl = args.url;
|
|
||||||
actualError = args.error;
|
|
||||||
testFinished = true;
|
|
||||||
// </hide>
|
|
||||||
var message;
|
|
||||||
if (!args.error) {
|
|
||||||
message = "WebView finished loading " + args.url;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
message = "Error loading " + args.url + ": " + args.error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
webView.url = "http://nsbuild01.telerik.com/docs/";
|
|
||||||
// ```
|
|
||||||
// </snippet>
|
|
||||||
|
|
||||||
TKUnit.wait(4);
|
|
||||||
|
|
||||||
helper.goBack();
|
|
||||||
|
|
||||||
if (testFinished) {
|
|
||||||
TKUnit.assert(actualUrl === "http://nsbuild01.telerik.com/docs/", "args.url should equal http://nsbuild01.telerik.com/docs/");
|
|
||||||
TKUnit.assert(actualError === undefined, actualError);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
TKUnit.assert(false, "TIMEOUT");
|
public testLoadExistingUrl(done) {
|
||||||
|
let webView = this.testView;
|
||||||
|
|
||||||
|
// <snippet module="ui/web-view" title="WebView">
|
||||||
|
// ### Using WebView
|
||||||
|
// ``` JavaScript
|
||||||
|
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
||||||
|
let message;
|
||||||
|
if (!args.error) {
|
||||||
|
message = "WebView finished loading " + args.url;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
message = "Error loading " + args.url + ": " + args.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <hide>
|
||||||
|
try {
|
||||||
|
TKUnit.assertEqual(args.url, "http://nsbuild01.telerik.com/docs/", "args.url");
|
||||||
|
TKUnit.assertNull(args.error, "args.error");
|
||||||
|
done(null);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// </hide>
|
||||||
|
});
|
||||||
|
webView.url = "http://nsbuild01.telerik.com/docs/";
|
||||||
|
// ```
|
||||||
|
// </snippet>
|
||||||
|
}
|
||||||
|
|
||||||
|
public testLoadLocalFile(done) {
|
||||||
|
let webView = this.testView;
|
||||||
|
|
||||||
|
// <snippet module="ui/web-view" title="WebView">
|
||||||
|
// ### Using WebView
|
||||||
|
// ``` JavaScript
|
||||||
|
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
||||||
|
// <hide>
|
||||||
|
let actual;
|
||||||
|
let expectedTitle = 'MyTitle';
|
||||||
|
let expectedHtml = '<span style="color:red">Test</span>';
|
||||||
|
|
||||||
|
if (webView.ios) {
|
||||||
|
actual = webView.ios.stringByEvaluatingJavaScriptFromString("document.body.innerHTML").trim();
|
||||||
|
} else if (webView.android) {
|
||||||
|
actual = webView.android.getTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
TKUnit.assertEqual(actual, webView.ios ? expectedHtml : expectedTitle, "File ~/ui/web-view/test.html not loaded properly.");
|
||||||
|
TKUnit.assertNull(args.error, "args.error");
|
||||||
|
done(null);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
// </hide>
|
||||||
|
|
||||||
|
let message;
|
||||||
|
if (!args.error) {
|
||||||
|
message = "WebView finished loading " + args.url;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
message = "Error loading " + args.url + ": " + args.error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
webView.src = "~/ui/web-view/test.html";
|
||||||
|
// ```
|
||||||
|
// </snippet>
|
||||||
|
}
|
||||||
|
|
||||||
|
public testLoadHTMLString(done) {
|
||||||
|
let webView = this.testView;
|
||||||
|
|
||||||
|
// <snippet module="ui/web-view" title="WebView">
|
||||||
|
// ### Using WebView
|
||||||
|
// ``` JavaScript
|
||||||
|
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
||||||
|
// <hide>
|
||||||
|
|
||||||
|
let actual;
|
||||||
|
let expected;
|
||||||
|
|
||||||
|
if (webView.ios) {
|
||||||
|
actual = webView.ios.stringByEvaluatingJavaScriptFromString("document.body.innerHTML").trim();
|
||||||
|
expected = '<span style="color:red">Test</span>';
|
||||||
|
} else if (webView.android) {
|
||||||
|
actual = webView.android.getTitle();
|
||||||
|
expected = 'MyTitle';
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
TKUnit.assertEqual(actual, expected, "HTML string not loaded properly. Actual: ");
|
||||||
|
TKUnit.assertNull(args.error, "args.error");
|
||||||
|
done(null);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
// </hide>
|
||||||
|
|
||||||
|
let message;
|
||||||
|
if (!args.error) {
|
||||||
|
message = "WebView finished loading " + args.url;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
message = "Error loading " + args.url + ": " + args.error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
webView.src = '<!DOCTYPE html><html><head><title>MyTitle</title><meta charset="utf-8" /></head><body><span style="color:red">Test</span></body></html>';
|
||||||
|
// ```
|
||||||
|
// </snippet>
|
||||||
|
}
|
||||||
|
|
||||||
|
public testLoadInvalidUrl(done) {
|
||||||
|
let webView = this.testView;
|
||||||
|
let actualError;
|
||||||
|
|
||||||
|
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
||||||
|
if (actualError) {
|
||||||
|
// Android call this twice -- the second time args.error is undefined.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
actualError = args.error;
|
||||||
|
try {
|
||||||
|
TKUnit.assert(actualError !== undefined, "There should be an error.");
|
||||||
|
done(null);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
webView.url = "kofti://mnogokofti";
|
||||||
|
}
|
||||||
|
|
||||||
|
public testLoadUpperCaseSrc(done) {
|
||||||
|
let webView = this.testView;
|
||||||
|
let targetSrc = "HTTP://nsbuild01.telerik.com/docs/";
|
||||||
|
|
||||||
|
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
||||||
|
try {
|
||||||
|
TKUnit.assertEqual(args.url, targetSrc.toLowerCase(), "args.url");
|
||||||
|
TKUnit.assertNull(args.error, "args.error");
|
||||||
|
done(null);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
webView.src = targetSrc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export var testLoadLocalFile = function () {
|
export function createTestCase(): WebViewTest {
|
||||||
var webView = prepare();
|
return new WebViewTest();
|
||||||
|
|
||||||
var testFinished = false;
|
|
||||||
var actualHtml;
|
|
||||||
var actualTitle;
|
|
||||||
var actualError;
|
|
||||||
|
|
||||||
var expectedTitle = 'MyTitle';
|
|
||||||
var expectedHtml = '<span style="color:red">Test</span>';
|
|
||||||
|
|
||||||
// <snippet module="ui/web-view" title="WebView">
|
|
||||||
// ### Using WebView
|
|
||||||
// ``` JavaScript
|
|
||||||
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
|
||||||
// <hide>
|
|
||||||
if (webView.ios) {
|
|
||||||
actualHtml = webView.ios.stringByEvaluatingJavaScriptFromString("document.body.innerHTML").trim();
|
|
||||||
} else if (webView.android) {
|
|
||||||
actualTitle = webView.android.getTitle()
|
|
||||||
}
|
|
||||||
|
|
||||||
actualError = args.error;
|
|
||||||
testFinished = true;
|
|
||||||
// </hide>
|
|
||||||
var message;
|
|
||||||
if (!args.error) {
|
|
||||||
message = "WebView finished loading " + args.url;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
message = "Error loading " + args.url + ": " + args.error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
webView.src = "~/ui/web-view/test.html";
|
|
||||||
// ```
|
|
||||||
// </snippet>
|
|
||||||
|
|
||||||
TKUnit.wait(4);
|
|
||||||
|
|
||||||
helper.goBack();
|
|
||||||
|
|
||||||
if (testFinished) {
|
|
||||||
if (webView.ios) {
|
|
||||||
TKUnit.assert(actualHtml === expectedHtml, "File ~/ui/web-view/test.html not loaded properly. Actual: " + actualHtml);
|
|
||||||
} else if (webView.android) {
|
|
||||||
TKUnit.assert(actualTitle === expectedTitle, "File ~/ui/web-view/test.html not loaded properly. Actual: " + actualTitle);
|
|
||||||
}
|
|
||||||
TKUnit.assert(actualError === undefined, actualError);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TKUnit.assert(false, "TIMEOUT");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export var testLoadHTMLString = function () {
|
|
||||||
var webView = prepare();
|
|
||||||
|
|
||||||
var testFinished = false;
|
|
||||||
var actualHtml;
|
|
||||||
var actualTitle;
|
|
||||||
var actualError;
|
|
||||||
|
|
||||||
var expectedTitle = 'MyTitle';
|
|
||||||
var expectedHtml = '<span style="color:red">Test</span>';
|
|
||||||
|
|
||||||
// <snippet module="ui/web-view" title="WebView">
|
|
||||||
// ### Using WebView
|
|
||||||
// ``` JavaScript
|
|
||||||
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
|
||||||
// <hide>
|
|
||||||
if (webView.ios) {
|
|
||||||
actualHtml = webView.ios.stringByEvaluatingJavaScriptFromString("document.body.innerHTML").trim();
|
|
||||||
} else if (webView.android) {
|
|
||||||
actualTitle = webView.android.getTitle()
|
|
||||||
}
|
|
||||||
|
|
||||||
actualError = args.error;
|
|
||||||
testFinished = true;
|
|
||||||
// </hide>
|
|
||||||
var message;
|
|
||||||
if (!args.error) {
|
|
||||||
message = "WebView finished loading " + args.url;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
message = "Error loading " + args.url + ": " + args.error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
webView.src = '<!DOCTYPE html><html><head><title>MyTitle</title><meta charset="utf-8" /></head><body><span style="color:red">Test</span></body></html>';
|
|
||||||
// ```
|
|
||||||
// </snippet>
|
|
||||||
|
|
||||||
TKUnit.wait(4);
|
|
||||||
|
|
||||||
helper.goBack();
|
|
||||||
|
|
||||||
if (testFinished) {
|
|
||||||
if (webView.ios) {
|
|
||||||
TKUnit.assert(actualHtml === expectedHtml, "HTML string not loaded properly. Actual: " + actualHtml);
|
|
||||||
} else if (webView.android) {
|
|
||||||
TKUnit.assert(actualTitle === expectedTitle, "HTML string not loaded properly. Actual: " + actualTitle);
|
|
||||||
}
|
|
||||||
TKUnit.assert(actualError === undefined, actualError);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TKUnit.assert(false, "TIMEOUT");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export var testLoadInvalidUrl = function () {
|
|
||||||
var webView = prepare();
|
|
||||||
|
|
||||||
var testFinished = false;
|
|
||||||
var actualError;
|
|
||||||
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
|
||||||
if (actualError) {
|
|
||||||
// Android call this twice -- the second time args.error is undefined.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
actualError = args.error;
|
|
||||||
testFinished = true;
|
|
||||||
});
|
|
||||||
webView.url = "kofti://mnogokofti";
|
|
||||||
|
|
||||||
TKUnit.wait(4);
|
|
||||||
|
|
||||||
helper.goBack();
|
|
||||||
|
|
||||||
if (testFinished) {
|
|
||||||
TKUnit.assert(actualError !== undefined, "There should be an error.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TKUnit.assert(false, "TIMEOUT");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export var testLoadUpperCaseSrc = function () {
|
|
||||||
var webView = prepare();
|
|
||||||
|
|
||||||
var testFinished = false;
|
|
||||||
var actualSrc;
|
|
||||||
var actualError;
|
|
||||||
|
|
||||||
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
|
||||||
actualSrc = args.url;
|
|
||||||
actualError = args.error;
|
|
||||||
testFinished = true;
|
|
||||||
});
|
|
||||||
var targetSrc = "HTTP://nsbuild01.telerik.com/docs/";
|
|
||||||
webView.src = targetSrc;
|
|
||||||
|
|
||||||
TKUnit.wait(4);
|
|
||||||
|
|
||||||
helper.goBack();
|
|
||||||
|
|
||||||
if (testFinished) {
|
|
||||||
TKUnit.assert(actualSrc === targetSrc.toLowerCase(), "args.url should equal '" + targetSrc.toLowerCase() + "'");
|
|
||||||
TKUnit.assert(actualError === undefined, actualError);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TKUnit.assert(false, "TIMEOUT");
|
|
||||||
}
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user