FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

chore: restore tabroot/resetrootview tests (#6705) · NativeScript/NativeScript@6095779 · GitHub

Commit 6095779

Browse files
authored
chore: restore tabroot/resetrootview tests (#6705)
1 parent 1989594 commit 6095779

4 files changed

Lines changed: 44 additions & 29 deletions

File tree

‎tests/app/testRunner.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ allTests["STYLE-PROPERTIES"] = stylePropertiesTests;
153153
import * as frameTests from "./ui/frame/frame-tests";
154154
allTests["FRAME"] = frameTests;
155155

156-
// import * as tabViewRootTests from "./ui/tab-view/tab-view-root-tests";
157-
// allTests["TAB-VIEW-ROOT"] = tabViewRootTests;
156+
import * as tabViewRootTests from "./ui/tab-view/tab-view-root-tests";
157+
allTests["TAB-VIEW-ROOT"] = tabViewRootTests;
158158

159159
import * as viewTests from "./ui/view/view-tests";
160160
allTests["VIEW"] = viewTests;
@@ -255,8 +255,8 @@ allTests["SEARCH-BAR"] = searchBarTests;
255255
import * as navigationTests from "./navigation/navigation-tests";
256256
allTests["NAVIGATION"] = navigationTests;
257257

258-
// import * as resetRootViewTests from "./ui/root-view/reset-root-view-tests";
259-
// allTests["RESET-ROOT-VIEW"] = resetRootViewTests;
258+
import * as resetRootViewTests from "./ui/root-view/reset-root-view-tests";
259+
allTests["RESET-ROOT-VIEW"] = resetRootViewTests;
260260

261261
import * as rootViewTests from "./ui/root-view/root-view-tests";
262262
allTests["ROOT-VIEW"] = rootViewTests;

‎tests/app/ui/root-view/reset-root-view-tests.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import * as TKUnit from "../../TKUnit";
22
import * as helper from "../helper";
33
import { Page } from "tns-core-modules/ui/page";
4+
import { isAndroid } from "tns-core-modules/platform";
45
import { Frame, NavigationEntry, stack } from "tns-core-modules/ui/frame";
56
import { _resetRootView, getRootView } from "tns-core-modules/application";
67
import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view";
78

9+
function waitUntilTabViewReady(page: Page, action: Function) {
10+
helper.waitUntilNavigatedTo(page, action);
11+
12+
if (isAndroid) {
13+
TKUnit.waitUntilReady(() => page.frame._currentEntry.fragment.isAdded());
14+
}
15+
}
16+
817
function createTestFrameRootEntry() {
918
const page = new Page();
1019
const frameRoot = new Frame();
@@ -77,7 +86,7 @@ export function test_reset_frame_to_tab() {
7786

7887
const testTabRoot = createTestTabRootEntry();
7988

80-
helper.waitUntilNavigatedTo(testTabRoot.page, () => _resetRootView(testTabRoot.entry));
89+
waitUntilTabViewReady(testTabRoot.page, () => _resetRootView(testTabRoot.entry));
8190

8291
const rootView2 = getRootView();
8392
const frameStack2 = stack();
@@ -88,7 +97,7 @@ export function test_reset_frame_to_tab() {
8897
export function test_reset_tab_to_frame() {
8998
const testTabRoot = createTestTabRootEntry();
9099

91-
helper.waitUntilNavigatedTo(testTabRoot.page, () => _resetRootView(testTabRoot.entry));
100+
waitUntilTabViewReady(testTabRoot.page, () => _resetRootView(testTabRoot.entry));
92101

93102
const rootView2 = getRootView();
94103
const frameStack2 = stack();
@@ -108,7 +117,7 @@ export function test_reset_tab_to_frame() {
108117
export function test_reset_tab_to_tab() {
109118
const testTabRoot1 = createTestTabRootEntry();
110119

111-
helper.waitUntilNavigatedTo(testTabRoot1.page, () => _resetRootView(testTabRoot1.entry));
120+
waitUntilTabViewReady(testTabRoot1.page, () => _resetRootView(testTabRoot1.entry));
112121

113122
const rootView1 = getRootView();
114123
const frameStack1 = stack();
@@ -117,7 +126,7 @@ export function test_reset_tab_to_tab() {
117126

118127
const testTabRoot2 = createTestTabRootEntry();
119128

120-
helper.waitUntilNavigatedTo(testTabRoot2.page, () => _resetRootView(testTabRoot2.entry));
129+
waitUntilTabViewReady(testTabRoot2.page, () => _resetRootView(testTabRoot2.entry));
121130

122131
const rootView2 = getRootView();
123132
const frameStack2 = stack();
@@ -128,7 +137,7 @@ export function test_reset_tab_to_tab() {
128137
export function test_reset_during_tab_index_change() {
129138
const testTabRoot = createTestTabRootEntry();
130139

131-
helper.waitUntilNavigatedTo(testTabRoot.page, () => _resetRootView(testTabRoot.entry));
140+
waitUntilTabViewReady(testTabRoot.page, () => _resetRootView(testTabRoot.entry));
132141

133142
testTabRoot.root.selectedIndex = 1;
134143

‎tests/app/ui/tab-view/tab-view-root-tests.ts‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ function waitUntilNavigatedToMaxTimeout(pages: Page[], action: Function) {
1818
TKUnit.waitUntilReady(() => completed === pages.length, maxTimeout);
1919
}
2020

21+
function waitUntilTabViewReady(page: Page, action: Function) {
22+
action();
23+
24+
if (isAndroid) {
25+
TKUnit.waitUntilReady(() => page.frame._currentEntry.fragment.isAdded());
26+
} else {
27+
TKUnit.waitUntilReady(() => page.isLoaded);
28+
}
29+
}
30+
2131
function createPage(i: number) {
2232
const page = new Page();
2333
page.id = `Tab${i} Frame${i} Page${i}`;
@@ -60,25 +70,21 @@ export function test_frame_topmost_matches_selectedIndex() {
6070
const items = createTabItemsWithFrames(3);
6171
const tabView = new TabView();
6272
tabView.items = items.map(item => item.tabItem);
63-
tabView.selectedIndex = 0;
73+
74+
// iOS cannot preload tab items
75+
// Android preloads 1 tab item to the sides by default
76+
// set this to 0, so that both platforms behave the same.
77+
tabView.androidOffscreenTabLimit = 0;
6478

6579
const entry: NavigationEntry = {
6680
create: () => tabView
6781
};
6882

69-
if (isAndroid) {
70-
waitUntilNavigatedToMaxTimeout([items[0].page, items[1].page], () => _resetRootView(entry));
71-
TKUnit.assertEqual(topmost().id, "Tab0 Frame0");
72-
73-
tabView.selectedIndex = 1;
74-
TKUnit.assertEqual(topmost().id, "Tab1 Frame1");
75-
} else {
76-
waitUntilNavigatedToMaxTimeout([items[0].page], () => _resetRootView(entry));
77-
TKUnit.assertEqual(topmost().id, "Tab0 Frame0");
83+
waitUntilNavigatedToMaxTimeout([items[0].page], () => _resetRootView(entry));
84+
TKUnit.assertEqual(topmost().id, "Tab0 Frame0");
7885

79-
waitUntilNavigatedToMaxTimeout([items[1].page], () => tabView.selectedIndex = 1);
80-
TKUnit.assertEqual(topmost().id, "Tab1 Frame1");
81-
}
86+
waitUntilNavigatedToMaxTimeout([items[1].page], () => tabView.selectedIndex = 1);
87+
TKUnit.assertEqual(topmost().id, "Tab1 Frame1");
8288
}
8389

8490
export function test_offset_zero_should_raise_same_events() {
@@ -159,8 +165,8 @@ export function test_offset_zero_should_raise_same_events() {
159165
TKUnit.assertDeepEqual(actualEventsRaised, expectedEventsRaisedAfterSelectThirdTab);
160166

161167
resetActualEventsRaised();
162-
tabView.selectedIndex = 0;
163-
TKUnit.waitUntilReady(() => items[0].page.isLoaded);
168+
169+
waitUntilTabViewReady(items[0].page, () => tabView.selectedIndex = 0);
164170

165171
const expectedEventsRaisedAfterReturnToFirstTab = [
166172
[
@@ -256,8 +262,8 @@ export function test_android_default_offset_should_preload_1_tab_on_each_side()
256262
TKUnit.assertDeepEqual(actualEventsRaised, expectedEventsRaisedAfterSelectThirdTab);
257263

258264
resetActualEventsRaised();
259-
tabView.selectedIndex = 0;
260-
TKUnit.waitUntilReady(() => items[0].page.isLoaded);
265+
266+
waitUntilTabViewReady(items[0].page, () => tabView.selectedIndex = 0);
261267

262268
const expectedEventsRaisedAfterReturnToFirstTab = [
263269
[

‎tests/package.json‎

Lines changed: 3 additions & 3 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": "5.0.0"
9+
"version": "5.1.0"
1010
},
1111
"tns-android": {
12-
"version": "5.0.0"
12+
"version": "5.1.0"
1313
}
1414
},
1515
"dependencies": {
@@ -25,4 +25,4 @@
2525
"tns-platform-declarations": "*",
2626
"typescript": "^3.1.6"
2727
}
28-
}
28+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL