From 4c08839459cdb50531b70bec008b169750fddb99 Mon Sep 17 00:00:00 2001 From: Manol Donev Date: Tue, 6 Nov 2018 16:57:38 +0200 Subject: [PATCH] test: add test for #6490 (#6517) --- tests/app/ui/helper.ts | 12 ++--- .../ui/tab-view/tab-view-navigation-tests.ts | 52 ++++++++++++++++++- tests/package.json | 4 +- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/tests/app/ui/helper.ts b/tests/app/ui/helper.ts index 5d3c4ff81..0f8509712 100644 --- a/tests/app/ui/helper.ts +++ b/tests/app/ui/helper.ts @@ -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 { diff --git a/tests/app/ui/tab-view/tab-view-navigation-tests.ts b/tests/app/ui/tab-view/tab-view-navigation-tests.ts index fb202a8a8..929012885 100644 --- a/tests/app/ui/tab-view/tab-view-navigation-tests.ts +++ b/tests/app/ui/tab-view/tab-view-navigation-tests.ts @@ -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(); + 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(); diff --git a/tests/package.json b/tests/package.json index b05b37039..eab3e58c4 100644 --- a/tests/package.json +++ b/tests/package.json @@ -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": {