test: add test for #6490 (#6517)

This commit is contained in:
Manol Donev
2018-11-06 16:57:38 +02:00
committed by GitHub
parent 1485445123
commit 4c08839459
3 changed files with 59 additions and 9 deletions

View File

@@ -209,8 +209,8 @@ export function waitUntilNavigatedTo(page: Page, action: Function) {
TKUnit.waitUntilReady(() => completed, 5);
}
export function waitUntilNavigatedFrom(action: Function) {
const currentPage = frame.topmost().currentPage;
export function waitUntilNavigatedFrom(action: Function, topFrame?: frame.Frame) {
const currentPage = topFrame ? topFrame.currentPage : frame.topmost().currentPage;
let completed = false;
function navigatedFrom(args) {
args.object.page.off("navigatedFrom", navigatedFrom);
@@ -226,19 +226,19 @@ export function waitUntilLayoutReady(view: View): void {
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;
entry.moduleName = null;
entry.create = function () {
return page;
};
waitUntilNavigatedFrom(() => frame.topmost().navigate(entry));
waitUntilNavigatedFrom(() => topFrame ? topFrame.navigate(entry) : frame.topmost().navigate(entry));
return page;
}
export function goBack() {
waitUntilNavigatedFrom(() => frame.topmost().goBack());
export function goBack(topFrame?: frame.Frame) {
waitUntilNavigatedFrom(() => topFrame ? topFrame.goBack() : frame.topmost().goBack());
}
export function assertAreClose(actual: number, expected: number, message: string): void {

View File

@@ -4,7 +4,7 @@ import { isIOS, isAndroid } from "tns-core-modules/platform";
import { Label } from "tns-core-modules/ui/label";
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
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 { TabView, TabViewItem } from "tns-core-modules/ui/tab-view";
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() {
var topFrame = frameModule.topmost();

View File

@@ -6,10 +6,10 @@
"nativescript": {
"id": "org.nativescript.UnitTestApp",
"tns-ios": {
"version": "4.2.0"
"version": "5.0.0"
},
"tns-android": {
"version": "4.2.0"
"version": "5.0.0"
}
},
"dependencies": {