diff --git a/tests/app/ui/frame/frame-tests-common.ts b/tests/app/ui/frame/frame-tests-common.ts new file mode 100644 index 000000000..402ee6d0f --- /dev/null +++ b/tests/app/ui/frame/frame-tests-common.ts @@ -0,0 +1,43 @@ +// >> frame-require +import frameModule = require("ui/frame"); +var topmost = frameModule.topmost(); +// << frame-require + +import labelModule = require("ui/label"); +import pagesModule = require("ui/page"); + +export var ignore_test_DummyTestForSnippetOnly0 = function () { + // >> frame-navigating + topmost.navigate("details-page"); + // << frame-navigating +} + +export var ignore_test_DummyTestForSnippetOnly1 = function () { + // >> frame-factory-func + var factoryFunc = function () { + var label = new labelModule.Label(); + label.text = "Hello, world!"; + var page = new pagesModule.Page(); + page.content = label; + return page; + }; + topmost.navigate(factoryFunc); + // <> frame-naventry + var navigationEntry = { + moduleName: "details-page", + context: { info: "something you want to pass to your page" }, + animated: false + }; + topmost.navigate(navigationEntry); + // << frame-naventry +} + +export var ignore_test_DummyTestForSnippetOnly3 = function () { + // >> frame-back + topmost.goBack(); + // << frame-back +} \ No newline at end of file diff --git a/tests/app/ui/frame/frame-tests.android.ts b/tests/app/ui/frame/frame-tests.android.ts new file mode 100644 index 000000000..6f082215a --- /dev/null +++ b/tests/app/ui/frame/frame-tests.android.ts @@ -0,0 +1,64 @@ +import frameModule = require("ui/frame"); +import TKUnit = require("../../TKUnit"); +import { widthProperty, heightProperty } from "ui/styling/style"; + +export function test_percent_width_and_height_set_to_page_support() { + let topFrame = frameModule.topmost(); + let currentPage = topFrame.currentPage; + + (currentPage).width = "50%"; + (currentPage).height = "50%"; + + TKUnit.waitUntilReady(() => { + return currentPage.isLayoutValid; + }, 1); + + let topFrameWidth = topFrame.getMeasuredWidth(); + let topFrameHeight = topFrame.getMeasuredHeight(); + + let currentPageWidth = currentPage.getMeasuredWidth(); + let currentPageHeight = currentPage.getMeasuredHeight(); + + TKUnit.assertEqual(currentPageWidth, Math.floor(topFrameWidth / 2), "Current page measuredWidth incorrect"); + TKUnit.assertEqual(currentPageHeight, Math.floor(topFrameHeight / 2), "Current page measuredHeight incorrect"); + + //reset values. + (currentPage.style)._resetValue(heightProperty); + (currentPage.style)._resetValue(widthProperty); + + TKUnit.assert(isNaN(currentPage.width), "width"); + TKUnit.assert(isNaN(currentPage.height), "height"); +} + +export function test_percent_margin_set_to_page_support() { + let topFrame = frameModule.topmost(); + let currentPage = topFrame.currentPage; + currentPage.margin = "10%"; + + TKUnit.waitUntilReady(() => { + return currentPage.isLayoutValid; + }, 1); + + let topFrameWidth = topFrame.getMeasuredWidth(); + let topFrameHeight = topFrame.getMeasuredHeight(); + + let currentPageWidth = currentPage.getMeasuredWidth(); + let currentPageHeight = currentPage.getMeasuredHeight() + + let marginLeft = topFrameWidth * 0.1; + let marginTop = topFrameHeight * 0.1; + + let bounds = currentPage._getCurrentLayoutBounds(); + TKUnit.assertEqual(bounds.left, Math.round(marginLeft), "Current page LEFT position incorrect"); + TKUnit.assertEqual(bounds.top, Math.round(marginTop), "Current page TOP position incorrect"); + TKUnit.assertEqual(bounds.right, Math.round(marginLeft + currentPageWidth), "Current page RIGHT position incorrect"); + TKUnit.assertEqual(bounds.bottom, Math.round(marginTop + currentPageHeight), "Current page BOTTOM position incorrect"); + + //reset values. + currentPage.margin = "0"; + + TKUnit.assertEqual(currentPage.marginLeft, 0, "marginLeft"); + TKUnit.assertEqual(currentPage.marginTop, 0, "marginTop"); + TKUnit.assertEqual(currentPage.marginRight, 0, "marginRight"); + TKUnit.assertEqual(currentPage.marginBottom, 0, "marginBottom"); +} \ No newline at end of file diff --git a/tests/app/ui/frame/frame-tests.ios.ts b/tests/app/ui/frame/frame-tests.ios.ts new file mode 100644 index 000000000..8d294d8e6 --- /dev/null +++ b/tests/app/ui/frame/frame-tests.ios.ts @@ -0,0 +1,65 @@ +import frameModule = require("ui/frame"); +import TKUnit = require("../../TKUnit"); +import { widthProperty, heightProperty } from "ui/styling/style"; +var uiUtils = require("ui/utils"); + +export function test_percent_width_and_height_set_to_page_support() { + let topFrame = frameModule.topmost(); + let currentPage = topFrame.currentPage; + + (currentPage).width = "50%"; + (currentPage).height = "50%"; + + TKUnit.waitUntilReady(() => { + return currentPage.isLayoutValid; + }, 1); + + let topFrameWidth = topFrame.getMeasuredWidth(); + let topFrameHeight = topFrame.getMeasuredHeight(); + + let currentPageWidth = currentPage.getMeasuredWidth(); + let currentPageHeight = currentPage.getMeasuredHeight(); + + TKUnit.assertEqual(currentPageWidth, Math.round(topFrameWidth / 2), "Current page measuredWidth incorrect"); + TKUnit.assertEqual(currentPageHeight, Math.round(topFrameHeight / 2), "Current page measuredHeight incorrect"); + + //reset values. + (currentPage.style)._resetValue(heightProperty); + (currentPage.style)._resetValue(widthProperty); + + TKUnit.assert(isNaN(currentPage.width), "width"); + TKUnit.assert(isNaN(currentPage.height), "height"); +} + +export function test_percent_margin_set_to_page_support() { + let topFrame = frameModule.topmost(); + let currentPage = topFrame.currentPage; + currentPage.margin = "10%"; + + TKUnit.waitUntilReady(() => { + return currentPage.isLayoutValid; + }, 1); + + let topFrameWidth = topFrame.getMeasuredWidth(); + let topFrameHeight = topFrame.getMeasuredHeight(); + + let currentPageWidth = currentPage.getMeasuredWidth(); + let currentPageHeight = currentPage.getMeasuredHeight() + + let marginLeft = topFrameWidth * 0.1; + let marginTop = topFrameHeight * 0.1 + uiUtils.ios.getStatusBarHeight(); + + let bounds = currentPage._getCurrentLayoutBounds(); + TKUnit.assertEqual(bounds.left, Math.round(marginLeft), "Current page LEFT position incorrect"); + TKUnit.assertEqual(bounds.top, Math.round(marginTop), "Current page TOP position incorrect"); + TKUnit.assertEqual(bounds.right, Math.round(marginLeft + currentPageWidth), "Current page RIGHT position incorrect"); + TKUnit.assertEqual(bounds.bottom, Math.round(marginTop + currentPageHeight), "Current page BOTTOM position incorrect"); + + //reset values. + currentPage.margin = "0"; + + TKUnit.assertEqual(currentPage.marginLeft, 0, "marginLeft"); + TKUnit.assertEqual(currentPage.marginTop, 0, "marginTop"); + TKUnit.assertEqual(currentPage.marginRight, 0, "marginRight"); + TKUnit.assertEqual(currentPage.marginBottom, 0, "marginBottom"); +} \ No newline at end of file diff --git a/tests/app/ui/frame/frame-tests.ts b/tests/app/ui/frame/frame-tests.ts deleted file mode 100644 index fe62d2d5b..000000000 --- a/tests/app/ui/frame/frame-tests.ts +++ /dev/null @@ -1,128 +0,0 @@ -// >> frame-require -import frameModule = require("ui/frame"); -var topmost = frameModule.topmost(); -// << frame-require - -import platform = require("platform"); -import labelModule = require("ui/label"); -import pagesModule = require("ui/page"); -import testModule = require("../../ui-test"); -import TKUnit = require("../../TKUnit"); -import {widthProperty, heightProperty} from "ui/styling/style" - -var uiUtils; -if (platform.isIOS) { - uiUtils = require("ui/utils"); -} - -export class FrameTest extends testModule.UITest { - - public create(): frameModule.Frame { - return new frameModule.Frame(); - } - - public test_percent_width_and_height_set_to_page_support() { - let topFrame = frameModule.topmost(); - - let currentPage = topFrame.currentPage; - - (currentPage).width = "50%"; - (currentPage).height = "50%"; - - this.waitUntilTestElementLayoutIsValid(); - - let topFrameWidth = topFrame.getMeasuredWidth(); - let topFrameHeight = topFrame.getMeasuredHeight(); - - let currentPageWidth = currentPage.getMeasuredWidth(); - let currentPageHeight = currentPage.getMeasuredHeight() - - TKUnit.assertEqual(currentPageWidth, Math.round(topFrameWidth / 2), "Current page MeasuredWidth incorrect"); - TKUnit.assertEqual(currentPageHeight, Math.round(topFrameHeight / 2), "Current page MeasuredHeight incorrect"); - - //reset values. - (currentPage.style)._resetValue(heightProperty); - (currentPage.style)._resetValue(widthProperty); - - TKUnit.assert(isNaN(currentPage.width), "width"); - TKUnit.assert(isNaN(currentPage.height), "height"); - } - - public test_percent_margin_set_to_page_support() { - let topFrame = frameModule.topmost(); - - let currentPage = topFrame.currentPage; - - currentPage.margin = "10%"; - - this.waitUntilTestElementLayoutIsValid(); - - let topFrameWidth = topFrame.getMeasuredWidth(); - let topFrameHeight = topFrame.getMeasuredHeight(); - - let currentPageWidth = currentPage.getMeasuredWidth(); - let currentPageHeight = currentPage.getMeasuredHeight() - - let marginLeft = topFrameWidth * 0.1; - let marginTop; - if (uiUtils) { - marginTop = topFrameHeight * 0.1 + uiUtils.ios.getStatusBarHeight(); - } else { - marginTop = topFrameHeight * 0.1; - } - - let bounds = currentPage._getCurrentLayoutBounds(); - TKUnit.assertEqual(bounds.left, Math.round(marginLeft), "Current page LEFT position incorrect"); - TKUnit.assertEqual(bounds.top, Math.round(marginTop), "Current page TOP position incorrect"); - TKUnit.assertEqual(bounds.right, Math.round(marginLeft + currentPageWidth), "Current page RIGHT position incorrect"); - TKUnit.assertEqual(bounds.bottom, Math.round(marginTop + currentPageHeight), "Current page BOTTOM position incorrect"); - - //reset values. - currentPage.margin = "0"; - - TKUnit.assertEqual(currentPage.marginLeft, 0, "marginLeft"); - TKUnit.assertEqual(currentPage.marginTop, 0, "marginTop"); - TKUnit.assertEqual(currentPage.marginRight, 0, "marginRight"); - TKUnit.assertEqual(currentPage.marginBottom, 0, "marginBottom"); - } -} - -export var ignore_test_DummyTestForSnippetOnly0 = function () { - // >> frame-navigating - topmost.navigate("details-page"); - // << frame-navigating -} - -export var ignore_test_DummyTestForSnippetOnly1 = function () { - // >> frame-factory-func - var factoryFunc = function () { - var label = new labelModule.Label(); - label.text = "Hello, world!"; - var page = new pagesModule.Page(); - page.content = label; - return page; - }; - topmost.navigate(factoryFunc); - // <> frame-naventry - var navigationEntry = { - moduleName: "details-page", - context: { info: "something you want to pass to your page" }, - animated: false - }; - topmost.navigate(navigationEntry); - // << frame-naventry -} - -export var ignore_test_DummyTestForSnippetOnly3 = function () { - // >> frame-back - topmost.goBack(); - // << frame-back -} - -export function createTestCase(): FrameTest { - return new FrameTest(); -} diff --git a/tests/app/ui/page/page-tests-common.ts b/tests/app/ui/page/page-tests-common.ts index 81a29a352..73c6693a5 100644 --- a/tests/app/ui/page/page-tests-common.ts +++ b/tests/app/ui/page/page-tests-common.ts @@ -20,7 +20,7 @@ import observable = require("data/observable"); import {Page, ShownModallyData, NavigatedData} from "ui/page"; import {Label} from "ui/label"; import {EventData} from "data/observable"; -import {widthProperty} from "ui/styling/style" +import {widthProperty, heightProperty} from "ui/styling/style" import platform = require("platform"); export function addLabelToPage(page: Page, text?: string) { @@ -554,10 +554,8 @@ export function test_percent_width_and_height_support() { TKUnit.assertEqual(pageHeight, Math.round(pageHeight / 2), "Current page MeasuredHeight incorrect"); //reset values. - testPage.height = Number.NaN; + (testPage.style)._resetValue(heightProperty); (testPage.style)._resetValue(widthProperty); - - testPage.height = Number.NaN; TKUnit.assert(isNaN(testPage.width), "width"); TKUnit.assert(isNaN(testPage.height), "height");