Skip to content

Commit 4c08839

Browse files
authored
1 parent 1485445 commit 4c08839

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

tests/app/ui/helper.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ export function waitUntilNavigatedTo(page: Page, action: Function) {
209209
TKUnit.waitUntilReady(() => completed, 5);
210210
}
211211

212-
export function waitUntilNavigatedFrom(action: Function) {
213-
const currentPage = frame.topmost().currentPage;
212+
export function waitUntilNavigatedFrom(action: Function, topFrame?: frame.Frame) {
213+
const currentPage = topFrame ? topFrame.currentPage : frame.topmost().currentPage;
214214
let completed = false;
215215
function navigatedFrom(args) {
216216
args.object.page.off("navigatedFrom", navigatedFrom);
@@ -226,19 +226,19 @@ export function waitUntilLayoutReady(view: View): void {
226226
TKUnit.waitUntilReady(() => view.isLayoutValid);
227227
}
228228

229-
export function navigateWithEntry(entry: frame.NavigationEntry): Page {
229+
export function navigateWithEntry(entry: frame.NavigationEntry, topFrame?: frame.Frame): Page {
230230
const page = createViewFromEntry(entry) as Page;
231231
entry.moduleName = null;
232232
entry.create = function () {
233233
return page;
234234
};
235235

236-
waitUntilNavigatedFrom(() => frame.topmost().navigate(entry));
236+
waitUntilNavigatedFrom(() => topFrame ? topFrame.navigate(entry) : frame.topmost().navigate(entry));
237237
return page;
238238
}
239239

240-
export function goBack() {
241-
waitUntilNavigatedFrom(() => frame.topmost().goBack());
240+
export function goBack(topFrame?: frame.Frame) {
241+
waitUntilNavigatedFrom(() => topFrame ? topFrame.goBack() : frame.topmost().goBack());
242242
}
243243

244244
export function assertAreClose(actual: number, expected: number, message: string): void {

tests/app/ui/tab-view/tab-view-navigation-tests.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isIOS, isAndroid } from "tns-core-modules/platform";
44
import { Label } from "tns-core-modules/ui/label";
55
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
66
import * as frameModule from "tns-core-modules/ui/frame";
7-
import { Page } from "tns-core-modules/ui/page";
7+
import { Page, NavigatedData } from "tns-core-modules/ui/page";
88
import { ListView, ItemEventData } from "tns-core-modules/ui/list-view";
99
import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view";
1010
import { Button } from "tns-core-modules/ui/button";
@@ -68,6 +68,56 @@ function _clickHandlerFactory(index: number) {
6868
}
6969
}
7070

71+
function _createFrameView(): frameModule.Frame {
72+
const frame = new frameModule.Frame();
73+
frame.navigate({ create: () => new Page() });
74+
return frame;
75+
}
76+
77+
export function testBackNavigationToTabViewWithNestedFramesShouldWork() {
78+
// https://github.com/NativeScript/NativeScript/issues/6490
79+
const topFrame = frameModule.topmost();
80+
81+
let tabViewPage: Page;
82+
let tabView: TabView;
83+
84+
const pageFactory = function (): Page {
85+
tabView = _createTabView();
86+
let items = Array<TabViewItem>();
87+
let tabViewitem = new TabViewItem();
88+
tabViewitem.title = "Item1";
89+
tabViewitem.view = _createFrameView();
90+
items.push(tabViewitem);
91+
92+
let tabViewitem2 = new TabViewItem();
93+
tabViewitem2.title = "Item2";
94+
tabViewitem2.view = _createFrameView();
95+
items.push(tabViewitem2);
96+
97+
tabView.items = items;
98+
99+
tabViewPage = new Page();
100+
tabViewPage.id = "tab-view-page";
101+
tabViewPage.content = tabView;
102+
103+
return tabViewPage;
104+
}
105+
106+
helper.waitUntilNavigatedFrom(() => topFrame.navigate(pageFactory), topFrame);
107+
108+
TKUnit.waitUntilReady(() => topFrame.currentPage === tabViewPage);
109+
TKUnit.waitUntilReady(() => tabViewIsFullyLoaded(tabView));
110+
111+
// navigate to a different page
112+
helper.waitUntilNavigatedFrom(() => topFrame.navigate({ create: () => new Page(), animated: false }), topFrame);
113+
114+
// navigate back to the page that hold the tabview with nested frames
115+
topFrame.goBack();
116+
117+
// make sure the app did not crash
118+
TKUnit.waitUntilReady(() => topFrame.navigationQueueIsEmpty());
119+
}
120+
71121
export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithAListViewTheListViewIsThere() {
72122
var topFrame = frameModule.topmost();
73123

tests/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"nativescript": {
77
"id": "org.nativescript.UnitTestApp",
88
"tns-ios": {
9-
"version": "4.2.0"
9+
"version": "5.0.0"
1010
},
1111
"tns-android": {
12-
"version": "4.2.0"
12+
"version": "5.0.0"
1313
}
1414
},
1515
"dependencies": {

0 commit comments

Comments
 (0)