From 60957799ad2876cb99af2c41c476f1ebc0fc74e7 Mon Sep 17 00:00:00 2001 From: Manol Donev Date: Fri, 14 Dec 2018 14:22:07 +0200 Subject: [PATCH] chore: restore tabroot/resetrootview tests (#6705) --- tests/app/testRunner.ts | 8 ++-- .../app/ui/root-view/reset-root-view-tests.ts | 19 ++++++--- tests/app/ui/tab-view/tab-view-root-tests.ts | 40 +++++++++++-------- tests/package.json | 6 +-- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/tests/app/testRunner.ts b/tests/app/testRunner.ts index a830c91b0..a119642a0 100644 --- a/tests/app/testRunner.ts +++ b/tests/app/testRunner.ts @@ -153,8 +153,8 @@ allTests["STYLE-PROPERTIES"] = stylePropertiesTests; import * as frameTests from "./ui/frame/frame-tests"; allTests["FRAME"] = frameTests; -// import * as tabViewRootTests from "./ui/tab-view/tab-view-root-tests"; -// allTests["TAB-VIEW-ROOT"] = tabViewRootTests; +import * as tabViewRootTests from "./ui/tab-view/tab-view-root-tests"; +allTests["TAB-VIEW-ROOT"] = tabViewRootTests; import * as viewTests from "./ui/view/view-tests"; allTests["VIEW"] = viewTests; @@ -255,8 +255,8 @@ allTests["SEARCH-BAR"] = searchBarTests; import * as navigationTests from "./navigation/navigation-tests"; allTests["NAVIGATION"] = navigationTests; -// import * as resetRootViewTests from "./ui/root-view/reset-root-view-tests"; -// allTests["RESET-ROOT-VIEW"] = resetRootViewTests; +import * as resetRootViewTests from "./ui/root-view/reset-root-view-tests"; +allTests["RESET-ROOT-VIEW"] = resetRootViewTests; import * as rootViewTests from "./ui/root-view/root-view-tests"; allTests["ROOT-VIEW"] = rootViewTests; diff --git a/tests/app/ui/root-view/reset-root-view-tests.ts b/tests/app/ui/root-view/reset-root-view-tests.ts index f28f8aafa..08e04e808 100644 --- a/tests/app/ui/root-view/reset-root-view-tests.ts +++ b/tests/app/ui/root-view/reset-root-view-tests.ts @@ -1,10 +1,19 @@ import * as TKUnit from "../../TKUnit"; import * as helper from "../helper"; import { Page } from "tns-core-modules/ui/page"; +import { isAndroid } from "tns-core-modules/platform"; import { Frame, NavigationEntry, stack } from "tns-core-modules/ui/frame"; import { _resetRootView, getRootView } from "tns-core-modules/application"; import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view"; +function waitUntilTabViewReady(page: Page, action: Function) { + helper.waitUntilNavigatedTo(page, action); + + if (isAndroid) { + TKUnit.waitUntilReady(() => page.frame._currentEntry.fragment.isAdded()); + } +} + function createTestFrameRootEntry() { const page = new Page(); const frameRoot = new Frame(); @@ -77,7 +86,7 @@ export function test_reset_frame_to_tab() { const testTabRoot = createTestTabRootEntry(); - helper.waitUntilNavigatedTo(testTabRoot.page, () => _resetRootView(testTabRoot.entry)); + waitUntilTabViewReady(testTabRoot.page, () => _resetRootView(testTabRoot.entry)); const rootView2 = getRootView(); const frameStack2 = stack(); @@ -88,7 +97,7 @@ export function test_reset_frame_to_tab() { export function test_reset_tab_to_frame() { const testTabRoot = createTestTabRootEntry(); - helper.waitUntilNavigatedTo(testTabRoot.page, () => _resetRootView(testTabRoot.entry)); + waitUntilTabViewReady(testTabRoot.page, () => _resetRootView(testTabRoot.entry)); const rootView2 = getRootView(); const frameStack2 = stack(); @@ -108,7 +117,7 @@ export function test_reset_tab_to_frame() { export function test_reset_tab_to_tab() { const testTabRoot1 = createTestTabRootEntry(); - helper.waitUntilNavigatedTo(testTabRoot1.page, () => _resetRootView(testTabRoot1.entry)); + waitUntilTabViewReady(testTabRoot1.page, () => _resetRootView(testTabRoot1.entry)); const rootView1 = getRootView(); const frameStack1 = stack(); @@ -117,7 +126,7 @@ export function test_reset_tab_to_tab() { const testTabRoot2 = createTestTabRootEntry(); - helper.waitUntilNavigatedTo(testTabRoot2.page, () => _resetRootView(testTabRoot2.entry)); + waitUntilTabViewReady(testTabRoot2.page, () => _resetRootView(testTabRoot2.entry)); const rootView2 = getRootView(); const frameStack2 = stack(); @@ -128,7 +137,7 @@ export function test_reset_tab_to_tab() { export function test_reset_during_tab_index_change() { const testTabRoot = createTestTabRootEntry(); - helper.waitUntilNavigatedTo(testTabRoot.page, () => _resetRootView(testTabRoot.entry)); + waitUntilTabViewReady(testTabRoot.page, () => _resetRootView(testTabRoot.entry)); testTabRoot.root.selectedIndex = 1; diff --git a/tests/app/ui/tab-view/tab-view-root-tests.ts b/tests/app/ui/tab-view/tab-view-root-tests.ts index 18d0fc99a..eb181e589 100644 --- a/tests/app/ui/tab-view/tab-view-root-tests.ts +++ b/tests/app/ui/tab-view/tab-view-root-tests.ts @@ -18,6 +18,16 @@ function waitUntilNavigatedToMaxTimeout(pages: Page[], action: Function) { TKUnit.waitUntilReady(() => completed === pages.length, maxTimeout); } +function waitUntilTabViewReady(page: Page, action: Function) { + action(); + + if (isAndroid) { + TKUnit.waitUntilReady(() => page.frame._currentEntry.fragment.isAdded()); + } else { + TKUnit.waitUntilReady(() => page.isLoaded); + } +} + function createPage(i: number) { const page = new Page(); page.id = `Tab${i} Frame${i} Page${i}`; @@ -60,25 +70,21 @@ export function test_frame_topmost_matches_selectedIndex() { const items = createTabItemsWithFrames(3); const tabView = new TabView(); tabView.items = items.map(item => item.tabItem); - tabView.selectedIndex = 0; + + // iOS cannot preload tab items + // Android preloads 1 tab item to the sides by default + // set this to 0, so that both platforms behave the same. + tabView.androidOffscreenTabLimit = 0; const entry: NavigationEntry = { create: () => tabView }; - if (isAndroid) { - waitUntilNavigatedToMaxTimeout([items[0].page, items[1].page], () => _resetRootView(entry)); - TKUnit.assertEqual(topmost().id, "Tab0 Frame0"); - - tabView.selectedIndex = 1; - TKUnit.assertEqual(topmost().id, "Tab1 Frame1"); - } else { - waitUntilNavigatedToMaxTimeout([items[0].page], () => _resetRootView(entry)); - TKUnit.assertEqual(topmost().id, "Tab0 Frame0"); + waitUntilNavigatedToMaxTimeout([items[0].page], () => _resetRootView(entry)); + TKUnit.assertEqual(topmost().id, "Tab0 Frame0"); - waitUntilNavigatedToMaxTimeout([items[1].page], () => tabView.selectedIndex = 1); - TKUnit.assertEqual(topmost().id, "Tab1 Frame1"); - } + waitUntilNavigatedToMaxTimeout([items[1].page], () => tabView.selectedIndex = 1); + TKUnit.assertEqual(topmost().id, "Tab1 Frame1"); } export function test_offset_zero_should_raise_same_events() { @@ -159,8 +165,8 @@ export function test_offset_zero_should_raise_same_events() { TKUnit.assertDeepEqual(actualEventsRaised, expectedEventsRaisedAfterSelectThirdTab); resetActualEventsRaised(); - tabView.selectedIndex = 0; - TKUnit.waitUntilReady(() => items[0].page.isLoaded); + + waitUntilTabViewReady(items[0].page, () => tabView.selectedIndex = 0); const expectedEventsRaisedAfterReturnToFirstTab = [ [ @@ -256,8 +262,8 @@ export function test_android_default_offset_should_preload_1_tab_on_each_side() TKUnit.assertDeepEqual(actualEventsRaised, expectedEventsRaisedAfterSelectThirdTab); resetActualEventsRaised(); - tabView.selectedIndex = 0; - TKUnit.waitUntilReady(() => items[0].page.isLoaded); + + waitUntilTabViewReady(items[0].page, () => tabView.selectedIndex = 0); const expectedEventsRaisedAfterReturnToFirstTab = [ [ diff --git a/tests/package.json b/tests/package.json index f7bba71ae..e5d9d7690 100644 --- a/tests/package.json +++ b/tests/package.json @@ -6,10 +6,10 @@ "nativescript": { "id": "org.nativescript.UnitTestApp", "tns-ios": { - "version": "5.0.0" + "version": "5.1.0" }, "tns-android": { - "version": "5.0.0" + "version": "5.1.0" } }, "dependencies": { @@ -25,4 +25,4 @@ "tns-platform-declarations": "*", "typescript": "^3.1.6" } -} \ No newline at end of file +}