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