mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
Fixed test_NavigateToNewPage_WithAndroidCache failure on Android API level 17
Unit tests re-factoring and improvements
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
import {Page, NavigatedData} from "ui/page";
|
||||
import {topmost as topmostFrame, NavigationTransition} from "ui/frame";
|
||||
import {Color} from "color";
|
||||
import helper = require("../ui/helper");
|
||||
|
||||
// Creates a random colorful page full of meaningless stuff.
|
||||
var id = 0;
|
||||
@ -13,17 +14,6 @@ var pageFactory = function (): Page {
|
||||
return page;
|
||||
};
|
||||
|
||||
function waitUntilNavigatedFrom(oldPage: Page) {
|
||||
let topmost = topmostFrame();
|
||||
TKUnit.waitUntilReady(() => {
|
||||
return topmost.currentPage
|
||||
&& topmost.currentPage !== oldPage
|
||||
&& topmost.currentPage.isLoaded
|
||||
&& !oldPage.isLoaded
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
function androidGC() {
|
||||
let topmost = topmostFrame();
|
||||
if (topmost.android) {
|
||||
@ -35,27 +25,20 @@ function androidGC() {
|
||||
function _test_backstackVisible(transition?: NavigationTransition) {
|
||||
let topmost = topmostFrame();
|
||||
let mainTestPage = topmost.currentPage;
|
||||
topmost.navigate({ create: pageFactory, transition: transition, animated: true });
|
||||
waitUntilNavigatedFrom(mainTestPage);
|
||||
helper.navigateWithEntry({ create: pageFactory, transition: transition, animated: true });
|
||||
|
||||
// page1 should not be added to the backstack
|
||||
let page0 = topmost.currentPage;
|
||||
topmost.navigate({ create: pageFactory, backstackVisible: false, transition: transition, animated: true });
|
||||
waitUntilNavigatedFrom(page0);
|
||||
helper.navigateWithEntry({ create: pageFactory, backstackVisible: false, transition: transition, animated: true });
|
||||
|
||||
let page1 = topmost.currentPage;
|
||||
topmost.navigate({ create: pageFactory, transition: transition, animated: true });
|
||||
waitUntilNavigatedFrom(page1);
|
||||
helper.navigateWithEntry({ create: pageFactory, transition: transition, animated: true });
|
||||
|
||||
let page2 = topmost.currentPage;
|
||||
topmost.goBack();
|
||||
waitUntilNavigatedFrom(page2);
|
||||
helper.goBack();
|
||||
|
||||
// From page2 we have to go directly to page0, skipping page1.
|
||||
TKUnit.assert(topmost.currentPage === page0, "Page 1 should be skipped when going back.");
|
||||
|
||||
topmost.goBack();
|
||||
waitUntilNavigatedFrom(page0);
|
||||
helper.goBack();
|
||||
TKUnit.assertEqual(topmost.currentPage, mainTestPage, "We should be on the main test page at the end of the test.");
|
||||
}
|
||||
|
||||
@ -66,7 +49,7 @@ export var test_backstackVisible = function () {
|
||||
|
||||
export var test_backstackVisible_WithTransition = function () {
|
||||
androidGC();
|
||||
_test_backstackVisible({name: "fade"});
|
||||
_test_backstackVisible({ name: "fade" });
|
||||
}
|
||||
|
||||
function _test_backToEntry(transition?: NavigationTransition) {
|
||||
@ -112,7 +95,7 @@ function _test_backToEntry(transition?: NavigationTransition) {
|
||||
currentPageMustBe("page1");
|
||||
let page1 = topmost.currentPage;
|
||||
back(1);
|
||||
waitUntilNavigatedFrom(page1);
|
||||
helper.waitUntilNavigatedFrom(page1);
|
||||
TKUnit.assertEqual(topmost.currentPage, mainTestPage, "We should be on the main test page at the end of the test.");
|
||||
}
|
||||
|
||||
@ -133,35 +116,23 @@ function _test_ClearHistory(transition?: NavigationTransition) {
|
||||
return mainTestPage;
|
||||
};
|
||||
|
||||
var currentPage: Page;
|
||||
|
||||
currentPage = topmost.currentPage;
|
||||
topmost.navigate({ create: pageFactory, clearHistory: true, transition: transition, animated: true });
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
helper.navigateWithEntry({ create: pageFactory, clearHistory: true, transition: transition, animated: true });
|
||||
TKUnit.assertEqual(topmost.backStack.length, 0, "1.topmost.backStack.length");
|
||||
TKUnit.assertEqual(topmost.canGoBack(), false, "1.topmost.canGoBack().");
|
||||
|
||||
currentPage = topmost.currentPage;
|
||||
topmost.navigate({ create: pageFactory, transition: transition, animated: true });
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
helper.navigateWithEntry({ create: pageFactory, transition: transition, animated: true });
|
||||
TKUnit.assertEqual(topmost.backStack.length, 1, "2.topmost.backStack.length");
|
||||
TKUnit.assertEqual(topmost.canGoBack(), true, "2.topmost.canGoBack().");
|
||||
|
||||
currentPage = topmost.currentPage;
|
||||
topmost.navigate({ create: pageFactory, transition: transition, animated: true });
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
helper.navigateWithEntry({ create: pageFactory, transition: transition, animated: true });
|
||||
TKUnit.assertEqual(topmost.backStack.length, 2, "3.topmost.backStack.length");
|
||||
TKUnit.assertEqual(topmost.canGoBack(), true, "3.topmost.canGoBack().");
|
||||
|
||||
currentPage = topmost.currentPage;
|
||||
topmost.navigate({ create: pageFactory, clearHistory: true, transition: transition, animated: true });
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
helper.navigateWithEntry({ create: pageFactory, clearHistory: true, transition: transition, animated: true });
|
||||
TKUnit.assertEqual(topmost.backStack.length, 0, "4.topmost.backStack.length");
|
||||
TKUnit.assertEqual(topmost.canGoBack(), false, "4.topmost.canGoBack().");
|
||||
|
||||
currentPage = topmost.currentPage;
|
||||
topmost.navigate({ create: mainPageFactory, clearHistory: true, animated: false });
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
helper.navigateWithEntry({ create: mainPageFactory, clearHistory: true, animated: false });
|
||||
TKUnit.assertEqual(topmost.backStack.length, 0, "5.topmost.backStack.length");
|
||||
TKUnit.assertEqual(topmost.canGoBack(), false, "5.topmost.canGoBack().");
|
||||
|
||||
@ -203,25 +174,18 @@ export var test_ClearHistoryWithTransitionDoesNotBreakNavigation = function () {
|
||||
};
|
||||
|
||||
// Go to details-page
|
||||
topmost.navigate({ create: pageFactory, clearHistory: false, animated: true });
|
||||
waitUntilNavigatedFrom(mainTestPage);
|
||||
helper.navigateWithEntry({ create: pageFactory, clearHistory: false, animated: true });
|
||||
|
||||
// Go back to main-page with clearHistory
|
||||
var detailsPage: Page;
|
||||
detailsPage = topmost.currentPage;
|
||||
topmost.transition = { name: "fade" };
|
||||
topmost.navigate({ create: mainPageFactory, clearHistory: true, animated: true });
|
||||
waitUntilNavigatedFrom(detailsPage);
|
||||
helper.navigateWithEntry({ create: mainPageFactory, clearHistory: true, animated: true });
|
||||
|
||||
// Go to details-page AGAIN
|
||||
topmost.navigate({ create: pageFactory, clearHistory: false, animated: true });
|
||||
waitUntilNavigatedFrom(mainTestPage);
|
||||
helper.navigateWithEntry({ create: pageFactory, clearHistory: false, animated: true });
|
||||
|
||||
// Go back to main-page with clearHistory
|
||||
detailsPage = topmost.currentPage;
|
||||
topmost.transition = { name: "fade" };
|
||||
topmost.navigate({ create: mainPageFactory, clearHistory: true, animated: true });
|
||||
waitUntilNavigatedFrom(detailsPage);
|
||||
helper.navigateWithEntry({ create: mainPageFactory, clearHistory: true, animated: true });
|
||||
|
||||
// Clean up
|
||||
topmost.transition = undefined;
|
||||
@ -245,24 +209,16 @@ export var test_ClearHistoryWithTransitionDoesNotBreakNavigation_WithLocalTransi
|
||||
};
|
||||
|
||||
// Go to 1st page
|
||||
var currentPage = topmost.currentPage;
|
||||
topmost.navigate({ create: pageFactory, clearHistory: false, transition: { name: "fade" }, animated: true });
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
helper.navigateWithEntry({ create: pageFactory, clearHistory: false, transition: { name: "fade" }, animated: true });
|
||||
|
||||
// Go to 2nd page
|
||||
currentPage = topmost.currentPage;
|
||||
topmost.navigate({ create: pageFactory, clearHistory: false, transition: { name: "fade" }, animated: true });
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
helper.navigateWithEntry({ create: pageFactory, clearHistory: false, transition: { name: "fade" }, animated: true });
|
||||
|
||||
// Go to 3rd page with clearHistory
|
||||
currentPage = topmost.currentPage;
|
||||
topmost.navigate({ create: pageFactory, clearHistory: true, transition: { name: "fade" }, animated: true });
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
helper.navigateWithEntry({ create: pageFactory, clearHistory: true, transition: { name: "fade" }, animated: true });
|
||||
|
||||
// Go back to main
|
||||
currentPage = topmost.currentPage;
|
||||
topmost.navigate({ create: mainPageFactory, clearHistory: true, transition: { name: "fade" }, animated: true });
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
helper.navigateWithEntry({ create: mainPageFactory, clearHistory: true, transition: { name: "fade" }, animated: true });
|
||||
|
||||
if (topmost.android) {
|
||||
topmostFrame().android.cachePagesOnNavigate = originalCachePagesOnNavigate;
|
||||
@ -301,13 +257,10 @@ function _test_NavigationEvents(transition?: NavigationTransition) {
|
||||
};
|
||||
|
||||
// Go to other page
|
||||
topmost.navigate({ create: secondPageFactory, transition: transition, animated: true });
|
||||
waitUntilNavigatedFrom(mainTestPage);
|
||||
helper.navigateWithEntry({ create: secondPageFactory, transition: transition, animated: true });
|
||||
|
||||
// Go back to main
|
||||
let currentPage = topmost.currentPage;
|
||||
topmost.goBack();
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
helper.goBack();
|
||||
|
||||
mainTestPage.id = originalMainPageId;
|
||||
|
||||
|
@ -84,13 +84,5 @@ export var test_Transitions = function () {
|
||||
_testTransition({ instance: customTransition });
|
||||
}
|
||||
|
||||
var oldPage = topmost.currentPage;
|
||||
topmost.navigate({ create: mainPageFactory, clearHistory: true, animated: false });
|
||||
TKUnit.waitUntilReady(() => {
|
||||
return topmost.currentPage
|
||||
&& topmost.currentPage !== oldPage
|
||||
&& topmost.currentPage.isLoaded
|
||||
&& !oldPage.isLoaded
|
||||
;
|
||||
});
|
||||
helper.navigateWithEntry({ create: mainPageFactory, clearHistory: true, animated: false });
|
||||
}
|
||||
|
@ -15,10 +15,10 @@ export var ASYNC = 0.2;
|
||||
export var MEMORY_ASYNC = 2;
|
||||
|
||||
function clearPage(): void {
|
||||
let newPage = frame.topmost().currentPage;
|
||||
let newPage = getCurrentPage();
|
||||
if (!newPage) {
|
||||
TKUnit.waitUntilReady(() => frame.topmost().currentPage !== null);
|
||||
newPage = frame.topmost().currentPage;
|
||||
TKUnit.waitUntilReady(() => getCurrentPage() !== null);
|
||||
newPage = getCurrentPage();
|
||||
}
|
||||
|
||||
if (!newPage) {
|
||||
@ -34,7 +34,7 @@ function clearPage(): void {
|
||||
|
||||
export function do_PageTest(test: (views: Array<view.View>) => void, content: view.View, secondView: view.View, thirdView: view.View) {
|
||||
clearPage();
|
||||
let newPage = frame.topmost().currentPage;
|
||||
let newPage = getCurrentPage();
|
||||
newPage.content = content;
|
||||
test([newPage, content, secondView, thirdView, newPage.actionBar]);
|
||||
newPage.content = null;
|
||||
@ -42,7 +42,7 @@ export function do_PageTest(test: (views: Array<view.View>) => void, content: vi
|
||||
|
||||
export function do_PageTest_WithButton(test: (views: Array<view.View>) => void) {
|
||||
clearPage();
|
||||
let newPage = frame.topmost().currentPage;
|
||||
let newPage = getCurrentPage();
|
||||
let btn = new button.Button();
|
||||
newPage.content = btn;
|
||||
test([newPage, btn, newPage.actionBar]);
|
||||
@ -51,7 +51,7 @@ export function do_PageTest_WithButton(test: (views: Array<view.View>) => void)
|
||||
|
||||
export function do_PageTest_WithStackLayout_AndButton(test: (views: Array<view.View>) => void) {
|
||||
clearPage();
|
||||
let newPage = frame.topmost().currentPage;
|
||||
let newPage = getCurrentPage();
|
||||
let stackLayout = new stackLayoutModule.StackLayout();
|
||||
let btn = new button.Button();
|
||||
stackLayout.addChild(btn);
|
||||
@ -63,7 +63,7 @@ export function do_PageTest_WithStackLayout_AndButton(test: (views: Array<view.V
|
||||
//export function buildUIAndRunTest(controlToTest, testFunction, pageCss?, testDelay?) {
|
||||
export function buildUIAndRunTest(controlToTest, testFunction, pageCss?) {
|
||||
clearPage();
|
||||
let newPage = frame.topmost().currentPage;
|
||||
let newPage = getCurrentPage();
|
||||
newPage.content = controlToTest;
|
||||
if (pageCss) {
|
||||
newPage.css = pageCss;
|
||||
@ -76,7 +76,7 @@ export function buildUIAndRunTest(controlToTest, testFunction, pageCss?) {
|
||||
|
||||
export function buildUIWithWeakRefAndInteract<T extends view.View>(createFunc: () => T, interactWithViewFunc?: (view: T) => void, done?) {
|
||||
clearPage();
|
||||
let newPage = frame.topmost().currentPage;
|
||||
let newPage = getCurrentPage();
|
||||
let sp = new stackLayoutModule.StackLayout();
|
||||
let testFinished = false;
|
||||
|
||||
@ -134,22 +134,31 @@ export function navigateToModule(moduleName: string, context?: any): page.Page {
|
||||
return navigateWithEntry(entry);
|
||||
}
|
||||
|
||||
export function getCurrentPage(): page.Page {
|
||||
return frame.topmost().currentPage;
|
||||
}
|
||||
|
||||
export function waitUntilNavigatedFrom(oldPage: page.Page) {
|
||||
TKUnit.waitUntilReady(() => getCurrentPage() && getCurrentPage() !== oldPage);
|
||||
}
|
||||
|
||||
export function navigateWithEntry(entry: frame.NavigationEntry): page.Page {
|
||||
let page = frame.resolvePageFromEntry(entry);
|
||||
entry.moduleName = null;
|
||||
entry.animated = false
|
||||
entry.create = function () {
|
||||
return page;
|
||||
}
|
||||
|
||||
let currentPage = getCurrentPage();
|
||||
frame.topmost().navigate(entry);
|
||||
TKUnit.waitUntilReady(() => getCurrentPage() !== null && getCurrentPage() !== currentPage);
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
return page;
|
||||
}
|
||||
|
||||
export function getCurrentPage(): page.Page {
|
||||
return frame.topmost().currentPage;
|
||||
export function goBack() {
|
||||
let currentPage = getCurrentPage();
|
||||
frame.topmost().goBack();
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
}
|
||||
|
||||
export function assertAreClose(actual: number, expected: number, message: string): void {
|
||||
|
@ -6,7 +6,8 @@ import types = require("utils/types");
|
||||
import platform = require("platform");
|
||||
import utils = require("utils/utils");
|
||||
import { Label } from "ui/label";
|
||||
import {topmost} from "ui/frame";
|
||||
import helper = require("../helper");
|
||||
import { Page } from "ui/page";
|
||||
|
||||
// >> article-require-listview-module
|
||||
import listViewModule = require("ui/list-view");
|
||||
@ -622,12 +623,8 @@ export class ListViewTest extends testModule.UITest<listViewModule.ListView> {
|
||||
listView.items = items;
|
||||
this.waitUntilListViewReady();
|
||||
|
||||
let currentPage = listView.page;
|
||||
let frame = topmost();
|
||||
frame.navigate("pages/navigation/pageB");
|
||||
TKUnit.waitUntilReady(() => frame.currentPage !== null && frame.currentPage !== currentPage);
|
||||
frame.goBack();
|
||||
TKUnit.waitUntilReady(() => frame.currentPage !== null && frame.currentPage === currentPage);
|
||||
helper.navigateWithHistory(() => new Page());
|
||||
helper.goBack();
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
TKUnit.assertEqual(items.getItem(i).loadedCount, 1 + modifier, "Loaded Count");
|
||||
|
@ -41,6 +41,7 @@ export function test_AfterPageLoaded_is_called_NativeInstance_is_created() {
|
||||
|
||||
let pageFactory = function (): Page {
|
||||
page = new Page();
|
||||
page.id = `page_test_AfterPageLoaded_is_called_NativeInstance_is_created`;
|
||||
page.on(view.View.loadedEvent, handler);
|
||||
|
||||
label = new Label();
|
||||
@ -67,6 +68,7 @@ export function test_PageLoaded_is_called_once() {
|
||||
|
||||
let pageFactory = function (): Page {
|
||||
page1 = new Page();
|
||||
page1.id = `page1_test_PageLoaded_is_called_once`;
|
||||
addLabelToPage(page1, "Page 1");
|
||||
return page1;
|
||||
};
|
||||
@ -76,6 +78,7 @@ export function test_PageLoaded_is_called_once() {
|
||||
|
||||
let pageFactory2 = function (): Page {
|
||||
page2 = new Page();
|
||||
page2.id = `page2_test_PageLoaded_is_called_once`;
|
||||
addLabelToPage(page2, "Page 2");
|
||||
page2.on(view.View.loadedEvent, handler);
|
||||
return page2;
|
||||
@ -137,6 +140,7 @@ function _test_PageNavigation_EventSequence(withTransition: boolean) {
|
||||
let eventSequence = [];
|
||||
let pageFactory = function () {
|
||||
testPage = new Page();
|
||||
testPage.id = "testPage_test_PageNavigation_EventSequence";
|
||||
addLabelToPage(testPage);
|
||||
|
||||
testPage.on(Page.navigatingToEvent, function (data: NavigatedData) {
|
||||
@ -172,32 +176,27 @@ function _test_PageNavigation_EventSequence(withTransition: boolean) {
|
||||
return testPage;
|
||||
};
|
||||
|
||||
let currentPage = frameModule.topmost().currentPage;
|
||||
let navigationEntry: frameModule.NavigationEntry;
|
||||
if (withTransition) {
|
||||
let navigationTransition: frameModule.NavigationTransition = {
|
||||
name: "slide",
|
||||
duration: 100,
|
||||
};
|
||||
let navigationEntry: frameModule.NavigationEntry = {
|
||||
navigationEntry = {
|
||||
create: pageFactory,
|
||||
context: context,
|
||||
animated: true,
|
||||
transition: navigationTransition
|
||||
transition: {
|
||||
name: "slide",
|
||||
duration: 100,
|
||||
}
|
||||
}
|
||||
frameModule.topmost().navigate(navigationEntry);
|
||||
}
|
||||
else {
|
||||
let navigationEntry: frameModule.NavigationEntry = {
|
||||
navigationEntry = {
|
||||
create: pageFactory,
|
||||
context: context,
|
||||
animated: false
|
||||
}
|
||||
frameModule.topmost().navigate(navigationEntry);
|
||||
}
|
||||
|
||||
TKUnit.waitUntilReady(() => frameModule.topmost().currentPage !== null && frameModule.topmost().currentPage === testPage);
|
||||
|
||||
frameModule.goBack();
|
||||
TKUnit.waitUntilReady(() => frameModule.topmost().currentPage !== null && frameModule.topmost().currentPage === currentPage);
|
||||
helper.navigateWithEntry(navigationEntry);
|
||||
helper.goBack();
|
||||
|
||||
let expectedEventSequence = ["navigatingTo", "loaded", "navigatedTo", "navigatingFrom", "unloaded", "navigatedFrom"];
|
||||
TKUnit.arrayAssert(eventSequence, expectedEventSequence, "Actual event sequence is not equal to expected. Actual: " + eventSequence + "; Expected: " + expectedEventSequence);
|
||||
@ -227,9 +226,7 @@ export function test_NavigateTo_WithContext() {
|
||||
let actualContextValue = testPage.navigationContext;
|
||||
TKUnit.assertEqual(actualContextValue, "myContext");
|
||||
|
||||
topFrame.goBack();
|
||||
TKUnit.waitUntilReady(() => topFrame.currentPage !== null && topFrame.currentPage === currentPage);
|
||||
|
||||
helper.goBack();
|
||||
TKUnit.assertNull(testPage.navigationContext, "Navigation context should be cleared on navigating back");
|
||||
}
|
||||
|
||||
@ -237,24 +234,21 @@ export function test_FrameBackStack_WhenNavigatingForwardAndBack() {
|
||||
let testPage: Page;
|
||||
let pageFactory = function () {
|
||||
testPage = new Page();
|
||||
testPage.id = "testPage_test_FrameBackStack_WhenNavigatingForwardAndBack";
|
||||
addLabelToPage(testPage);
|
||||
return testPage;
|
||||
};
|
||||
|
||||
helper.navigateWithHistory(pageFactory);
|
||||
|
||||
let topFrame = frameModule.topmost();
|
||||
let currentPage = topFrame.currentPage;
|
||||
|
||||
topFrame.navigate(pageFactory);
|
||||
TKUnit.waitUntilReady(() => topFrame.currentPage !== null && topFrame.currentPage === testPage);
|
||||
|
||||
TKUnit.assertEqual(topFrame.backStack.length, 1);
|
||||
TKUnit.assertTrue(topFrame.canGoBack(), "We should can go back.");
|
||||
TKUnit.assertTrue(topFrame.canGoBack(), "topFrame.canGoBack() should be true");
|
||||
|
||||
topFrame.goBack();
|
||||
TKUnit.waitUntilReady(() => topFrame.currentPage !== null && topFrame.currentPage === currentPage);
|
||||
helper.goBack();
|
||||
|
||||
TKUnit.assertEqual(topFrame.backStack.length, 0);
|
||||
TKUnit.assertFalse(topFrame.canGoBack(), "canGoBack should return false.");
|
||||
TKUnit.assertFalse(topFrame.canGoBack(), "topFrame.canGoBack() should be false");
|
||||
}
|
||||
|
||||
export function test_LoadPageFromModule() {
|
||||
@ -291,6 +285,7 @@ export function test_NavigateToPageCreatedWithNavigationEntry() {
|
||||
let testPage: Page;
|
||||
let pageFactory = function () {
|
||||
testPage = new Page();
|
||||
testPage.id = "testPage_test_NavigateToPageCreatedWithNavigationEntry";
|
||||
addLabelToPage(testPage, expectedText);
|
||||
return testPage;
|
||||
};
|
||||
@ -304,6 +299,7 @@ export function test_NavigateToPageCreatedWithNavigationEntry() {
|
||||
export function test_cssShouldBeAppliedToAllNestedElements() {
|
||||
let expectedText = "Some text";
|
||||
let testPage = new Page();
|
||||
testPage.id = "testPage_test_cssShouldBeAppliedToAllNestedElements";
|
||||
let label = new Label();
|
||||
label.text = expectedText;
|
||||
|
||||
@ -325,6 +321,7 @@ export function test_cssShouldBeAppliedToAllNestedElements() {
|
||||
export function test_cssShouldBeAppliedAfterChangeToAllNestedElements() {
|
||||
let expectedText = "Some text";
|
||||
let testPage = new Page();
|
||||
testPage.id = "testPage_test_cssShouldBeAppliedAfterChangeToAllNestedElements";
|
||||
let label = new Label();
|
||||
label.text = expectedText;
|
||||
|
||||
@ -349,6 +346,7 @@ export function test_cssShouldBeAppliedAfterChangeToAllNestedElements() {
|
||||
|
||||
export function test_page_backgroundColor_is_white() {
|
||||
let page = new Page();
|
||||
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");
|
||||
@ -362,7 +360,7 @@ export function test_WhenPageIsLoadedFrameCurrentPageIsNotYetTheSameAsThePage()
|
||||
|
||||
let pageFactory = function (): Page {
|
||||
page = new Page();
|
||||
page.id = "newPage";
|
||||
page.id = "page_test_WhenPageIsLoadedFrameCurrentPageIsNotYetTheSameAsThePage";
|
||||
page.on(view.View.loadedEvent, loadedEventHandler);
|
||||
let label = new Label();
|
||||
label.text = "Text";
|
||||
@ -382,7 +380,7 @@ export function test_WhenPageIsNavigatedToFrameCurrentPageIsNowTheSameAsThePage(
|
||||
|
||||
let pageFactory = function (): Page {
|
||||
page = new Page();
|
||||
page.id = "newPage";
|
||||
page.id = "page_test_WhenPageIsNavigatedToFrameCurrentPageIsNowTheSameAsThePage";
|
||||
page.on(Page.navigatedToEvent, navigatedEventHandler);
|
||||
let label = new Label();
|
||||
label.text = "Text";
|
||||
@ -410,31 +408,32 @@ export function test_WhenNavigatingForwardAndBack_IsBackNavigationIsCorrect() {
|
||||
|
||||
let pageFactory1 = function (): Page {
|
||||
page1 = new Page();
|
||||
page1.id = "page1_test_WhenNavigatingForwardAndBack_IsBackNavigationIsCorrect";
|
||||
page1.on(Page.navigatedToEvent, navigatedEventHandler);
|
||||
return page1;
|
||||
};
|
||||
|
||||
let pageFactory2 = function (): Page {
|
||||
page2 = new Page();
|
||||
page2.id = "page2_test_WhenNavigatingForwardAndBack_IsBackNavigationIsCorrect";
|
||||
page2.on(Page.navigatedToEvent, navigatedEventHandler);
|
||||
return page2;
|
||||
};
|
||||
|
||||
let topFrame = frameModule.topmost();
|
||||
helper.navigateWithHistory(pageFactory1);
|
||||
helper.navigateWithHistory(pageFactory2);
|
||||
|
||||
frameModule.goBack();
|
||||
TKUnit.waitUntilReady(() => topFrame.currentPage !== null && topFrame.currentPage === page1);
|
||||
helper.goBack();
|
||||
|
||||
TKUnit.assertEqual(forwardCounter, 2, "Forward navigation counter should be 1");
|
||||
TKUnit.assertEqual(forwardCounter, 2, "Forward navigation counter should be 2");
|
||||
TKUnit.assertEqual(backCounter, 1, "Backward navigation counter should be 1");
|
||||
page1.off(Page.navigatedToEvent, navigatedEventHandler);
|
||||
page2.off(Page.navigatedToEvent, navigatedEventHandler);
|
||||
|
||||
helper.goBack();
|
||||
}
|
||||
|
||||
export function test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal() {
|
||||
|
||||
if (platform.device.os === platform.platformNames.android
|
||||
&& android.os.Build.VERSION.SDK_INT === android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
|
||||
&& android.os.Build.CPU_ABI.indexOf("x86") !== -1) {
|
||||
@ -494,7 +493,7 @@ export function test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal() {
|
||||
|
||||
let masterPageFactory = function (): Page {
|
||||
masterPage = new Page();
|
||||
masterPage.id = "newPage";
|
||||
masterPage.id = "masterPage_test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal";
|
||||
masterPage.on(Page.navigatedToEvent, navigatedToEventHandler);
|
||||
let label = new Label();
|
||||
label.text = "Text";
|
||||
|
@ -8,11 +8,21 @@ import frame = require("ui/frame");
|
||||
global.moduleMerge(PageTestCommon, exports);
|
||||
|
||||
export function test_NavigateToNewPage_WithAndroidCache() {
|
||||
// Clear history if any.
|
||||
helper.navigate(() => {
|
||||
let launchPage = new PageModule.Page();
|
||||
launchPage.id = "launchPage_test_NavigateToNewPage_WithAndroidCache";
|
||||
return launchPage;
|
||||
});
|
||||
|
||||
TKUnit.assertEqual(frame.topmost().backStack.length, 0, "The backstack should be empty before this test can be run.");
|
||||
|
||||
var testPage: PageModule.Page;
|
||||
var label: LabelModule.Label;
|
||||
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
testPage = new PageModule.Page();
|
||||
testPage.id = "testPage_test_NavigateToNewPage_WithAndroidCache";
|
||||
label = new LabelModule.Label();
|
||||
label.text = "The quick brown fox jumps over the lazy dog.";
|
||||
testPage.content = label;
|
||||
@ -22,13 +32,11 @@ export function test_NavigateToNewPage_WithAndroidCache() {
|
||||
var androidFrame = frame.topmost().android;
|
||||
var cachingBefore = androidFrame.cachePagesOnNavigate;
|
||||
try {
|
||||
let currentPage = frame.topmost().currentPage;
|
||||
androidFrame.cachePagesOnNavigate = true;
|
||||
|
||||
helper.navigateWithHistory(pageFactory);
|
||||
|
||||
frame.goBack();
|
||||
TKUnit.waitUntilReady(() => frame.topmost().currentPage !== null && frame.topmost().currentPage === currentPage);
|
||||
helper.goBack();
|
||||
}
|
||||
finally {
|
||||
androidFrame.cachePagesOnNavigate = cachingBefore;
|
||||
@ -50,14 +58,13 @@ export var test_NavigateToNewPage_InnerControl = function () {
|
||||
var testPage: PageModule.Page;
|
||||
var pageFactory = function () {
|
||||
testPage = new PageModule.Page();
|
||||
testPage.id = "testPage_test_NavigateToNewPage_InnerControl";
|
||||
PageTestCommon.addLabelToPage(testPage);
|
||||
return testPage;
|
||||
};
|
||||
|
||||
let currentPage = frame.topmost().currentPage;
|
||||
helper.navigateWithHistory(pageFactory);
|
||||
frame.goBack();
|
||||
TKUnit.waitUntilReady(() => frame.topmost().currentPage !== null && frame.topmost().currentPage === currentPage);
|
||||
helper.goBack();
|
||||
|
||||
var label = <LabelModule.Label>testPage.content;
|
||||
|
||||
@ -72,6 +79,7 @@ export var test_ChangePageCaching_AfterNavigated_Throws = function () {
|
||||
var testPage: PageModule.Page;
|
||||
var pageFactory = function () {
|
||||
var testPage = new PageModule.Page();
|
||||
testPage.id = "testPage_test_ChangePageCaching_AfterNavigated_Throws";
|
||||
testPage.content = new LabelModule.Label();
|
||||
return testPage;
|
||||
};
|
||||
@ -99,6 +107,7 @@ export var test_SetPageCaching_ToTheSameValue_AfterNavigated_DoesNotThrow = func
|
||||
var testPage: PageModule.Page;
|
||||
var pageFactory = function () {
|
||||
var testPage = new PageModule.Page();
|
||||
testPage.id = "testPage_test_SetPageCaching_ToTheSameValue_AfterNavigated_DoesNotThrow";
|
||||
testPage.content = new LabelModule.Label();
|
||||
return testPage;
|
||||
};
|
||||
|
@ -18,12 +18,10 @@ export function test_NavigateToNewPage_InnerControl() {
|
||||
return testPage;
|
||||
};
|
||||
|
||||
let currentPage = helper.getCurrentPage();
|
||||
helper.navigateWithHistory(pageFactory);
|
||||
var label = <Label>testPage.content;
|
||||
|
||||
frame.goBack();
|
||||
TKUnit.waitUntilReady(() => !label.isLoaded && frame.topmost().currentPage === currentPage);
|
||||
helper.goBack();
|
||||
|
||||
TKUnit.assertEqual(label._context, undefined, "label._context should be undefined after navigate back.");
|
||||
TKUnit.assertEqual(label.android, undefined, "label.android should be undefined after navigate back.");
|
||||
|
@ -494,6 +494,9 @@ class AndroidFrame extends Observable implements definition.AndroidFrame {
|
||||
public set cachePagesOnNavigate(value: boolean) {
|
||||
if (this._cachePagesOnNavigate !== value) {
|
||||
if (this._owner.backStack.length > 0) {
|
||||
this._owner._printFrameBackStack();
|
||||
this._owner._printNativeBackStack();
|
||||
console.log(`currentPage: ${this._owner.currentPage}`);
|
||||
throw new Error("Cannot set cachePagesOnNavigate if there are items in the back stack.");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user