Merge pull request #3497 from NativeScript/nnikolov/PageTests

Page tests fix.
This commit is contained in:
Nedyalko Nikolov
2017-01-16 19:39:44 +02:00
committed by GitHub
8 changed files with 31 additions and 14 deletions

View File

@ -81,7 +81,7 @@ allTests["SLIDER"] = require("./ui/slider/slider-tests");
allTests["SWITCH"] = require("./ui/switch/switch-tests");
allTests["PROGRESS"] = require("./ui/progress/progress-tests");
allTests["PLACEHOLDER"] = require("./ui/placeholder/placeholder-tests");
// allTests["PAGE"] = require("./ui/page/page-tests");
allTests["PAGE"] = require("./ui/page/page-tests");
allTests["LISTVIEW"] = require("./ui/list-view/list-view-tests");
allTests["ACTIVITY-INDICATOR"] = require("./ui/activity-indicator/activity-indicator-tests");
allTests["TEXT-FIELD"] = require("./ui/text-field/text-field-tests");

View File

@ -23,6 +23,7 @@ import { EventData } from "data/observable";
import { PercentLength } from "ui/core/view";
import * as platform from "platform";
import {unsetValue} from "ui/core/view";
import { Color } from "color";
export function addLabelToPage(page: Page, text?: string) {
let label = new Label();
@ -122,7 +123,7 @@ export function test_NavigateToNewPage() {
TKUnit.waitUntilReady(() => { return topFrame.currentPage !== null && topFrame.currentPage === currentPage });
TKUnit.assert(testPage.parent === undefined, "Page.parent should become undefined after navigating back");
TKUnit.assert(testPage._context === undefined, "Page._context should become undefined after navigating back");
TKUnit.assert(testPage._context === null, "Page._context should become undefined after navigating back");
TKUnit.assert(testPage.isLoaded === false, "Page.isLoaded should become false after navigating back");
TKUnit.assert(testPage.frame === undefined, "Page.frame should become undefined after navigating back");
TKUnit.assert(testPage._isAddedToNativeVisualTree === false, "Page._isAddedToNativeVisualTree should become false after navigating back");
@ -376,7 +377,12 @@ export function test_page_backgroundColor_is_white() {
page.id = "page_test_page_backgroundColor_is_white";
let factory = () => page;
helper.navigate(factory);
TKUnit.assertEqual(page.style.backgroundColor.hex.toLowerCase(), "#ffffff", "page background-color");
let whiteColor = new Color("white");
if (platform.isIOS) {
TKUnit.assertTrue(whiteColor.ios.CGColor.isEqual(page.nativeView.backgroundColor.CGColor), "page default backgroundColor should be white");
} else {
TKUnit.assertEqual(page.nativeView.getBackground().getColor(), whiteColor.android, "page default backgroundColor should be white");
}
}
export function test_WhenPageIsLoadedFrameCurrentPageIsNotYetTheSameAsThePage() {

View File

@ -48,7 +48,7 @@ export function test_NavigateToNewPage_WithAndroidCache() {
TKUnit.assert(testPage.frame === undefined, "Page.frame should become undefined after navigating back");
TKUnit.assert(testPage._isAddedToNativeVisualTree === false, "Page._isAddedToNativeVisualTree should become false after navigating back");
TKUnit.assert(label._context === undefined, "InnerControl._context should not be set after navigate back.");
TKUnit.assert(label._context === null, "InnerControl._context should not be set after navigate back.");
TKUnit.assert(label.android === undefined, "InnerControl.android should not be set after navigate back.");
TKUnit.assert(label._nativeView === undefined, "InnerControl._nativeView hould not be set after navigate back.");
TKUnit.assert(label.isLoaded === false, "InnerControl.isLoaded should become false after navigating back");
@ -69,7 +69,7 @@ export var test_NavigateToNewPage_InnerControl = function () {
var label = <LabelModule.Label>testPage.content;
TKUnit.assert(label._context === undefined, "InnerControl._context should be undefined after navigate back.");
TKUnit.assert(label._context === null, "InnerControl._context should be undefined after navigate back.");
TKUnit.assert(label.android === undefined, "InnerControl.android should be undefined after navigate back.");
TKUnit.assert(label._nativeView === undefined, "InnerControl._nativeView should be undefined after navigate back.");
TKUnit.assert(label.isLoaded === false, "InnerControl.isLoaded should become false after navigating back");

View File

@ -23,7 +23,7 @@ export function test_NavigateToNewPage_InnerControl() {
helper.goBack();
TKUnit.assertEqual(label._context, undefined, "label._context should be undefined after navigate back.");
TKUnit.assertEqual(label._context, null, "label._context should be undefined after navigate back.");
TKUnit.assertEqual(label.android, undefined, "label.android should be undefined after navigate back.");
TKUnit.assertFalse(label.isLoaded, "label.isLoaded should become false after navigating back");
}

View File

@ -1485,7 +1485,11 @@ function convertToTransform(value: string): [CssProperty<any, any>, any][] {
}
// Background properties.
export const backgroundInternalProperty = new CssProperty<Style, Background>({ name: "backgroundInternal", cssName: "_backgroundInternal", defaultValue: Background.default });
export const backgroundInternalProperty = new CssProperty<Style, Background>({
name: "backgroundInternal",
cssName: "_backgroundInternal",
defaultValue: Background.default
});
backgroundInternalProperty.register(Style);
let pattern: RegExp = /url\(('|")(.*?)\1\)/;

View File

@ -1,7 +1,6 @@
import { Page as PageDefinition, NavigatedData, ShownModallyData } from "ui/page";
import {
ContentView, View, backgroundColorProperty,
eachDescendant, Property, Color, isIOS, booleanConverter, resetCSSProperties
ContentView, View, eachDescendant, Property, Color, isIOS, booleanConverter, resetCSSProperties
} from "ui/content-view";
import { Frame, topmost as topmostFrame, resolvePageFromEntry } from "ui/frame";
import { ActionBar } from "ui/action-bar";
@ -41,9 +40,6 @@ export class PageBase extends ContentView implements PageDefinition {
constructor() {
super();
this.actionBar = new ActionBar();
// The default style of the page should be white background
this.style[backgroundColorProperty.cssName] = new Color("white");
}
// public onLoaded() {

View File

@ -92,10 +92,15 @@ export class Page extends PageBase {
return this._grid;
}
get nativeView(): android.view.ViewGroup {
return this._grid;
}
public _createNativeView() {
this._grid = new org.nativescript.widgets.GridLayout(this._context);
this._grid.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.auto));
this._grid.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.star));
this.nativeView.setBackgroundColor(new Color("white").android);
}
public _addViewToNativeVisualTree(child: View, atIndex?: number): boolean {
@ -126,6 +131,7 @@ export class Page extends PageBase {
if (!skipDetached) {
super._tearDownUI();
this._isAddedToNativeVisualTree = false;
}
}

View File

@ -5,6 +5,7 @@
} from "./page-common";
import { ios as iosApp } from "application";
import { device } from "platform";
import { Color } from "color";
import * as uiUtils from "ui/utils";
export * from "./page-common";
@ -115,9 +116,9 @@ class UIViewControllerImpl extends UIViewController {
let widthSpec = layout.makeMeasureSpec(width, mode);
let heightSpec = layout.makeMeasureSpec(height, mode);
View.measureChild(null, owner, widthSpec, heightSpec);
View.measureChild(owner._modalParent, owner, widthSpec, heightSpec);
let top = ((backgroundSpanUnderStatusBar && isFullScreen) || ios.MajorVersion < 8 || !isFullScreen) ? 0 : statusBarHeight;
View.layoutChild(null, owner, 0, top, width, bottom);
View.layoutChild(owner._modalParent, owner, 0, top, width, bottom);
if (ios.MajorVersion < 8) {
if (!backgroundSpanUnderStatusBar && (!isTablet || isFullScreen)) {
@ -339,6 +340,7 @@ export class Page extends PageBase {
super();
this._ios = UIViewControllerImpl.initWithOwner(new WeakRef(this));
this.nativeView = this._ios.view;
this.nativeView.backgroundColor = new Color("white").ios;
}
public requestLayout(): void {
@ -582,6 +584,9 @@ export class Page extends PageBase {
}
set [actionBarHiddenProperty.native](value: boolean) {
this._updateEnableSwipeBackNavigation(value);
if (this.isLoaded) {
this.updateActionBar(value);
}
}
get [statusBarStyleProperty.native](): UIBarStyle {