diff --git a/apps/tests/TKUnit.ts b/apps/tests/TKUnit.ts
index 119986f1e..c27906a67 100644
--- a/apps/tests/TKUnit.ts
+++ b/apps/tests/TKUnit.ts
@@ -115,7 +115,7 @@ function runAsync(testInfo: TestInfoEntry, recursiveIndex: number, testTimeout?:
runTests(testsQueue, recursiveIndex + 1);
}
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) {
+ 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);
}
};
diff --git a/apps/tests/layouts/absolute-layout-tests.ts b/apps/tests/layouts/absolute-layout-tests.ts
index 2d380229d..44d7eeacc 100644
--- a/apps/tests/layouts/absolute-layout-tests.ts
+++ b/apps/tests/layouts/absolute-layout-tests.ts
@@ -1,4 +1,5 @@
-import TKUnit = require("../TKUnit");
+import testModule = require("../ui-test");
+import TKUnit = require("../TKUnit");
import viewModule = require("ui/core/view");
import labelModule = require("ui/label");
import helper = require("../ui/helper");
@@ -23,63 +24,83 @@ import absoluteLayoutModule = require("ui/layouts/absolute-layout");
//```
//
-export var testAll = function () {
- //
- // ## 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);
- // ```
- //
+export class AbsoluteLayoutTest extends testModule.UITest {
- helper.buildUIAndRunTest(absoluteLayout, function (views: Array) {
- TKUnit.waitUntilReady(function isReady() {
- return absoluteLayout.isLayoutValid;
- }, 1);
+ public create(): absoluteLayoutModule.AbsoluteLayout {
+ return new absoluteLayoutModule.AbsoluteLayout();
+ }
- var actualValue = viewModule.getViewById(absoluteLayout, "LT")._getCurrentLayoutBounds();
- var width = actualValue.right - actualValue.left;
- var height = actualValue.bottom - actualValue.top;
+ public snippet() {
+
+ //
+ // ## 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);
+ // ```
+ //
+ }
+
+ 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.top, layoutHelper.dip(10), "ActualTop");
TKUnit.assertEqual(width, layoutHelper.dip(100), "ActualWidth");
TKUnit.assertEqual(height, layoutHelper.dip(100), "Actualheight");
- });
-}
+ }
-export function test_padding() {
- var absoluteLayout = new absoluteLayoutModule.AbsoluteLayout();
- absoluteLayout.width = 200;
- absoluteLayout.height = 200;
- absoluteLayout.paddingLeft = 5;
- absoluteLayout.paddingTop = 15;
+ public test_padding() {
+ let absoluteLayout = this.testView;
+ absoluteLayout.width = 200;
+ absoluteLayout.height = 200;
+ absoluteLayout.paddingLeft = 5;
+ absoluteLayout.paddingTop = 15;
- // Left Top
- var btn = new layoutHelper.MyButton();
- btn.width = 100;
- btn.height = 100;
- absoluteLayoutModule.AbsoluteLayout.setLeft(btn, 20);
- absoluteLayoutModule.AbsoluteLayout.setTop(btn, 20);
- absoluteLayout.addChild(btn);
-
- helper.buildUIAndRunTest(absoluteLayout, function (views: Array) {
- TKUnit.waitUntilReady(function isReady() {
- return absoluteLayout.isLayoutValid;
- }, 1);
+ // Left Top
+ let btn = new layoutHelper.MyButton();
+ btn.width = 100;
+ btn.height = 100;
+ absoluteLayoutModule.AbsoluteLayout.setLeft(btn, 20);
+ absoluteLayoutModule.AbsoluteLayout.setTop(btn, 20);
+ absoluteLayout.addChild(btn);
+ this.waitUntilTestElementLayoutIsValid();
layoutHelper.assertMeasure(btn, 100, 100);
layoutHelper.assertLayout(btn, 25, 35, 100, 100);
- });
+ }
}
+
+export function createTestCase(): AbsoluteLayoutTest {
+ return new AbsoluteLayoutTest();
+}
\ No newline at end of file
diff --git a/apps/tests/layouts/dock-layout-tests.ts b/apps/tests/layouts/dock-layout-tests.ts
index d26349d3b..6a584fa08 100644
--- a/apps/tests/layouts/dock-layout-tests.ts
+++ b/apps/tests/layouts/dock-layout-tests.ts
@@ -4,6 +4,7 @@ import {DockLayout} from "ui/layouts/dock-layout";
import TKUnit = require("../TKUnit");
import helper = require("./layout-helper");
import navHelper = require("../ui/helper");
+import testModule = require("../ui-test");
//
// # DockLayout
@@ -16,11 +17,11 @@ import dockModule = require("ui/layouts/dock-layout");
//```XML
//
//
-//
//
//```
@@ -32,184 +33,164 @@ import enums = require("ui/enums");
// ```
//
-var testPage: pageModule.Page;
-var rootLayout: DockLayout;
-var tmp: button.Button;
+export class DockLayoutTest extends testModule.UITest {
-export function setUpModule() {
- var pageFactory = function () {
- testPage = new pageModule.Page();
- tmp = new button.Button();
- tmp.text = "Loading test";
- testPage.content = tmp;
- return testPage;
- };
+ public create(): DockLayout {
+ let rootLayout = new DockLayout();
+ rootLayout.height = 300;
+ rootLayout.width = 300;
+ return rootLayout;
+ }
- 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() {
+ //
+ // ## 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);
+ // ```
+ //
+ }
}
-export function tearDownModule() {
- navHelper.goBack();
- 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() {
- //
- // ## 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);
- // ```
- //
-}
+export function createTestCase(): DockLayoutTest {
+ return new DockLayoutTest();
+}
\ No newline at end of file
diff --git a/apps/tests/layouts/grid-layout-tests.ts b/apps/tests/layouts/grid-layout-tests.ts
index 13fe551d0..bd2fb6a3e 100644
--- a/apps/tests/layouts/grid-layout-tests.ts
+++ b/apps/tests/layouts/grid-layout-tests.ts
@@ -8,8 +8,8 @@ import navHelper = require("../ui/helper");
import utils = require("utils/utils");
import builder = require("ui/builder");
import enums = require("ui/enums");
+import testModule = require("../ui-test");
-var ASYNC = 2;
var DELTA = 1;
export class MyGridLayout extends layout.GridLayout {
@@ -35,660 +35,628 @@ export class MyGridLayout extends layout.GridLayout {
}
}
-var tmp: Button;
-var newPage: page.Page;
-var rootLayout: MyGridLayout;
+export class GridLayoutTest extends testModule.UITest {
-export function setUpModule() {
- var pageFactory = function (): page.Page {
- newPage = new page.Page;
- tmp = new Button();
- tmp.text = "Loading test";
- newPage.content = tmp;
- return newPage;
- };
- navHelper.navigate(pageFactory);
-}
+ public create(): layout.GridLayout {
+ return new MyGridLayout();
+ }
-export function tearDownModule() {
- navHelper.goBack();
+ private row(view: view.View): number {
+ return layout.GridLayout.getRow(view);
+ }
- tmp = null;
- newPage = null;
- rootLayout = null;
-}
+ private rowSpan(view: view.View): number {
+ return layout.GridLayout.getRowSpan(view);
+ }
-export function setUp() {
- rootLayout = new MyGridLayout();
- newPage.content = rootLayout;
-}
+ private col(view: view.View): number {
+ return layout.GridLayout.getColumn(view);
+ }
-export function tearDown() {
- newPage.content = tmp;
-}
+ private colSpan(view: view.View): number {
+ return layout.GridLayout.getColumnSpan(view);
+ }
-function row(view: view.View): number {
- return layout.GridLayout.getRow(view);
-}
+ private prepareGridLayout(wait?: boolean) {
-function rowSpan(view: view.View): number {
- return layout.GridLayout.getRowSpan(view);
-}
+ this.testView.addRow(new layout.ItemSpec(1, layout.GridUnitType.star));
+ this.testView.addRow(new layout.ItemSpec(2, layout.GridUnitType.star));
+ this.testView.addRow(new layout.ItemSpec(50, layout.GridUnitType.pixel));
+ this.testView.addRow(new layout.ItemSpec(50, layout.GridUnitType.auto));
-function col(view: view.View): number {
- return layout.GridLayout.getColumn(view);
-}
+ this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
+ this.testView.addColumn(new layout.ItemSpec(2, layout.GridUnitType.star));
+ this.testView.addColumn(new layout.ItemSpec(50, layout.GridUnitType.pixel));
+ this.testView.addColumn(new layout.ItemSpec(50, layout.GridUnitType.auto));
-function colSpan(view: view.View): number {
- return layout.GridLayout.getColumnSpan(view);
-}
+ for (var r = 0; r < 4; r++) {
+ for (var c = 0; c < 4; c++) {
+ var btn = new helper.MyButton();
+ btn.text = "R" + r + "C" + c;
+ layout.GridLayout.setColumn(btn, c);
+ layout.GridLayout.setRow(btn, r);
+ if (c === 3) {
+ btn.width = 100; // Auto column should take 100px for this test.
+ }
-export function test_row_defaultValue() {
- var test = new Button();
- TKUnit.assert(test !== null);
- TKUnit.assertEqual(row(test), 0, "'row' property default value should be 0.");
-}
+ if (r === 3) {
+ btn.height = 100; // Auto row should take 100px for this test.
+ }
-export function test_rowSpan_defaultValue() {
- var test = new Button();
- TKUnit.assert(test !== null);
- TKUnit.assertEqual(rowSpan(test), 1, "'rowSpan' property default value should be 1.");
-}
+ this.testView.addChild(btn);
+ }
+ }
-export function test_column_defaultValue() {
- var test = new Button();
- TKUnit.assert(test !== null);
- TKUnit.assertEqual(col(test), 0, "'column' property default value should be 0.");
-}
+ this.testView.width = 300;
+ this.testView.height = 300;
-export function test_columnSpan_defaultValue() {
- var test = new Button();
- TKUnit.assert(test !== null);
- TKUnit.assertEqual(colSpan(test), 1, "'columnSpan' property default value should be 1.");
-}
+ if (wait) {
+ this.waitUntilTestElementLayoutIsValid();
+ }
+ }
-export function test_getRow_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.getRow(null);
- }, "getRow called with null should throw exception");
-}
+ public test_row_defaultValue() {
+ var test = new Button();
+ TKUnit.assert(test !== null);
+ TKUnit.assertEqual(this.row(test), 0, "'row' property default value should be 0.");
+ }
-export function test_getRowSpan_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.getRowSpan(null);
- }, "getRowSpan called with null should throw exception");
-}
+ public test_rowSpan_defaultValue() {
+ var test = new Button();
+ TKUnit.assert(test !== null);
+ TKUnit.assertEqual(this.rowSpan(test), 1, "'rowSpan' property default value should be 1.");
+ }
-export function test_getColumn_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.getColumn(null);
- }, "getColumn called with null should throw exception");
-}
+ public test_column_defaultValue() {
+ var test = new Button();
+ TKUnit.assert(test !== null);
+ TKUnit.assertEqual(this.col(test), 0, "'column' property default value should be 0.");
+ }
-export function test_getColumnSpan_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.getColumnSpan(null);
- }, "getColumnSpan called with null should throw exception");
-}
+ public test_columnSpan_defaultValue() {
+ var test = new Button();
+ TKUnit.assert(test !== null);
+ TKUnit.assertEqual(this.colSpan(test), 1, "'columnSpan' property default value should be 1.");
+ }
-export function test_setRow_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.setRow(null, 1);
- }, "setRow called with null should throw exception");
-}
+ public test_getRow_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.getRow(null);
+ }, "getRow called with null should throw exception");
+ }
-export function test_setRowSpan_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.setRowSpan(null, 1);
- }, "setRowSpan called with null should throw exception");
-}
+ public test_getRowSpan_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.getRowSpan(null);
+ }, "getRowSpan called with null should throw exception");
+ }
-export function test_setColumn_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.setColumn(null, 1);
- }, "setColumn called with null should throw exception")
-}
+ public test_getColumn_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.getColumn(null);
+ }, "getColumn called with null should throw exception");
+ }
-export function test_setColumnSpan_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.setColumnSpan(null, 1);
- }, "setColumnSpan called with null should throw exception");
-}
+ public test_getColumnSpan_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.getColumnSpan(null);
+ }, "getColumnSpan called with null should throw exception");
+ }
-export function test_setRow_shouldThrow_onNegativeValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.setRow(tmp, -1);
- }, "setRow should throw when value < 0");
-}
+ public test_setRow_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.setRow(null, 1);
+ }, "setRow called with null should throw exception");
+ }
-export function test_setRowSpan_shouldThrow_onNotPositiveValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.setRowSpan(tmp, 0);
- }, "setRowSpan should throw when value <= 0");
-}
+ public test_setRowSpan_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.setRowSpan(null, 1);
+ }, "setRowSpan called with null should throw exception");
+ }
-export function test_setColumn_shouldThrow_onNegativeValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.setColumn(tmp, -1);
- }, "setColumn should when value < 0");
-}
+ public test_setColumn_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.setColumn(null, 1);
+ }, "setColumn called with null should throw exception")
+ }
-export function test_setColumnSpan_shouldThrow_onNotPositiveValues() {
- TKUnit.assertThrows(() => {
- layout.GridLayout.setColumnSpan(tmp, 0);
- }, "setColumnSpan should throw when value <= 0");
-}
+ public test_setColumnSpan_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.setColumnSpan(null, 1);
+ }, "setColumnSpan called with null should throw exception");
+ }
-export function test_addRow_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- rootLayout.addRow(null);
- }, "addRow called with null should throw exception");
-}
+ public test_setRow_shouldThrow_onNegativeValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.setRow(new Button(), -1);
+ }, "setRow should throw when value < 0");
+ }
-export function test_addColumn_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- rootLayout.addColumn(null);
- }, "addColumn called with null should throw exception");
-}
+ public test_setRowSpan_shouldThrow_onNotPositiveValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.setRowSpan(new Button(), 0);
+ }, "setRowSpan should throw when value <= 0");
+ }
-export function test_removeRow_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- rootLayout.removeRow(null);
- }, "removeRow called with null should throw exception");
-}
+ public test_setColumn_shouldThrow_onNegativeValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.setColumn(new Button(), -1);
+ }, "setColumn should when value < 0");
+ }
-export function test_removeColumn_shouldThrow_onNullValues() {
- TKUnit.assertThrows(() => {
- rootLayout.removeColumn(null);
- }, "removeColumn called with null should throw exception");
-}
+ public test_setColumnSpan_shouldThrow_onNotPositiveValues() {
+ TKUnit.assertThrows(() => {
+ layout.GridLayout.setColumnSpan(new Button(), 0);
+ }, "setColumnSpan should throw when value <= 0");
+ }
-export function test_removeColumns() {
- prepareGridLayout(false);
- TKUnit.assertTrue(rootLayout.getColumns().length > 0, "There should be columns.");
- rootLayout.removeColumns();
- TKUnit.assertTrue(rootLayout.getColumns().length === 0, "Columns should be empty.");
-}
+ public test_addRow_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ this.testView.addRow(null);
+ }, "addRow called with null should throw exception");
+ }
-export function test_removeRows() {
- prepareGridLayout(false);
- TKUnit.assertTrue(rootLayout.getRows().length > 0, "There should be rows.");
- rootLayout.removeRows();
- TKUnit.assertTrue(rootLayout.getRows().length === 0, "Rows should be empty.");
-}
+ public test_addColumn_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ this.testView.addColumn(null);
+ }, "addColumn called with null should throw exception");
+ }
-export function test_removeChildren() {
- prepareGridLayout(false);
- TKUnit.assertTrue(rootLayout.getChildrenCount() > 0, "There should be children.");
- rootLayout.removeChildren();
- TKUnit.assertTrue(rootLayout.getChildrenCount() === 0, "Childrens should be empty.");
-}
+ public test_removeRow_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ this.testView.removeRow(null);
+ }, "removeRow called with null should throw exception");
+ }
-export function test_measuredWidth_when_not_stretched_single_column() {
- rootLayout.horizontalAlignment = enums.HorizontalAlignment.center;
- let btn = new Button();
- btn.text = "A";
- rootLayout.addChild(btn);
- TKUnit.waitUntilReady(function () {
- return rootLayout.isLayoutValid;
- }, ASYNC);
+ public test_removeColumn_shouldThrow_onNullValues() {
+ TKUnit.assertThrows(() => {
+ this.testView.removeColumn(null);
+ }, "removeColumn called with null should throw exception");
+ }
- TKUnit.assertTrue(btn.getMeasuredWidth() === rootLayout.getMeasuredWidth());
-}
+ public test_removeColumns() {
+ this.prepareGridLayout(false);
+ TKUnit.assertTrue(this.testView.getColumns().length > 0, "There should be columns.");
+ this.testView.removeColumns();
+ TKUnit.assertTrue(this.testView.getColumns().length === 0, "Columns should be empty.");
+ }
-export function test_measuredWidth_when_not_stretched_two_columns() {
- rootLayout.horizontalAlignment = enums.HorizontalAlignment.center;
- rootLayout.addColumn(new layout.ItemSpec(80, layout.GridUnitType.pixel));
- rootLayout.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
+ public test_removeRows() {
+ this.prepareGridLayout(false);
+ TKUnit.assertTrue(this.testView.getRows().length > 0, "There should be rows.");
+ this.testView.removeRows();
+ TKUnit.assertTrue(this.testView.getRows().length === 0, "Rows should be empty.");
+ }
- let btn = new Button();
- btn.text = "A";
- btn.width = 100;
- MyGridLayout.setColumnSpan(btn, 2);
- rootLayout.addChild(btn);
- TKUnit.waitUntilReady(function () {
- return rootLayout.isLayoutValid;
- }, ASYNC);
+ public test_removeChildren() {
+ this.prepareGridLayout(false);
+ TKUnit.assertTrue(this.testView.getChildrenCount() > 0, "There should be children.");
+ this.testView.removeChildren();
+ TKUnit.assertTrue(this.testView.getChildrenCount() === 0, "Childrens should be empty.");
+ }
- var density = utils.layout.getDisplayDensity();
- var delta = Math.floor(density) !== density ? 2 : DELTA;
- var cols = rootLayout.getColumns();
- TKUnit.assertAreClose(cols[0].actualLength, 80, delta);
- TKUnit.assertAreClose(cols[1].actualLength, 20, delta);
- TKUnit.assertAreClose(rootLayout.getMeasuredWidth(), 100 * density, delta);
-}
-
-export function test_measuredWidth_when_not_stretched_three_columns() {
- rootLayout.horizontalAlignment = enums.HorizontalAlignment.center;
- rootLayout.addColumn(new layout.ItemSpec(80, layout.GridUnitType.pixel));
- rootLayout.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
- rootLayout.addColumn(new layout.ItemSpec(1, layout.GridUnitType.auto));
-
- for (let i = 1; i < 4; i++) {
+ public test_measuredWidth_when_not_stretched_single_column() {
+ this.testView.horizontalAlignment = enums.HorizontalAlignment.center;
let btn = new Button();
btn.text = "A";
- btn.width = i * 20;
- MyGridLayout.setColumn(btn, i - 1);
- rootLayout.addChild(btn);
+ this.testView.addChild(btn);
+
+ this.waitUntilTestElementLayoutIsValid();
+
+ TKUnit.assertTrue(btn.getMeasuredWidth() === this.testView.getMeasuredWidth());
}
- let btn = new Button();
- btn.text = "B";
- btn.width = 100;
- MyGridLayout.setColumnSpan(btn, 3);
- rootLayout.addChild(btn);
- TKUnit.waitUntilReady(function () {
- return rootLayout.isLayoutValid;
- }, ASYNC);
+ public test_measuredWidth_when_not_stretched_two_columns() {
+ this.testView.horizontalAlignment = enums.HorizontalAlignment.center;
+ this.testView.addColumn(new layout.ItemSpec(80, layout.GridUnitType.pixel));
+ this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
- var density = utils.layout.getDisplayDensity();
- var delta = Math.floor(density) !== density ? 2 : DELTA;
- var cols = rootLayout.getColumns();
- TKUnit.assertAreClose(cols[0].actualLength, 80, delta);
- TKUnit.assertAreClose(cols[1].actualLength, 40, delta);
- TKUnit.assertAreClose(cols[2].actualLength, 60, delta);
- TKUnit.assertAreClose(rootLayout.getMeasuredWidth(), 180 * density, delta);
-}
+ let btn = new Button();
+ btn.text = "A";
+ btn.width = 100;
+ MyGridLayout.setColumnSpan(btn, 2);
+ this.testView.addChild(btn);
-export function test_getRows_shouldNotReturnNULL() {
- var rows = rootLayout.getRows();
- TKUnit.assert(rows, "getRows should not return null/undefinied");
-}
+ this.waitUntilTestElementLayoutIsValid();
-export function test_getColumns_shouldNotReturnNULL() {
- var cols = rootLayout.getColumns();
- TKUnit.assert(cols, "getColumns should not return null/undefinied");
-}
-
-export function test_ItemSpec_actualLength_defaultValue() {
- var def = new layout.ItemSpec(1, layout.GridUnitType.auto);
- TKUnit.assertEqual(def.actualLength, 0, "'actualLength' property default value should be 0.");
-}
-
-export function test_ItemSpec_constructor_throws_onNegativeValue() {
- TKUnit.assertThrows(() => {
- new layout.ItemSpec(-1, layout.GridUnitType.auto);
- }, "'value' should be positive number.");
-}
-
-export function test_ItemSpec_constructor_doesnt_throw_onCorrectType() {
- try {
- new layout.ItemSpec(1, layout.GridUnitType.auto);
- new layout.ItemSpec(1, layout.GridUnitType.star);
- new layout.ItemSpec(1, layout.GridUnitType.pixel);
+ var density = utils.layout.getDisplayDensity();
+ var delta = Math.floor(density) !== density ? 2 : DELTA;
+ var cols = this.testView.getColumns();
+ TKUnit.assertAreClose(cols[0].actualLength, 80, delta);
+ TKUnit.assertAreClose(cols[1].actualLength, 20, delta);
+ TKUnit.assertAreClose(this.testView.getMeasuredWidth(), 100 * density, delta);
}
- catch (ex) {
- TKUnit.assert(false, "ItemSpec type should support auto, star and pixel.");
+
+ public test_measuredWidth_when_not_stretched_three_columns() {
+ this.testView.horizontalAlignment = enums.HorizontalAlignment.center;
+ this.testView.addColumn(new layout.ItemSpec(80, layout.GridUnitType.pixel));
+ this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
+ this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.auto));
+
+ for (let i = 1; i < 4; i++) {
+ let btn = new Button();
+ btn.text = "A";
+ btn.width = i * 20;
+ MyGridLayout.setColumn(btn, i - 1);
+ this.testView.addChild(btn);
+ }
+
+ let btn = new Button();
+ btn.text = "B";
+ btn.width = 100;
+ MyGridLayout.setColumnSpan(btn, 3);
+ this.testView.addChild(btn);
+
+ this.waitUntilTestElementLayoutIsValid();
+
+ var density = utils.layout.getDisplayDensity();
+ var delta = Math.floor(density) !== density ? 2 : DELTA;
+ var cols = this.testView.getColumns();
+ TKUnit.assertAreClose(cols[0].actualLength, 80, delta);
+ TKUnit.assertAreClose(cols[1].actualLength, 40, delta);
+ TKUnit.assertAreClose(cols[2].actualLength, 60, delta);
+ TKUnit.assertAreClose(this.testView.getMeasuredWidth(), 180 * density, delta);
}
-}
-export function test_ItemSpec_constructor_throws_onWrongType() {
- TKUnit.assertThrows(() => {
- new layout.ItemSpec(1, "unsupported");
- }, "'ItemSpec type' incorrect value.");
-}
+ public test_getRows_shouldNotReturnNULL() {
+ var rows = this.testView.getRows();
+ TKUnit.assert(rows, "getRows should not return null/undefinied");
+ }
-export function test_ItemSpec_auto() {
- var w = new layout.ItemSpec(1, layout.GridUnitType.auto);
- TKUnit.assertEqual(w.gridUnitType, layout.GridUnitType.auto, "'gridUnitType' property default value should be 'auto'");
- TKUnit.assertEqual(w.isAbsolute, false, "'isAbsolute' property default value should be 'false'");
- TKUnit.assertEqual(w.isAuto, true, "'isAuto' property default value should be 'false'");
- TKUnit.assertEqual(w.isStar, false, "'isAuto' property default value should be 'true'");
- TKUnit.assertEqual(w.value, 1, "'value' property default value should be '1'");
-}
+ public test_getColumns_shouldNotReturnNULL() {
+ var cols = this.testView.getColumns();
+ TKUnit.assert(cols, "getColumns should not return null/undefinied");
+ }
-export function test_ItemSpec_unitType_pixel() {
- var w = new layout.ItemSpec(6, layout.GridUnitType.pixel);
- TKUnit.assertEqual(w.gridUnitType, layout.GridUnitType.pixel, "'gridUnitType' property default value should be 'pixel'");
- TKUnit.assertEqual(w.isAbsolute, true, "'isAbsolute' property default value should be 'false'");
- TKUnit.assertEqual(w.isAuto, false, "'isAuto' property default value should be 'false'");
- TKUnit.assertEqual(w.isStar, false, "'isAuto' property default value should be 'true'");
- TKUnit.assertEqual(w.value, 6, "'value' property default value should be '1'");
-}
+ public test_ItemSpec_actualLength_defaultValue() {
+ var def = new layout.ItemSpec(1, layout.GridUnitType.auto);
+ TKUnit.assertEqual(def.actualLength, 0, "'actualLength' property default value should be 0.");
+ }
-export function test_ItemSpec_unitType() {
- var w = new layout.ItemSpec(2, layout.GridUnitType.star);
- TKUnit.assertEqual(w.gridUnitType, layout.GridUnitType.star, "'gridUnitType' property default value should be 'star'");
- TKUnit.assertEqual(w.isAbsolute, false, "'isAbsolute' property default value should be 'false'");
- TKUnit.assertEqual(w.isAuto, false, "'isAuto' property default value should be 'false'");
- TKUnit.assertEqual(w.isStar, true, "'isAuto' property default value should be 'true'");
- TKUnit.assertEqual(w.value, 2, "'value' property default value should be '1'");
-}
+ public test_ItemSpec_constructor_throws_onNegativeValue() {
+ TKUnit.assertThrows(() => {
+ new layout.ItemSpec(-1, layout.GridUnitType.auto);
+ }, "'value' should be positive number.");
+ }
-function prepareGridLayout(wait?: boolean) {
-
- rootLayout.addRow(new layout.ItemSpec(1, layout.GridUnitType.star));
- rootLayout.addRow(new layout.ItemSpec(2, layout.GridUnitType.star));
- rootLayout.addRow(new layout.ItemSpec(50, layout.GridUnitType.pixel));
- rootLayout.addRow(new layout.ItemSpec(50, layout.GridUnitType.auto));
-
- rootLayout.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
- rootLayout.addColumn(new layout.ItemSpec(2, layout.GridUnitType.star));
- rootLayout.addColumn(new layout.ItemSpec(50, layout.GridUnitType.pixel));
- rootLayout.addColumn(new layout.ItemSpec(50, layout.GridUnitType.auto));
-
- for (var r = 0; r < 4; r++) {
- for (var c = 0; c < 4; c++) {
- var btn = new helper.MyButton();
- btn.text = "R" + r + "C" + c;
- layout.GridLayout.setColumn(btn, c);
- layout.GridLayout.setRow(btn, r);
- if (c === 3) {
- btn.width = 100; // Auto column should take 100px for this test.
- }
-
- if (r === 3) {
- btn.height = 100; // Auto row should take 100px for this test.
- }
-
- rootLayout.addChild(btn);
+ public test_ItemSpec_constructor_doesnt_throw_onCorrectType() {
+ try {
+ new layout.ItemSpec(1, layout.GridUnitType.auto);
+ new layout.ItemSpec(1, layout.GridUnitType.star);
+ new layout.ItemSpec(1, layout.GridUnitType.pixel);
+ }
+ catch (ex) {
+ TKUnit.assert(false, "ItemSpec type should support auto, star and pixel.");
}
}
- rootLayout.width = 300;
- rootLayout.height = 300;
-
- if (wait) {
- TKUnit.waitUntilReady(function () {
- return rootLayout.isLayoutValid;
- }, ASYNC);
+ public test_ItemSpec_constructor_throws_onWrongType() {
+ TKUnit.assertThrows(() => {
+ new layout.ItemSpec(1, "unsupported");
+ }, "'ItemSpec type' incorrect value.");
}
-}
-export function test_desiredSize_isCorrect() {
- prepareGridLayout(false);
+ public test_ItemSpec_auto() {
+ var w = new layout.ItemSpec(1, layout.GridUnitType.auto);
+ TKUnit.assertEqual(w.gridUnitType, layout.GridUnitType.auto, "'gridUnitType' property default value should be 'auto'");
+ TKUnit.assertEqual(w.isAbsolute, false, "'isAbsolute' property default value should be 'false'");
+ TKUnit.assertEqual(w.isAuto, true, "'isAuto' property default value should be 'false'");
+ TKUnit.assertEqual(w.isStar, false, "'isAuto' property default value should be 'true'");
+ TKUnit.assertEqual(w.value, 1, "'value' property default value should be '1'");
+ }
- rootLayout.width = Number.NaN;
- rootLayout.height = Number.NaN;
+ public test_ItemSpec_unitType_pixel() {
+ var w = new layout.ItemSpec(6, layout.GridUnitType.pixel);
+ TKUnit.assertEqual(w.gridUnitType, layout.GridUnitType.pixel, "'gridUnitType' property default value should be 'pixel'");
+ TKUnit.assertEqual(w.isAbsolute, true, "'isAbsolute' property default value should be 'false'");
+ TKUnit.assertEqual(w.isAuto, false, "'isAuto' property default value should be 'false'");
+ TKUnit.assertEqual(w.isStar, false, "'isAuto' property default value should be 'true'");
+ TKUnit.assertEqual(w.value, 6, "'value' property default value should be '1'");
+ }
- TKUnit.waitUntilReady(function () {
- return rootLayout.isLayoutValid;
- }, ASYNC);
+ public test_ItemSpec_unitType() {
+ var w = new layout.ItemSpec(2, layout.GridUnitType.star);
+ TKUnit.assertEqual(w.gridUnitType, layout.GridUnitType.star, "'gridUnitType' property default value should be 'star'");
+ TKUnit.assertEqual(w.isAbsolute, false, "'isAbsolute' property default value should be 'false'");
+ TKUnit.assertEqual(w.isAuto, false, "'isAuto' property default value should be 'false'");
+ TKUnit.assertEqual(w.isStar, true, "'isAuto' property default value should be 'true'");
+ TKUnit.assertEqual(w.value, 2, "'value' property default value should be '1'");
+ }
- var maxWidth = 0;
- var maxHeight = 0;
- var width = 0;
- var height = 0;
- var i = 0;
- var cols = rootLayout.getColumns();
- var rows = rootLayout.getRows();
+ public test_desiredSize_isCorrect() {
+ this.prepareGridLayout(false);
- for (var r = 0; r < 4; r++) {
- width = 0;
- height = 0;
- for (var c = 0; c < 4; c++) {
- var btn = rootLayout.getChildAt(i++);
- if (cols[c].isAbsolute) {
- width += helper.dip(cols[c].actualLength);
+ this.testView.width = Number.NaN;
+ this.testView.height = Number.NaN;
+
+ this.waitUntilTestElementLayoutIsValid();
+
+ var maxWidth = 0;
+ var maxHeight = 0;
+ var width = 0;
+ var height = 0;
+ var i = 0;
+ var cols = this.testView.getColumns();
+ var rows = this.testView.getRows();
+
+ for (var r = 0; r < 4; r++) {
+ width = 0;
+ height = 0;
+ for (var c = 0; c < 4; c++) {
+ var btn = this.testView.getChildAt(i++);
+ if (cols[c].isAbsolute) {
+ width += helper.dip(cols[c].actualLength);
+ }
+ else {
+ width += btn.getMeasuredWidth();
+ }
+
+ height = Math.max(height, btn.getMeasuredHeight());
+ }
+
+ maxWidth = Math.max(maxWidth, width);
+
+ if (rows[r].isAbsolute) {
+ maxHeight += helper.dip(rows[r].actualLength);
}
else {
- width += btn.getMeasuredWidth();
+ maxHeight += height;
}
-
- height = Math.max(height, btn.getMeasuredHeight());
}
- maxWidth = Math.max(maxWidth, width);
+ var delta = 1.1; // Set to an overly high value to avoid failing on some emulators.
- if (rows[r].isAbsolute) {
- maxHeight += helper.dip(rows[r].actualLength);
- }
- else {
- maxHeight += height;
+ let measuredWidth = this.testView.getMeasuredWidth();
+ let measuredHeight = this.testView.getMeasuredHeight();
+ TKUnit.assertAreClose(measuredWidth, maxWidth, delta, "GridLayout incorrect measured width");
+ TKUnit.assertAreClose(measuredHeight, maxHeight, delta, "GridLayout incorrect measured height");
+ }
+
+ public test_columnsActualWidth_isCorrect() {
+ this.prepareGridLayout(true);
+
+ var cols = this.testView.getColumns();
+ TKUnit.assertEqual(cols[0].actualLength, 50, "Star column should be 50px width");
+ TKUnit.assertEqual(cols[1].actualLength, 100, "2*Star column should be 100px width");
+ TKUnit.assertEqual(cols[2].actualLength, 50, "Absolute column should be 50px width");
+ TKUnit.assertEqual(cols[3].actualLength, 100, "Auto column should be 100px width");
+ }
+
+ public test_rowsActualHeight_isCorrect() {
+ this.prepareGridLayout(true);
+
+ var rows = this.testView.getRows();
+ TKUnit.assertEqual(rows[0].actualLength, 50, "Star row should be 50px width");
+ TKUnit.assertEqual(rows[1].actualLength, 100, "2*Star row should be 100px width");
+ TKUnit.assertEqual(rows[2].actualLength, 50, "Absolute row should be 50px width");
+ TKUnit.assertEqual(rows[3].actualLength, 100, "Auto row should be 100px width");
+ }
+
+ public test_Measure_and_Layout_Children_withCorrect_size() {
+
+ this.prepareGridLayout(true);
+
+ var rows = this.testView.getRows();
+ var cols = this.testView.getColumns();
+ var i = 0;
+ var density = utils.layout.getDisplayDensity();
+ var delta = Math.floor(density) !== density ? 1.1 : DELTA;
+
+ for (var r = 0; r < 4; r++) {
+
+ for (var c = 0; c < 4; c++) {
+ var btn = this.testView.getChildAt(i++);
+ var col = cols[c];
+ var row = rows[r];
+
+ var h = r % 2 === 0 ? 50 : 100;
+ var w = c % 2 === 0 ? 50 : 100;
+
+ h = Math.round(h * density);
+ w = Math.round(w * density);
+
+ if (row.isAuto) {
+ TKUnit.assertAreClose(btn.layoutHeight, btn.getMeasuredHeight(), delta, "Auto rows should layout with measured height");
+ }
+ else if (row.isAbsolute) {
+ TKUnit.assertAreClose(btn.measureHeight, h, delta, "Absolute rows should measure with specific height");
+ TKUnit.assertAreClose(btn.layoutHeight, h, delta, "Absolute rows should layout with specific height");
+ }
+ else {
+ TKUnit.assertAreClose(btn.measureHeight, h, delta, "Star rows should measure with specific height");
+ TKUnit.assertAreClose(btn.layoutHeight, h, delta, "Star rows should layout with exact length");
+ }
+
+ if (col.isAuto) {
+ TKUnit.assertAreClose(btn.layoutWidth, btn.getMeasuredWidth(), delta, "Auto columns should layout with measured width");
+ }
+ else if (col.isAbsolute) {
+ TKUnit.assertAreClose(btn.measureWidth, w, delta, "Absolute columns should measure with specific width");
+ TKUnit.assertAreClose(btn.layoutWidth, w, delta, "Absolute columns should layout with specific width");
+ }
+ else {
+ TKUnit.assertAreClose(btn.measureWidth, w, delta, "Star columns should measure with specific width");
+ TKUnit.assertAreClose(btn.layoutWidth, w, delta, "Star columns should layout with exact length");
+ }
+ }
}
}
- var delta = 1.1; // Set to an overly high value to avoid failing on some emulators.
+ public test_ColumnWidth_when_4stars_and_width_110() {
- let measuredWidth = rootLayout.getMeasuredWidth();
- let measuredHeight = rootLayout.getMeasuredHeight();
- TKUnit.assertAreClose(measuredWidth, maxWidth, delta, "GridLayout incorrect measured width");
- TKUnit.assertAreClose(measuredHeight, maxHeight, delta, "GridLayout incorrect measured height");
-}
+ this.testView.width = 110;
+ this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
+ this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
+ this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
+ this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
-export function test_columnsActualWidth_isCorrect() {
- prepareGridLayout(true);
+ this.waitUntilTestElementLayoutIsValid();
- var cols = rootLayout.getColumns();
- TKUnit.assertEqual(cols[0].actualLength, 50, "Star column should be 50px width");
- TKUnit.assertEqual(cols[1].actualLength, 100, "2*Star column should be 100px width");
- TKUnit.assertEqual(cols[2].actualLength, 50, "Absolute column should be 50px width");
- TKUnit.assertEqual(cols[3].actualLength, 100, "Auto column should be 100px width");
-}
+ var cols = this.testView.getColumns();
-export function test_rowsActualHeight_isCorrect() {
- prepareGridLayout(true);
+ var density = utils.layout.getDisplayDensity();
+ var delta = Math.floor(density) !== density ? 1.1 : DELTA;
- var rows = rootLayout.getRows();
- TKUnit.assertEqual(rows[0].actualLength, 50, "Star row should be 50px width");
- TKUnit.assertEqual(rows[1].actualLength, 100, "2*Star row should be 100px width");
- TKUnit.assertEqual(rows[2].actualLength, 50, "Absolute row should be 50px width");
- TKUnit.assertEqual(rows[3].actualLength, 100, "Auto row should be 100px width");
-}
+ TKUnit.assertAreClose(cols[0].actualLength, 28, delta, "Column[0] actual length should be 28");
+ TKUnit.assertAreClose(cols[1].actualLength, 27, delta, "Column[1] actual length should be 27");
+ TKUnit.assertAreClose(cols[2].actualLength, 28, delta, "Column[2] actual length should be 28");
+ TKUnit.assertAreClose(cols[3].actualLength, 27, delta, "Column[3] actual length should be 27");
+ }
-export function test_Measure_and_Layout_Children_withCorrect_size() {
+ public test_margins_and_verticalAlignment_center() {
- prepareGridLayout(true);
+ this.testView.height = 200;
+ this.testView.width = 200;
+ var btn = new helper.MyButton();
+ btn.text = "btn";
+ btn.height = 100;
+ btn.width = 100;
+ btn.marginBottom = 50;
+ btn.marginRight = 50;
+ this.testView.addChild(btn);
- var rows = rootLayout.getRows();
- var cols = rootLayout.getColumns();
- var i = 0;
- var density = utils.layout.getDisplayDensity();
- var delta = Math.floor(density) !== density ? 1.1 : DELTA;
+ this.waitUntilTestElementLayoutIsValid();
- for (var r = 0; r < 4; r++) {
+ var density = utils.layout.getDisplayDensity();
+ var delta = Math.floor(density) !== density ? 1.1 : DELTA;
- for (var c = 0; c < 4; c++) {
- var btn = rootLayout.getChildAt(i++);
- var col = cols[c];
- var row = rows[r];
+ TKUnit.assertAreClose(btn.layoutTop, 25 * density, delta, "vertical margins");
+ TKUnit.assertAreClose(btn.layoutLeft, 25 * density, delta, "horizontal margins");
+ }
- var h = r % 2 === 0 ? 50 : 100;
- var w = c % 2 === 0 ? 50 : 100;
+ public test_set_columns_in_XML() {
+ var p = builder.parse("");
+ var grid = p.content;
- h = Math.round(h * density);
- w = Math.round(w * density);
+ var columns: Array = grid.getColumns();
- if (row.isAuto) {
- TKUnit.assertAreClose(btn.layoutHeight, btn.getMeasuredHeight(), delta, "Auto rows should layout with measured height");
- }
- else if (row.isAbsolute) {
- TKUnit.assertAreClose(btn.measureHeight, h, delta, "Absolute rows should measure with specific height");
- TKUnit.assertAreClose(btn.layoutHeight, h, delta, "Absolute rows should layout with specific height");
- }
- else {
- TKUnit.assertAreClose(btn.measureHeight, h, delta, "Star rows should measure with specific height");
- TKUnit.assertAreClose(btn.layoutHeight, h, delta, "Star rows should layout with exact length");
- }
+ TKUnit.assertEqual(columns.length, 4, "columns.length");
+ TKUnit.assert(columns[0].isAuto, "columns[0].isAuto");
- if (col.isAuto) {
- TKUnit.assertAreClose(btn.layoutWidth, btn.getMeasuredWidth(), delta, "Auto columns should layout with measured width");
- }
- else if (col.isAbsolute) {
- TKUnit.assertAreClose(btn.measureWidth, w, delta, "Absolute columns should measure with specific width");
- TKUnit.assertAreClose(btn.layoutWidth, w, delta, "Absolute columns should layout with specific width");
- }
- else {
- TKUnit.assertAreClose(btn.measureWidth, w, delta, "Star columns should measure with specific width");
- TKUnit.assertAreClose(btn.layoutWidth, w, delta, "Star columns should layout with exact length");
- }
- }
+ TKUnit.assert(columns[1].isStar, "columns[1].isStar");
+ TKUnit.assertEqual(columns[1].value, 1, "columns[1].value");
+
+ TKUnit.assert(columns[2].isStar, "columns[2].isStar");
+ TKUnit.assertEqual(columns[2].value, 10, "columns[2].value");
+
+ TKUnit.assert(columns[3].isAbsolute, "columns[3].isAbsolute");
+ TKUnit.assertEqual(columns[3].value, 100, "columns[3].value");
+ }
+
+ public test_set_rows_in_XML() {
+ var p = builder.parse("");
+ var grid = p.content;
+
+ var rows: Array = grid.getRows();
+
+ TKUnit.assertEqual(rows.length, 4, "rows.length");
+ TKUnit.assert(rows[0].isAuto, "rows[0].isAuto");
+
+ TKUnit.assert(rows[1].isStar, "rows[1].isStar");
+ TKUnit.assertEqual(rows[1].value, 1, "rows[1].value");
+
+ TKUnit.assert(rows[2].isStar, "rows[2].isStar");
+ TKUnit.assertEqual(rows[2].value, 10, "rows[2].value");
+
+ TKUnit.assert(rows[3].isAbsolute, "rows[3].isAbsolute");
+ TKUnit.assertEqual(rows[3].value, 100, "rows[3].value");
+ }
+
+ public test_padding() {
+ this.testView.paddingLeft = 10;
+ this.testView.paddingTop = 20;
+ this.testView.paddingRight = 30;
+ this.testView.paddingBottom = 40;
+
+ this.testView.width = 300;
+ this.testView.height = 300;
+
+ var btn = new helper.MyButton();
+ this.testView.addChild(btn);
+
+ this.waitUntilTestElementLayoutIsValid();
+
+ helper.assertMeasure(btn, 260, 240);
+ helper.assertLayout(btn, 10, 20, 260, 240);
+ }
+
+ public test_codesnippets = function () {
+ //
+ // ## GridLayout sample
+ // ### Creating Grid Layout via code.
+ // ``` JavaScript
+ //var layout = require("ui/layouts/grid-layout");
+ var gridLayout = new layout.GridLayout();
+ // ```
+
+ // ### Create grid layout with an xml declaration
+ // ``` XML
+ //
+ //
+ //
+ //
+ //// by default column and row are set to 0
+ //
+ //
+ // ```
+
+ // ### Add views to grid layout
+ // ``` JavaScript
+ var btn1 = new Button();
+ var btn2 = new Button();
+ var btn3 = new Button();
+ var btn4 = new Button();
+ gridLayout.addChild(btn1);
+ gridLayout.addChild(btn2);
+ gridLayout.addChild(btn3);
+ gridLayout.addChild(btn4);
+ // ```
+
+ // ### Set column property on views - btn1 in first column, btn2 is second and btn3 in third
+ // ``` JavaScript
+ layout.GridLayout.setColumn(btn1, 0);
+ layout.GridLayout.setColumn(btn2, 1);
+ layout.GridLayout.setColumn(btn3, 2);
+ // ```
+
+ // ### Set row property on btn4.
+ // ``` JavaScript
+ layout.GridLayout.setRow(btn4, 1);
+ // ```
+
+ // ### Set columnSpan property on btn4 to stretch into all columns
+ // ``` JavaScript
+ layout.GridLayout.setColumnSpan(btn4, 3);
+ // ```
+
+ // ### Create ItemSpec for columns and rows 3 columns - 80px, *, auto size and 2 rows - 100px and auto size
+ // ``` JavaScript
+ //// ItemSpec modes of the column refers to its width.
+ //// Absolute size of the column
+ var firstColumn = new layout.ItemSpec(80, layout.GridUnitType.pixel);
+ //// Star width means that this column will expand to fill the gap left from other columns
+ var secondColumn = new layout.ItemSpec(1, layout.GridUnitType.star);
+ //// Auto size means that column will expand or shrink in order to give enough place for all child UI elements.
+ var thirdColumn = new layout.ItemSpec(1, layout.GridUnitType.auto);
+
+ //// Star and Auto modes for rows behave like corresponding setting for columns but refer to row height.
+ var firstRow = new layout.ItemSpec(1, layout.GridUnitType.auto);
+ var secondRow = new layout.ItemSpec(1, layout.GridUnitType.star);
+ // ```
+
+ // ### Add columns and rows to GridLayout
+ // ``` JavaScript
+ gridLayout.addColumn(firstColumn);
+ gridLayout.addColumn(secondColumn);
+ gridLayout.addColumn(thirdColumn);
+ gridLayout.addRow(firstRow);
+ gridLayout.addRow(secondRow);
+ // ```
+ //
}
}
-export function test_ColumnWidth_when_4stars_and_width_110() {
-
- rootLayout.width = 110;
- rootLayout.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
- rootLayout.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
- rootLayout.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
- rootLayout.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
-
- TKUnit.waitUntilReady(function () {
- return rootLayout.isLayoutValid;
- }, ASYNC);
-
- var cols = rootLayout.getColumns();
-
- var density = utils.layout.getDisplayDensity();
- var delta = Math.floor(density) !== density ? 1.1 : DELTA;
-
- TKUnit.assertAreClose(cols[0].actualLength, 28, delta, "Column[0] actual length should be 28");
- TKUnit.assertAreClose(cols[1].actualLength, 27, delta, "Column[1] actual length should be 27");
- TKUnit.assertAreClose(cols[2].actualLength, 28, delta, "Column[2] actual length should be 28");
- TKUnit.assertAreClose(cols[3].actualLength, 27, delta, "Column[3] actual length should be 27");
-}
-
-export function test_margins_and_verticalAlignment_center() {
-
- rootLayout.height = 200;
- rootLayout.width = 200;
- var btn = new helper.MyButton();
- btn.text = "btn";
- btn.height = 100;
- btn.width = 100;
- btn.marginBottom = 50;
- btn.marginRight = 50;
- rootLayout.addChild(btn);
-
- TKUnit.waitUntilReady(function () {
- return btn.isLayoutValid;
- }, ASYNC);
-
- var density = utils.layout.getDisplayDensity();
- var delta = Math.floor(density) !== density ? 1.1 : DELTA;
-
- TKUnit.assertAreClose(btn.layoutTop, 25 * density, delta, "vertical margins");
- TKUnit.assertAreClose(btn.layoutLeft, 25 * density, delta, "horizontal margins");
-}
-
-export function test_set_columns_in_XML() {
- var p = builder.parse("");
- var grid = p.content;
-
- var columns: Array = grid.getColumns();
-
- TKUnit.assertEqual(columns.length, 4, "columns.length");
- TKUnit.assert(columns[0].isAuto, "columns[0].isAuto");
-
- TKUnit.assert(columns[1].isStar, "columns[1].isStar");
- TKUnit.assertEqual(columns[1].value, 1, "columns[1].value");
-
- TKUnit.assert(columns[2].isStar, "columns[2].isStar");
- TKUnit.assertEqual(columns[2].value, 10, "columns[2].value");
-
- TKUnit.assert(columns[3].isAbsolute, "columns[3].isAbsolute");
- TKUnit.assertEqual(columns[3].value, 100, "columns[3].value");
-};
-
-export function test_set_rows_in_XML() {
- var p = builder.parse("");
- var grid = p.content;
-
- var rows: Array = grid.getRows();
-
- TKUnit.assertEqual(rows.length, 4, "rows.length");
- TKUnit.assert(rows[0].isAuto, "rows[0].isAuto");
-
- TKUnit.assert(rows[1].isStar, "rows[1].isStar");
- TKUnit.assertEqual(rows[1].value, 1, "rows[1].value");
-
- TKUnit.assert(rows[2].isStar, "rows[2].isStar");
- TKUnit.assertEqual(rows[2].value, 10, "rows[2].value");
-
- TKUnit.assert(rows[3].isAbsolute, "rows[3].isAbsolute");
- TKUnit.assertEqual(rows[3].value, 100, "rows[3].value");
-};
-
-export function test_padding() {
- rootLayout.paddingLeft = 10;
- rootLayout.paddingTop = 20;
- rootLayout.paddingRight = 30;
- rootLayout.paddingBottom = 40;
-
- rootLayout.width = 300;
- rootLayout.height = 300;
-
- var btn = new helper.MyButton();
- rootLayout.addChild(btn);
-
- TKUnit.waitUntilReady(() => { return btn.isLayoutValid });
-
- helper.assertMeasure(btn, 260, 240);
- helper.assertLayout(btn, 10, 20, 260, 240);
-}
-
-export var test_codesnippets = function () {
- //
- // ## GridLayout sample
- // ### Creating Grid Layout via code.
- // ``` JavaScript
- //var layout = require("ui/layouts/grid-layout");
- var gridLayout = new layout.GridLayout();
- // ```
-
- // ### Create grid layout with an xml declaration
- // ``` XML
- //
- //
- //
- //
- //// by default column and row are set to 0
- //
- //
- // ```
-
- // ### Add views to grid layout
- // ``` JavaScript
- var btn1 = new Button();
- var btn2 = new Button();
- var btn3 = new Button();
- var btn4 = new Button();
- gridLayout.addChild(btn1);
- gridLayout.addChild(btn2);
- gridLayout.addChild(btn3);
- gridLayout.addChild(btn4);
- // ```
-
- // ### Set column property on views - btn1 in first column, btn2 is second and btn3 in third
- // ``` JavaScript
- layout.GridLayout.setColumn(btn1, 0);
- layout.GridLayout.setColumn(btn2, 1);
- layout.GridLayout.setColumn(btn3, 2);
- // ```
-
- // ### Set row property on btn4.
- // ``` JavaScript
- layout.GridLayout.setRow(btn4, 1);
- // ```
-
- // ### Set columnSpan property on btn4 to stretch into all columns
- // ``` JavaScript
- layout.GridLayout.setColumnSpan(btn4, 3);
- // ```
-
- // ### Create ItemSpec for columns and rows 3 columns - 80px, *, auto size and 2 rows - 100px and auto size
- // ``` JavaScript
- //// ItemSpec modes of the column refers to its width.
- //// Absolute size of the column
- var firstColumn = new layout.ItemSpec(80, layout.GridUnitType.pixel);
- //// Star width means that this column will expand to fill the gap left from other columns
- var secondColumn = new layout.ItemSpec(1, layout.GridUnitType.star);
- //// Auto size means that column will expand or shrink in order to give enough place for all child UI elements.
- var thirdColumn = new layout.ItemSpec(1, layout.GridUnitType.auto);
-
- //// Star and Auto modes for rows behave like corresponding setting for columns but refer to row height.
- var firstRow = new layout.ItemSpec(1, layout.GridUnitType.auto);
- var secondRow = new layout.ItemSpec(1, layout.GridUnitType.star);
- // ```
-
- // ### Add columns and rows to GridLayout
- // ``` JavaScript
- gridLayout.addColumn(firstColumn);
- gridLayout.addColumn(secondColumn);
- gridLayout.addColumn(thirdColumn);
- gridLayout.addRow(firstRow);
- gridLayout.addRow(secondRow);
- // ```
- //
-};
+export function createTestCase(): GridLayoutTest {
+ return new GridLayoutTest();
+}
\ No newline at end of file
diff --git a/apps/tests/layouts/stack-layout-tests.ts b/apps/tests/layouts/stack-layout-tests.ts
index a011bf091..c6092e115 100644
--- a/apps/tests/layouts/stack-layout-tests.ts
+++ b/apps/tests/layouts/stack-layout-tests.ts
@@ -6,241 +6,205 @@ import helper = require("./layout-helper");
import navHelper = require("../ui/helper");
import enums = require("ui/enums");
import utils = require("utils/utils");
+import testModule = require("../ui-test");
-var ASYNC = 2;
+export class StackLayoutTest extends testModule.UITest {
-var tmp: Button;
-var newPage: Page;
-var rootLayout: helper.MyStackLayout;
-var btn1: helper.MyButton;
-var btn2: helper.MyButton;
+ private rootLayout: helper.MyStackLayout;
+ private btn1: helper.MyButton;
+ private btn2: helper.MyButton;
-export function setUpModule() {
- var pageFactory = function () {
- newPage = new Page();
- tmp = new Button();
- tmp.text = "Loading test";
- newPage.content = tmp;
- return newPage;
- };
+ public create(): StackLayout {
+ this.rootLayout = new helper.MyStackLayout();
+ this.btn1 = new helper.MyButton();
+ this.btn1.text = "btn1";
+ this.rootLayout.addChild(this.btn1);
+ this.btn2 = new helper.MyButton();
+ 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 = [];
+ 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 = 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() {
+ //
+ // ### 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
+ //
+ //
+ //
+ //
+ //
+ //```
+ //
+
+ // ### 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;
+ // ```
+
+ //
+ }
}
-export function tearDownModule() {
- navHelper.goBack();
- 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 = [];
- 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 = 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() {
- //
- // ### Create StackLayout
- // ``` JavaScript
- var stackLayout = new StackLayout();
- // ```
-
- // ### Declaring a StackLayout.
- //```XML
- //
- //
- //
- //
- //
- //```
- //
-
- // ### 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;
- // ```
-
- //
-}
+export function createTestCase(): StackLayoutTest {
+ return new StackLayoutTest();
+}
\ No newline at end of file
diff --git a/apps/tests/layouts/wrap-layout-tests.ts b/apps/tests/layouts/wrap-layout-tests.ts
index f9eea6ca1..b178ee656 100644
--- a/apps/tests/layouts/wrap-layout-tests.ts
+++ b/apps/tests/layouts/wrap-layout-tests.ts
@@ -3,6 +3,7 @@ import viewModule = require("ui/core/view");
import labelModule = require("ui/label");
import helper = require("../ui/helper");
import layoutHelper = require("./layout-helper");
+import testModule = require("../ui-test");
//
// # WrapLayout
@@ -17,220 +18,174 @@ import enums = require("ui/enums");
// ```
//
-var _createWrapLayoutFunc = function (childCount: number, childWidth?: number, childHeight?: number): wrapLayoutModule.WrapLayout {
- //
- // ## Creating a WrapLayout
- // ``` JavaScript
- var wrapLayout = new wrapLayoutModule.WrapLayout();
- // ```
- //
+export class WrapLayoutTest extends testModule.UITest {
- // ### Declaring a WrapLayout.
- //```XML
- //
- //
- //
- //
- //
- //
- //
- //
- //```
- //
+ public create(): wrapLayoutModule.WrapLayout {
+ //
+ // ## Creating a WrapLayout
+ // ``` JavaScript
+ var wrapLayout = new wrapLayoutModule.WrapLayout();
+ // ```
+ //
- wrapLayout.width = 200;
- wrapLayout.height = 200;
+ // ### Declaring a WrapLayout.
+ //```XML
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //```
+ //
- var label;
- var i;
- for (i = 0; i < childCount; i++) {
- label = new labelModule.Label();
- label.text = "" + i;
- label.id = "" + i;
+ wrapLayout.width = 200;
+ wrapLayout.height = 200;
- label.width = childWidth || 100;
- label.height = childHeight || 100;
- wrapLayout.addChild(label);
+ var label;
+ var i;
+ 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() {
- var wrapLayout = _createWrapLayoutFunc(2);
- wrapLayout.orientation = enums.Orientation.horizontal;
- helper.buildUIAndRunTest(wrapLayout, function (views: Array) {
- TKUnit.waitUntilReady(function isReady() {
- return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
- }, 1);
+ this.testView.orientation = enums.Orientation.horizontal;
+ this.waitUntilTestElementLayoutIsValid();
- 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.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();
+ actualValue = this.testView.getChildAt(1)._getCurrentLayoutBounds();
TKUnit.assertEqual(actualValue.left, layoutHelper.dip(100), "ActualLeft 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.bottom, layoutHelper.dip(100), "ActualBottom on Index 1");
- });
-}
+ }
-export function testVerticalOrientation() {
- var wrapLayout = _createWrapLayoutFunc(2);
- //
- // ## Setting the orientation of a wrap-layout.
- // ``` JavaScript
- wrapLayout.orientation = enums.Orientation.vertical;
- // ```
- //
- helper.buildUIAndRunTest(wrapLayout, function (views: Array) {
- 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) {
+ public testVerticalOrientation() {
+ var wrapLayout = this.testView;
+ //
+ // ## Setting the orientation of a wrap-layout.
+ // ``` JavaScript
wrapLayout.orientation = enums.Orientation.vertical;
+ // ```
+ //
+ this.waitUntilTestElementLayoutIsValid();
- TKUnit.waitUntilReady(() => {
- return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
- });
-
- var actualValue = viewModule.getViewById(wrapLayout, "0")._getCurrentLayoutBounds();
+ 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 = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds();
+ 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");
- });
-}
+ }
-export function testItemWidth() {
- var wrapLayout = _createWrapLayoutFunc(2);
- wrapLayout.itemWidth = 50;
- helper.buildUIAndRunTest(wrapLayout, function (views: Array) {
- TKUnit.waitUntilReady(function isReady() {
- return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
- }, 1);
+ public testChangeOrientation() {
+ this.testView.orientation = enums.Orientation.horizontal;
+ this.waitUntilTestElementLayoutIsValid();
+ this.testView.orientation = enums.Orientation.vertical;
+ this.waitUntilTestElementLayoutIsValid();
- 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");
- });
-}
+ }
-export function testChangeItemWidth() {
- var wrapLayout = _createWrapLayoutFunc(2);
- helper.buildUIAndRunTest(wrapLayout, function (views: Array) {
- TKUnit.waitUntilReady(() => {
- return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
- });
+ public testChangeItemWidth() {
+ this.waitUntilTestElementLayoutIsValid();
+ this.testView.itemWidth = 50;
+ this.waitUntilTestElementLayoutIsValid();
- wrapLayout.itemWidth = 50;
-
- TKUnit.waitUntilReady(() => {
- return wrapLayout.isLayoutValid;
- });
-
- var actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds().left;
+ let actualValue = this.testView.getChildAt(1)._getCurrentLayoutBounds().left;
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualLeft on Index 1");
- });
-}
+ }
-export function testItemHeight() {
- var wrapLayout = _createWrapLayoutFunc(2);
- wrapLayout.itemHeight = 50;
- wrapLayout.orientation = enums.Orientation.vertical;
- helper.buildUIAndRunTest(wrapLayout, function (views: Array) {
- TKUnit.waitUntilReady(function isReady() {
- return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
- }, 1);
+ public testItemHeight() {
+ this.testView.itemHeight = 50;
+ this.testView.orientation = enums.Orientation.vertical;
+ this.waitUntilTestElementLayoutIsValid();
- 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");
- });
-}
+ }
-export function testChangeItemHeight() {
- var wrapLayout = _createWrapLayoutFunc(2);
- wrapLayout.orientation = enums.Orientation.vertical;
- helper.buildUIAndRunTest(wrapLayout, function (views: Array) {
- TKUnit.waitUntilReady(() => {
- return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
- });
+ public testChangeItemHeight() {
+ this.testView.orientation = enums.Orientation.vertical;
+ this.waitUntilTestElementLayoutIsValid();
+ this.testView.itemHeight = 50;
+ this.waitUntilTestElementLayoutIsValid();
- wrapLayout.itemHeight = 50;
-
- TKUnit.waitUntilReady(() => {
- return wrapLayout.isLayoutValid;
- });
-
- 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");
- });
-}
+ }
-export function testPaddingLeftAndTop() {
- var wrapLayout = new wrapLayoutModule.WrapLayout();
- wrapLayout.paddingLeft = 20;
- wrapLayout.paddingTop = 30;
+ public testPaddingLeftAndTop() {
+ this.testView.removeChildren();
+ this.testView.paddingLeft = 20;
+ this.testView.paddingTop = 30;
- var btn = new layoutHelper.MyButton();
- btn.width = 50;
- btn.height = 50;
- wrapLayout.addChild(btn);
+ var btn = new layoutHelper.MyButton();
+ btn.width = 50;
+ btn.height = 50;
+ this.testView.addChild(btn);
- helper.buildUIAndRunTest(wrapLayout, function (views: Array) {
- TKUnit.waitUntilReady(() => {
- return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
- });
+ this.waitUntilTestElementLayoutIsValid();
layoutHelper.assertLayout(btn, 20, 30, 50, 50);
- });
-}
+ }
-export function testPaddingRight() {
- var wrapLayout = new wrapLayoutModule.WrapLayout();
- wrapLayout.paddingRight = 30;
- wrapLayout.width = 200;
+ public testPaddingRight() {
+ this.testView.removeChildren();
+ this.testView.paddingRight = 30;
+ this.testView.width = 200;
- var btn1 = new layoutHelper.MyButton();
- wrapLayout.addChild(btn1);
- btn1.width = 100;
- btn1.height = 50;
+ var btn1 = new layoutHelper.MyButton();
+ this.testView.addChild(btn1);
+ btn1.width = 100;
+ btn1.height = 50;
- var btn2 = new layoutHelper.MyButton();
- btn2.width = 80;
- btn2.height = 50;
- wrapLayout.addChild(btn2);
+ var btn2 = new layoutHelper.MyButton();
+ btn2.width = 80;
+ btn2.height = 50;
+ this.testView.addChild(btn2);
- helper.buildUIAndRunTest(wrapLayout, function (views: Array) {
- TKUnit.waitUntilReady(() => {
- return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
- });
+ this.waitUntilTestElementLayoutIsValid();
layoutHelper.assertMeasure(btn1, 100, 50);
layoutHelper.assertMeasure(btn2, 80, 50);
@@ -239,29 +194,25 @@ export function testPaddingRight() {
// because for the padding (200 - 100 - 30) = 70 button wants 80
layoutHelper.assertLayout(btn1, 0, 0, 100, 50, "button1");
layoutHelper.assertLayout(btn2, 0, 50, 80, 50, "button2");
- });
-}
+ }
-export function testPaddingBottom() {
- var wrapLayout = new wrapLayoutModule.WrapLayout();
- wrapLayout.paddingBottom = 30;
- wrapLayout.height = 200;
- wrapLayout.orientation = enums.Orientation.vertical;
+ public testPaddingBottom() {
+ this.testView.removeChildren();
+ this.testView.paddingBottom = 30;
+ this.testView.height = 200;
+ this.testView.orientation = enums.Orientation.vertical;
- var btn1 = new layoutHelper.MyButton();
- wrapLayout.addChild(btn1);
- btn1.width = 50;
- btn1.height = 100;
+ var btn1 = new layoutHelper.MyButton();
+ this.testView.addChild(btn1);
+ btn1.width = 50;
+ btn1.height = 100;
- var btn2 = new layoutHelper.MyButton();
- btn2.width = 50;
- btn2.height = 80;
- wrapLayout.addChild(btn2);
+ var btn2 = new layoutHelper.MyButton();
+ btn2.width = 50;
+ btn2.height = 80;
+ this.testView.addChild(btn2);
- helper.buildUIAndRunTest(wrapLayout, function (views: Array) {
- TKUnit.waitUntilReady(() => {
- return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
- });
+ this.waitUntilTestElementLayoutIsValid();
layoutHelper.assertMeasure(btn1, 50, 100);
layoutHelper.assertMeasure(btn2, 50, 80);
@@ -270,5 +221,9 @@ export function testPaddingBottom() {
// because of the padding (200 - 100 - 30) = 70 button wants 80
layoutHelper.assertLayout(btn1, 0, 0, 50, 100, "button1");
layoutHelper.assertLayout(btn2, 50, 0, 50, 80, "button2");
- });
+ }
+}
+
+export function createTestCase(): WrapLayoutTest {
+ return new WrapLayoutTest();
}
\ No newline at end of file
diff --git a/apps/tests/testRunner.ts b/apps/tests/testRunner.ts
index e3ea56eea..3e9562b01 100644
--- a/apps/tests/testRunner.ts
+++ b/apps/tests/testRunner.ts
@@ -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) {
if (running) {
// TODO: We may schedule pending run requests
@@ -143,19 +164,18 @@ export var runAll = function (moduleName?: string) {
}
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;
+ test.name = name;
+
+
+ testsQueue.push(new TestInfo(startLog, test));
if (test.setUpModule) {
testsQueue.push(new TestInfo(test.setUpModule, test));
}
+
for (var testName in test) {
var testFunction = test[testName];
if ((typeof (testFunction) === "function") && (testName.substring(0, 4) == "test")) {
@@ -172,13 +192,7 @@ export var runAll = function (moduleName?: string) {
if (test.tearDownModule) {
testsQueue.push(new TestInfo(test.tearDownModule, 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(log, test));
}
testsQueue.push(new TestInfo(printRunTestStats));
diff --git a/apps/tests/ui-test.ts b/apps/tests/ui-test.ts
index b2428a712..08ed1bfde 100644
--- a/apps/tests/ui-test.ts
+++ b/apps/tests/ui-test.ts
@@ -1,12 +1,12 @@
-import pageModule = require("ui/page");
-import navHelper = require("./ui/helper");
-import viewModule = require("ui/core/view");
+import {Page} from "ui/page";
+import {View} from "ui/core/view";
import trace = require("trace");
+import navHelper = require("./ui/helper");
import TKUnit = require("./TKUnit");
-export class UITest implements trace.TraceWriter {
+export class UITest implements trace.TraceWriter {
- private _testPage: pageModule.Page;
+ private _testPage: Page;
private _testView: T;
private _errorMessage;
@@ -14,7 +14,7 @@ export class UITest implements trace.TraceWriter {
return this._errorMessage;
}
- public get testPage(): pageModule.Page {
+ public get testPage(): Page {
return this._testPage;
}
@@ -41,7 +41,7 @@ export class UITest implements trace.TraceWriter {
public setUpModule(): void {
var pageFactory = () => {
- var page = new pageModule.Page();
+ var page = new Page();
this._testPage = page;
return page;
};
@@ -67,6 +67,7 @@ export class UITest implements trace.TraceWriter {
this._testPage.content = null;
this._testPage.bindingContext = null;
this._testPage.css = "";
+ this._testView = null;
this._errorMessage = undefined;
}
@@ -77,6 +78,6 @@ export class UITest implements trace.TraceWriter {
}
}
-export function createTestCase(): UITest {
+export function createTestCase(): UITest {
return null;
}
\ No newline at end of file
diff --git a/apps/tests/ui/scroll-view/scroll-view-tests.ts b/apps/tests/ui/scroll-view/scroll-view-tests.ts
index f1d69fe7b..6ad66c441 100644
--- a/apps/tests/ui/scroll-view/scroll-view-tests.ts
+++ b/apps/tests/ui/scroll-view/scroll-view-tests.ts
@@ -5,6 +5,7 @@ import buttonModule = require("ui/button");
import page = require("ui/page");
import button = require("ui/button");
import enums = require("ui/enums");
+import testModule = require("../../ui-test");
//
// # ScrollView
@@ -24,278 +25,248 @@ import scrollViewModule = require("ui/scroll-view");
//
-var ASYNC = 5;
-var tmp: buttonModule.Button;
-var newPage: page.Page;
-
-//
-// ### Creating a ScrollView
-// ``` JavaScript
-var scrollView = new scrollViewModule.ScrollView();
-// ```
-//
-
-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");
+class ScrollLayoutTest extends testModule.UITest {
+ public create(): scrollViewModule.ScrollView {
+ return new scrollViewModule.ScrollView();
}
- else if (app.ios) {
- TKUnit.assert(scrollView.ios instanceof UIScrollView, "ios property is UIScrollView");
+
+ public test_snippets() {
+ //
+ // ### Creating a ScrollView
+ // ``` JavaScript
+ var scrollView = new scrollViewModule.ScrollView();
+ // ```
+ //
+ }
+
+ 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() {
- scrollView.orientation = enums.Orientation.horizontal;
-
- 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");
-}
+export function createTestCase(): ScrollLayoutTest {
+ return new ScrollLayoutTest();
+}
\ No newline at end of file
diff --git a/apps/tests/ui/web-view/web-view-tests.ts b/apps/tests/ui/web-view/web-view-tests.ts
index 598922ebd..4c5e97906 100644
--- a/apps/tests/ui/web-view/web-view-tests.ts
+++ b/apps/tests/ui/web-view/web-view-tests.ts
@@ -1,6 +1,7 @@
import TKUnit = require("../../TKUnit");
import helper = require("../helper");
import page = require("ui/page");
+import testModule = require("../../ui-test");
//
// # WebView
@@ -20,230 +21,174 @@ import webViewModule = require("ui/web-view");
//
-var _createWebViewFunc = function (): webViewModule.WebView {
- //
- // ### Creating a WebView
- // ``` JavaScript
- var webView = new webViewModule.WebView();
- // ```
- //
- return webView;
-}
+export class WebViewTest extends testModule.UITest {
-function prepare(): webViewModule.WebView {
- var newPage: page.Page;
- var webView = _createWebViewFunc();
- var pageFactory = function (): page.Page {
- newPage = new page.Page();
- newPage.content = webView;
- return newPage;
- };
-
- helper.navigate(pageFactory);
-
- return webView;
-}
-
-export var testLoadExistingUrl = function () {
- var webView = prepare();
-
- var testFinished = false;
- var actualUrl;
- var actualError;
-
- //
- // ### Using WebView
- // ``` JavaScript
- webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
- //
- actualUrl = args.url;
- actualError = args.error;
- testFinished = true;
- //
- 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/";
- // ```
- //
-
- 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);
+ public create(): webViewModule.WebView {
+ //
+ // ### Creating a WebView
+ // ``` JavaScript
+ let webView = new webViewModule.WebView();
+ // ```
+ //
+ return webView;
}
- else {
- TKUnit.assert(false, "TIMEOUT");
+
+ public testLoadExistingUrl(done) {
+ let webView = this.testView;
+
+ //
+ // ### 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;
+ }
+
+ //
+ try {
+ TKUnit.assertEqual(args.url, "http://nsbuild01.telerik.com/docs/", "args.url");
+ TKUnit.assertNull(args.error, "args.error");
+ done(null);
+ }
+ catch (e) {
+ done(e);
+ }
+
+ //
+ });
+ webView.url = "http://nsbuild01.telerik.com/docs/";
+ // ```
+ //
+ }
+
+ public testLoadLocalFile(done) {
+ let webView = this.testView;
+
+ //
+ // ### Using WebView
+ // ``` JavaScript
+ webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
+ //
+ let actual;
+ let expectedTitle = 'MyTitle';
+ let expectedHtml = 'Test';
+
+ 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);
+ }
+ //
+
+ 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";
+ // ```
+ //
+ }
+
+ public testLoadHTMLString(done) {
+ let webView = this.testView;
+
+ //
+ // ### Using WebView
+ // ``` JavaScript
+ webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
+ //
+
+ let actual;
+ let expected;
+
+ if (webView.ios) {
+ actual = webView.ios.stringByEvaluatingJavaScriptFromString("document.body.innerHTML").trim();
+ expected = 'Test';
+ } 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);
+ }
+ //
+
+ let message;
+ if (!args.error) {
+ message = "WebView finished loading " + args.url;
+ }
+ else {
+ message = "Error loading " + args.url + ": " + args.error;
+ }
+ });
+ webView.src = 'MyTitleTest';
+ // ```
+ //
+ }
+
+ 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 () {
- var webView = prepare();
-
- var testFinished = false;
- var actualHtml;
- var actualTitle;
- var actualError;
-
- var expectedTitle = 'MyTitle';
- var expectedHtml = 'Test';
-
- //
- // ### Using WebView
- // ``` JavaScript
- webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
- //
- if (webView.ios) {
- actualHtml = webView.ios.stringByEvaluatingJavaScriptFromString("document.body.innerHTML").trim();
- } else if (webView.android) {
- actualTitle = webView.android.getTitle()
- }
-
- actualError = args.error;
- testFinished = true;
- //
- 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";
- // ```
- //
-
- 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 = 'Test';
-
- //
- // ### Using WebView
- // ``` JavaScript
- webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
- //
- if (webView.ios) {
- actualHtml = webView.ios.stringByEvaluatingJavaScriptFromString("document.body.innerHTML").trim();
- } else if (webView.android) {
- actualTitle = webView.android.getTitle()
- }
-
- actualError = args.error;
- testFinished = true;
- //
- var message;
- if (!args.error) {
- message = "WebView finished loading " + args.url;
- }
- else {
- message = "Error loading " + args.url + ": " + args.error;
- }
- });
- webView.src = 'MyTitleTest';
- // ```
- //
-
- 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");
- }
-}
+export function createTestCase(): WebViewTest {
+ return new WebViewTest();
+}
\ No newline at end of file