Files
NativeScript/tests/app/ui/tabs/tabs-root-tests.ts
Alexander Vakrilov cc97a16800 feat: Scoped Packages (#7911)
* chore: move tns-core-modules to nativescript-core

* chore: preparing compat generate script

* chore: add missing definitions

* chore: no need for http-request to be private

* chore: packages chore

* test: generate tests for tns-core-modules

* chore: add anroid module for consistency

* chore: add .npmignore

* chore: added privateModulesWhitelist

* chore(webpack): added bundle-entry-points

* chore: scripts

* chore: tests changed to use @ns/core

* test: add scoped-packages test project

* test: fix types

* test: update test project

* chore: build scripts

* chore: update build script

* chore: npm scripts cleanup

* chore: make the compat pgk work with old wp config

* test: generate diff friendly tests

* chore: create barrel exports

* chore: move files after rebase

* chore: typedoc config

* chore: compat mode

* chore: review of barrels

* chore: remove tns-core-modules import after rebase

* chore: dev workflow setup

* chore: update developer-workflow

* docs: experiment with API extractor

* chore: api-extractor and barrel exports

* chore: api-extractor configs

* chore: generate d.ts rollup with api-extractor

* refactor: move methods inside Frame

* chore: fic tests to use Frame static methods

* refactor: create Builder class

* refactor: use Builder class in tests

* refactor: include Style in ui barrel

* chore: separate compat build script

* chore: fix tslint errors

* chore: update NATIVESCRIPT_CORE_ARGS

* chore: fix compat pack

* chore: fix ui-test-app build with linked modules

* chore: Application, ApplicationSettings, Connectivity and Http

* chore: export Trace, Profiling and Utils

* refactor: Static create methods for ImageSource

* chore: fix deprecated usages of ImageSource

* chore: move Span and FormattedString to ui

* chore: add events-args and ImageSource to index files

* chore: check for CLI >= 6.2 when building for IOS

* chore: update travis build

* chore: copy Pod file to compat package

* chore: update error msg ui-tests-app

* refactor: Apply suggestions from code review

Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com>

* chore: typings and refs

* chore: add missing d.ts files for public API

* chore: adress code review FB

* chore: update api-report

* chore: dev-workflow for other apps

* chore: api update

* chore: update api-report
2019-10-17 00:45:33 +03:00

198 lines
6.2 KiB
TypeScript

import * as TKUnit from "../../tk-unit";
import { _resetRootView } from "@nativescript/core/application/";
import { Frame, NavigationEntry, } from "@nativescript/core/ui/frame";
import { Page } from "@nativescript/core/ui/page";
import { Tabs, TabContentItem, TabStrip, TabStripItem } from "@nativescript/core/ui/tabs";
function waitUntilNavigatedToMaxTimeout(pages: Page[], action: Function) {
const maxTimeout = 8;
let completed = 0;
function navigatedTo(args) {
args.object.page.off("navigatedTo", navigatedTo);
completed++;
}
pages.forEach(page => page.on("navigatedTo", navigatedTo));
action();
TKUnit.waitUntilReady(() => completed === pages.length, maxTimeout);
}
function createPage(i: number) {
const page = new Page();
page.id = `Tab${i} Frame${i} Page${i}`;
return page;
}
function createFrame(i: number, page: Page) {
const frame = new Frame();
frame.navigate(() => page);
frame.id = `Tab${i} Frame${i}`;
return frame;
}
function createTabItem(i: number, frame: Frame) {
const tabEntry = new TabContentItem();
// tabEntry.title = "Tab " + i;
tabEntry.content = frame;
tabEntry["index"] = i;
return tabEntry;
}
function createTabItemsWithFrames(count: number) {
const items = [];
for (var i = 0; i < count; i++) {
const page = createPage(i);
const frame = createFrame(i, page);
const tabItem = createTabItem(i, frame);
items.push({ page, frame, tabItem });
}
return items;
}
function createTabStrip(count: number): TabStrip {
const items = new Array<TabStripItem>();
for (let i = 0; i < count; i++) {
let tabStripEntry = new TabStripItem();
tabStripEntry.title = "Tab " + i;
items.push(tabStripEntry);
}
const tabStrip = new TabStrip();
tabStrip.items = items;
return tabStrip;
}
export function test_frame_topmost_matches_selectedIndex() {
const items = createTabItemsWithFrames(3);
const tabView = new Tabs();
tabView.items = items.map(item => item.tabItem);
tabView.tabStrip = createTabStrip(3);
// 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
};
waitUntilNavigatedToMaxTimeout([items[0].page], () => _resetRootView(entry));
TKUnit.assertEqual(Frame.topmost().id, "Tab0 Frame0");
waitUntilNavigatedToMaxTimeout([items[1].page], () => tabView.selectedIndex = 1);
TKUnit.assertEqual(Frame.topmost().id, "Tab1 Frame1");
}
// TODO: _resetRootView doesn't work with TabView or Tabs with pre-loading. The fragments that are removed crash the app with missing reference.
// export function test_preloading_one_to_the_side_on_index_change() {
// let actualEventsRaised = [];
// function resetActualEventsRaised() {
// for (var i = 0; i < actualEventsRaised.length; i++) {
// actualEventsRaised[i] = [];
// }
// }
// function attachEventHandlers(i: number, item) {
// actualEventsRaised.push([]);
// const page = item.page;
// page.on(Page.loadedEvent, () => actualEventsRaised[i].push(`${page.id} loaded`));
// page.on(Page.unloadedEvent, () => actualEventsRaised[i].push(`${page.id} unloaded`));
// page.on(Page.navigatingToEvent, () => actualEventsRaised[i].push(`${page.id} navigatingTo`));
// page.on(Page.navigatingFromEvent, () => actualEventsRaised[i].push(`${page.id} navigatingFrom`));
// page.on(Page.navigatedToEvent, () => actualEventsRaised[i].push(`${page.id} navigatedTo`));
// page.on(Page.navigatedFromEvent, () => actualEventsRaised[i].push(`${page.id} navigatedFrom`));
// const frame = item.frame;
// frame.on(Frame.loadedEvent, () => actualEventsRaised[i].push(`${frame.id} loaded`));
// frame.on(Frame.unloadedEvent, () => actualEventsRaised[i].push(`${frame.id} unloaded`));
// }
// const items = createTabItemsWithFrames(3);
// items.forEach((item, i) => {
// attachEventHandlers(i, item);
// });
// const tabView = new Tabs();
// tabView.items = items.map(item => item.tabItem);
// tabView.tabStrip = createTabStrip(3);
// const entry: NavigationEntry = {
// create: () => tabView
// };
// waitUntilNavigatedToMaxTimeout([items[0].page], () => _resetRootView(entry));
// const expectedEventsRaisedAfterTabCreated = [
// [
// "Tab0 Frame0 loaded",
// "Tab0 Frame0 Page0 navigatingTo",
// "Tab0 Frame0 Page0 loaded",
// "Tab0 Frame0 Page0 navigatedTo",
// ],
// [],
// []
// ];
// TKUnit.assertDeepEqual(actualEventsRaised, expectedEventsRaisedAfterTabCreated);
// resetActualEventsRaised();
// waitUntilNavigatedToMaxTimeout([items[2].page], () => tabView.selectedIndex = 2);
// const expectedEventsRaisedAfterSelectThirdTab = [
// [
// "Tab0 Frame0 Page0 unloaded",
// "Tab0 Frame0 unloaded",
// ],
// [],
// [
// "Tab2 Frame2 loaded",
// "Tab2 Frame2 Page2 navigatingTo",
// "Tab2 Frame2 Page2 loaded",
// "Tab2 Frame2 Page2 navigatedTo"
// ]
// ];
// TKUnit.assertDeepEqual(actualEventsRaised, expectedEventsRaisedAfterSelectThirdTab);
// resetActualEventsRaised();
// waitUntilTabViewReady(items[0].page, () => tabView.selectedIndex = 0);
// const expectedEventsRaisedAfterReturnToFirstTab = [
// [
// "Tab0 Frame0 Page0 loaded",
// "Tab0 Frame0 loaded",
// ],
// [],
// [
// "Tab2 Frame2 Page2 unloaded",
// "Tab2 Frame2 unloaded",
// ]
// ];
// TKUnit.assertDeepEqual(actualEventsRaised, expectedEventsRaisedAfterReturnToFirstTab);
// }
export function tearDownModule() {
const page = new Page();
const frame = new Frame();
frame.navigate(() => page);
const entry: NavigationEntry = {
create: () => frame
};
waitUntilNavigatedToMaxTimeout([page], () => _resetRootView(entry));
}