mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
@@ -209,8 +209,8 @@ export function waitUntilNavigatedTo(page: Page, action: Function) {
|
|||||||
TKUnit.waitUntilReady(() => completed, 5);
|
TKUnit.waitUntilReady(() => completed, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function waitUntilNavigatedFrom(action: Function) {
|
export function waitUntilNavigatedFrom(action: Function, topFrame?: frame.Frame) {
|
||||||
const currentPage = frame.topmost().currentPage;
|
const currentPage = topFrame ? topFrame.currentPage : frame.topmost().currentPage;
|
||||||
let completed = false;
|
let completed = false;
|
||||||
function navigatedFrom(args) {
|
function navigatedFrom(args) {
|
||||||
args.object.page.off("navigatedFrom", navigatedFrom);
|
args.object.page.off("navigatedFrom", navigatedFrom);
|
||||||
@@ -226,19 +226,19 @@ export function waitUntilLayoutReady(view: View): void {
|
|||||||
TKUnit.waitUntilReady(() => view.isLayoutValid);
|
TKUnit.waitUntilReady(() => view.isLayoutValid);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function navigateWithEntry(entry: frame.NavigationEntry): Page {
|
export function navigateWithEntry(entry: frame.NavigationEntry, topFrame?: frame.Frame): Page {
|
||||||
const page = createViewFromEntry(entry) as Page;
|
const page = createViewFromEntry(entry) as Page;
|
||||||
entry.moduleName = null;
|
entry.moduleName = null;
|
||||||
entry.create = function () {
|
entry.create = function () {
|
||||||
return page;
|
return page;
|
||||||
};
|
};
|
||||||
|
|
||||||
waitUntilNavigatedFrom(() => frame.topmost().navigate(entry));
|
waitUntilNavigatedFrom(() => topFrame ? topFrame.navigate(entry) : frame.topmost().navigate(entry));
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function goBack() {
|
export function goBack(topFrame?: frame.Frame) {
|
||||||
waitUntilNavigatedFrom(() => frame.topmost().goBack());
|
waitUntilNavigatedFrom(() => topFrame ? topFrame.goBack() : frame.topmost().goBack());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function assertAreClose(actual: number, expected: number, message: string): void {
|
export function assertAreClose(actual: number, expected: number, message: string): void {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { isIOS, isAndroid } from "tns-core-modules/platform";
|
|||||||
import { Label } from "tns-core-modules/ui/label";
|
import { Label } from "tns-core-modules/ui/label";
|
||||||
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
|
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
|
||||||
import * as frameModule from "tns-core-modules/ui/frame";
|
import * as frameModule from "tns-core-modules/ui/frame";
|
||||||
import { Page } from "tns-core-modules/ui/page";
|
import { Page, NavigatedData } from "tns-core-modules/ui/page";
|
||||||
import { ListView, ItemEventData } from "tns-core-modules/ui/list-view";
|
import { ListView, ItemEventData } from "tns-core-modules/ui/list-view";
|
||||||
import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view";
|
import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view";
|
||||||
import { Button } from "tns-core-modules/ui/button";
|
import { Button } from "tns-core-modules/ui/button";
|
||||||
@@ -68,6 +68,56 @@ function _clickHandlerFactory(index: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _createFrameView(): frameModule.Frame {
|
||||||
|
const frame = new frameModule.Frame();
|
||||||
|
frame.navigate({ create: () => new Page() });
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function testBackNavigationToTabViewWithNestedFramesShouldWork() {
|
||||||
|
// https://github.com/NativeScript/NativeScript/issues/6490
|
||||||
|
const topFrame = frameModule.topmost();
|
||||||
|
|
||||||
|
let tabViewPage: Page;
|
||||||
|
let tabView: TabView;
|
||||||
|
|
||||||
|
const pageFactory = function (): Page {
|
||||||
|
tabView = _createTabView();
|
||||||
|
let items = Array<TabViewItem>();
|
||||||
|
let tabViewitem = new TabViewItem();
|
||||||
|
tabViewitem.title = "Item1";
|
||||||
|
tabViewitem.view = _createFrameView();
|
||||||
|
items.push(tabViewitem);
|
||||||
|
|
||||||
|
let tabViewitem2 = new TabViewItem();
|
||||||
|
tabViewitem2.title = "Item2";
|
||||||
|
tabViewitem2.view = _createFrameView();
|
||||||
|
items.push(tabViewitem2);
|
||||||
|
|
||||||
|
tabView.items = items;
|
||||||
|
|
||||||
|
tabViewPage = new Page();
|
||||||
|
tabViewPage.id = "tab-view-page";
|
||||||
|
tabViewPage.content = tabView;
|
||||||
|
|
||||||
|
return tabViewPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
helper.waitUntilNavigatedFrom(() => topFrame.navigate(pageFactory), topFrame);
|
||||||
|
|
||||||
|
TKUnit.waitUntilReady(() => topFrame.currentPage === tabViewPage);
|
||||||
|
TKUnit.waitUntilReady(() => tabViewIsFullyLoaded(tabView));
|
||||||
|
|
||||||
|
// navigate to a different page
|
||||||
|
helper.waitUntilNavigatedFrom(() => topFrame.navigate({ create: () => new Page(), animated: false }), topFrame);
|
||||||
|
|
||||||
|
// navigate back to the page that hold the tabview with nested frames
|
||||||
|
topFrame.goBack();
|
||||||
|
|
||||||
|
// make sure the app did not crash
|
||||||
|
TKUnit.waitUntilReady(() => topFrame.navigationQueueIsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithAListViewTheListViewIsThere() {
|
export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithAListViewTheListViewIsThere() {
|
||||||
var topFrame = frameModule.topmost();
|
var topFrame = frameModule.topmost();
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
"nativescript": {
|
"nativescript": {
|
||||||
"id": "org.nativescript.UnitTestApp",
|
"id": "org.nativescript.UnitTestApp",
|
||||||
"tns-ios": {
|
"tns-ios": {
|
||||||
"version": "4.2.0"
|
"version": "5.0.0"
|
||||||
},
|
},
|
||||||
"tns-android": {
|
"tns-android": {
|
||||||
"version": "4.2.0"
|
"version": "5.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user