Merge pull request #1636 from NativeScript/tab-view-navigation-tests

Re-enabled TabView Navigation Tests.
This commit is contained in:
Rossen Hristov
2016-02-25 09:08:21 +02:00

View File

@@ -1,121 +1,131 @@
//function _createTabView(): TabView { import TKUnit = require("../../TKUnit");
//var tabView = new TabView(); import helper = require("../helper");
//tabView.id = "TabView"; import {Label} from "ui/label";
//return tabView; import {StackLayout} from "ui/layouts/stack-layout";
//} import frameModule = require("ui/frame");
import {Page} from "ui/page";
import {ListView, ItemEventData} from "ui/list-view";
import {TabView, TabViewItem} from "ui/tab-view";
import {Button} from "ui/button";
import types = require("utils/types");
//function _createItems(count: number): Array<TabViewItem> { var ASYNC = 2;
//var items = new Array<TabViewItem>();
//for (var i = 0; i < count; i++) {
//var label = new Label();
//label.text = "Tab " + i;
//var tabEntry = new TabViewItem({
//title: "Tab " + i,
//view: label
//});
//items.push(tabEntry);
//}
//return items;
//}
//function _createListView(): ListView { function _createTabView(): TabView {
//var listView = new ListView(); var tabView = new TabView();
//listView.id = "ListView"; tabView.id = "TabView";
//var items = Array.apply(null, Array(10)).map(function (_, i) { return i; }); return tabView;
}
//listView.on(ListView.itemLoadingEvent, function (args: ItemEventData) { function _createItems(count: number): Array<TabViewItem> {
//var button = <Button>args.view; var items = new Array<TabViewItem>();
//if (!button) { for (var i = 0; i < count; i++) {
//button = new Button(); var label = new Label();
//args.view = button; label.text = "Tab " + i;
//} var tabEntry = new TabViewItem({
title: "Tab " + i,
view: label
});
tabEntry["index"] = i;
items.push(tabEntry);
}
return items;
}
//button.text = "Button" + args.index; function _createListView(): ListView {
//button.id = button.text; var listView = new ListView();
//button.on(Button.tapEvent, _clickHandlerFactory(args.index)); listView.id = "ListView";
//}); var items = Array.apply(null, Array(10)).map(function (_, i) { return i; });
//listView.items = items; listView.on(ListView.itemLoadingEvent, function (args: ItemEventData) {
var button = <Button>args.view;
if (!button) {
button = new Button();
args.view = button;
}
//return listView; button.text = "Button" + args.index;
//} button.id = button.text;
button.on(Button.tapEvent, _clickHandlerFactory(args.index));
});
//var _clickHandlerFactory = function (index: number) { listView.items = items;
//return function () {
//var pageFactory = function (): Page {
//var detailsLabel = new Label();
//detailsLabel.text = "Details Page " + index;
//var detailsPage = new Page();
//detailsPage.content = detailsLabel;
//return detailsPage;
//};
//helper.navigate(pageFactory); return listView;
//} }
//}
var _clickHandlerFactory = function (index: number) {
return function () {
var pageFactory = function (): Page {
var detailsLabel = new Label();
detailsLabel.text = "Details Page " + index;
var detailsPage = new Page();
detailsPage.id = "details-page";
detailsPage.content = detailsLabel;
return detailsPage;
};
helper.navigate(pageFactory);
}
}
export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithAListViewTheListViewIsThere() { export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithAListViewTheListViewIsThere() {
/*
var topFrame = frameModule.topmost(); var topFrame = frameModule.topmost();
var oldChache;
var oldChache;
if (topFrame.android) { if (topFrame.android) {
oldChache = topFrame.android.cachePagesOnNavigate; oldChache = topFrame.android.cachePagesOnNavigate;
topFrame.android.cachePagesOnNavigate = true; topFrame.android.cachePagesOnNavigate = true;
} }
try { var tabView;
var pageFactory = function (): Page {
tabView = _createTabView();
var items = [];
items.push({
title: "List",
view: _createListView()
});
var label = new Label();
label.text = "About";
var aboutLayout = new StackLayout();
aboutLayout.id = "AboutLayout";
aboutLayout.addChild(label);
items.push({
title: "About",
view: aboutLayout
});
tabView.items = items;
var mainPage: Page; var tabViewPage = new Page();
var pageFactory = function (): Page { tabViewPage.id = "tab-view-page";
var tabView = _createTabView(); tabViewPage.content = tabView;
var items = [];
items.push({
title: "List",
view: _createListView()
});
var label = new Label();
label.text = "About";
var aboutLayout = new StackLayout();
aboutLayout.id = "AboutLayout";
aboutLayout.addChild(label);
items.push({
title: "About",
view: aboutLayout
});
tabView.items = items;
mainPage = new Page(); return tabViewPage;
mainPage.content = tabView;
return mainPage;
}
helper.navigate(pageFactory);
var tabView = mainPage.getViewById<TabView>("TabView");
// This will navigate to a details page. The wait is inside the method.
_clickTheFirstButtonInTheListViewNatively(tabView);
// Go back to the main page containing the TabView.
helper.goBack();
// Go back to the root tests page.
helper.goBack();
}
finally {
if (topFrame.android) {
topFrame.android.cachePagesOnNavigate = oldChache;
}
} }
var listView = mainPage.getViewById<ListView>("ListView"); helper.navigate(pageFactory);
TKUnit.waitUntilReady(() => { return topFrame.currentPage.id === "tab-view-page" }, ASYNC);
TKUnit.waitUntilReady(() => { return tabViewIsFullyLoaded(tabView) }, ASYNC);
TKUnit.assert(listView !== undefined, "ListView should be created when navigating back to the main page."); // This will navigate to a details page. The wait is inside the method.
*/ _clickTheFirstButtonInTheListViewNatively(tabView);
TKUnit.waitUntilReady(() => { return topFrame.currentPage.id === "details-page" }, ASYNC);
helper.goBack();
TKUnit.waitUntilReady(() => { return topFrame.currentPage.id === "tab-view-page" }, ASYNC);
TKUnit.waitUntilReady(() => { return tabViewIsFullyLoaded(tabView) }, ASYNC);
helper.goBack();
TKUnit.waitUntilReady(() => { return topFrame.currentPage.id === "mainPage" }, ASYNC);
if (topFrame.android) {
topFrame.android.cachePagesOnNavigate = oldChache;
}
TKUnit.assert(tabView.items[0].view instanceof ListView, "ListView should be created when navigating back to the main page.");
} }
/*
export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack_NoPageCaching() { export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack_NoPageCaching() {
testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack(false); testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack(false);
} }
@@ -123,93 +133,108 @@ export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack_NoPageCa
export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack_WithPageCaching() { export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack_WithPageCaching() {
testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack(true); testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack(true);
} }
*/
//function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack(enablePageCache: boolean) {
//var i: number;
//var itemCount = 3;
//var loadedItems = [0, 0, 0];
//var unloadedItems = [0, 0, 0];
//var topFrame = frameModule.topmost(); function tabViewIsFullyLoaded(tabView: TabView): boolean {
//var oldChache; if (!tabView.isLoaded) {
return false;
}
//if (topFrame.android) { for (var i = 0; i < tabView.items.length; i++) {
//oldChache = topFrame.android.cachePagesOnNavigate; if (!tabView.items[i].view.isLoaded) {
//topFrame.android.cachePagesOnNavigate = enablePageCache; return false;
//} }
}
//try { if (tabView.android) {
//var tabView = _createTabView(); var viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
//var items = _createItems(itemCount); if (viewPager.getChildCount() === 0) {
//tabView.items = items; return false;
}
}
//function createLoadedFor(itemIndex: number) { return true;
//return function () { }
//loadedItems[itemIndex] = loadedItems[itemIndex] + 1;
//}
//}
//function createUnloadedFor(itemIndex: number) { function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack(enablePageCache: boolean) {
//return function () { var topFrame = frameModule.topmost();
//unloadedItems[itemIndex] = unloadedItems[itemIndex] + 1;
//}
//}
//helper.buildUIAndRunTest(tabView, function () { var oldChache;
//try { if (topFrame.android) {
//TKUnit.waitUntilReady(() => { return items[0].view.isLoaded; }, ASYNC); oldChache = topFrame.android.cachePagesOnNavigate;
topFrame.android.cachePagesOnNavigate = enablePageCache;
}
//// Attach to loaded/unloaded events var i: number;
//for (i = 0; i < itemCount; i++) { var itemCount = 2;
//items[i].view.on("loaded", createLoadedFor(i)); var loadedEventsCount = [0, 0];
//items[i].view.on("unloaded", createUnloadedFor(i)); var unloadedEventsCount = [0, 0];
//}
//var detailsPageFactory = function (): Page { var tabView = _createTabView();
//var detailsPage = new Page(); tabView.items = _createItems(itemCount);
//detailsPage.content = new Label();
//return detailsPage;
//};
//helper.navigate(detailsPageFactory); helper.navigate(() => {
//} var tabViewPage = new Page();
//finally { tabViewPage.id = "tab-view-page";
//// Go back to the test page. tabViewPage.content = tabView;
//helper.goBack(); return tabViewPage;
//} });
TKUnit.waitUntilReady(() => { return topFrame.currentPage.id === "tab-view-page" }, ASYNC);
TKUnit.waitUntilReady(() => { return tabViewIsFullyLoaded(tabView) }, ASYNC);
//TKUnit.waitUntilReady(() => { return items[0].view.isLoaded; }, ASYNC); function createLoadedFor(tabIndex: number) {
return function () {
loadedEventsCount[tabIndex] = loadedEventsCount[tabIndex] + 1;
}
}
////console.log(">>>>>>>>>>>>> loaded items: " + loadedItems.join(", ")); function createUnloadedFor(tabIndex: number) {
////console.log(">>>>>>>>>>>>> unloadedItems items: " + unloadedItems.join(", ")); return function () {
unloadedEventsCount[tabIndex] = unloadedEventsCount[tabIndex] + 1;
}
}
//// Check that at least the first item is loaded and unloaded for (i = 0; i < itemCount; i++) {
//TKUnit.assert(items[0].view.isLoaded, "The content of the first tab should be loaded."); tabView.items[i].view.on("loaded", createLoadedFor(i));
//TKUnit.assertEqual(loadedItems[0], 1, "loaded count for 1st item"); tabView.items[i].view.on("unloaded", createUnloadedFor(i));
//TKUnit.assertEqual(unloadedItems[0], 1, "unloaded count for 1st item"); }
//// Check that loaded/unloaded coutns are equal for all tabs helper.navigate(() => {
//for (i = 0; i < itemCount; i++) { var detailsPage = new Page();
//TKUnit.assert(loadedItems[i] === unloadedItems[i], detailsPage.id = "details-page";
//"Loaded and unloaded calls are not equal for item " + i + " loaded: " + loadedItems[i] + " unloaded: " + unloadedItems[i]); detailsPage.content = new Label();
//} return detailsPage;
//}); });
//} TKUnit.waitUntilReady(() => { return topFrame.currentPage.id === "details-page" }, ASYNC);
//finally {
//// Return original page cache value
//if (topFrame.android) {
//topFrame.android.cachePagesOnNavigate = oldChache;
//}
//}
//}
//function _clickTheFirstButtonInTheListViewNatively(tabView: TabView) { helper.goBack();
//if (tabView.android) { TKUnit.waitUntilReady(() => { return topFrame.currentPage.id === "tab-view-page" }, ASYNC);
//var viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager; TKUnit.waitUntilReady(() => { return tabViewIsFullyLoaded(tabView) }, ASYNC);
//var androidListView = <android.widget.ListView>viewPager.getChildAt(0);
//(<android.widget.Button>androidListView.getChildAt(0)).performClick(); for (i = 0; i < itemCount; i++) {
//} tabView.items[i].view.off("loaded");
//else { tabView.items[i].view.off("unloaded");
//(<UIButton>(<UITableView>tabView.ios.viewControllers[0].view.subviews[0]).cellForRowAtIndexPath(NSIndexPath.indexPathForItemInSection(0, 0)).contentView.subviews[0]).sendActionsForControlEvents(UIControlEvents.UIControlEventTouchUpInside); }
//}
//} helper.goBack();
TKUnit.waitUntilReady(() => { return topFrame.currentPage.id === "mainPage" }, ASYNC);
if (topFrame.android) {
topFrame.android.cachePagesOnNavigate = oldChache;
}
TKUnit.arrayAssert(loadedEventsCount, [1, 1]);
TKUnit.arrayAssert(unloadedEventsCount, [1, 1]);
}
function _clickTheFirstButtonInTheListViewNatively(tabView: TabView) {
if (tabView.android) {
var viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
var androidListView = <android.widget.ListView>viewPager.getChildAt(0);
var stackLayout = <org.nativescript.widgets.StackLayout>androidListView.getChildAt(0);
var button = <android.widget.Button>stackLayout.getChildAt(0);
button.performClick();
}
else {
(<UIButton>(<UITableView>tabView.ios.viewControllers[0].view.subviews[0]).cellForRowAtIndexPath(NSIndexPath.indexPathForItemInSection(0, 0)).contentView.subviews[0]).sendActionsForControlEvents(UIControlEvents.UIControlEventTouchUpInside);
}
}