|
1 | 1 | import * as TKUnit from "../TKUnit";
|
2 | 2 | import { EventData, Page, NavigatedData } from "tns-core-modules/ui/page";
|
3 | 3 | import { topmost as topmostFrame, NavigationTransition } from "tns-core-modules/ui/frame";
|
| 4 | +import { StackLayout, } from "tns-core-modules/ui/layouts/stack-layout"; |
| 5 | +import { GridLayout, } from "tns-core-modules/ui/layouts/grid-layout"; |
4 | 6 | import { Color } from "tns-core-modules/color";
|
5 | 7 | import * as helper from "../ui/helper";
|
6 |
| - |
| 8 | +import * as frame from "tns-core-modules/ui/frame"; |
7 | 9 | // Creates a random colorful page full of meaningless stuff.
|
8 | 10 | let id = 0;
|
9 | 11 | let pageFactory = function (): Page {
|
@@ -51,6 +53,65 @@ export function test_backstackVisible_WithTransition() {
|
51 | 53 | _test_backstackVisible({ name: "fade", duration: 10 });
|
52 | 54 | }
|
53 | 55 |
|
| 56 | +export function test_backAndForwardParentPage_nestedFrames() { |
| 57 | + const topmost = topmostFrame(); |
| 58 | + const mainTestPage = topmost.currentPage; |
| 59 | + let innerFrame; |
| 60 | + |
| 61 | + const page = (title) => { |
| 62 | + const p = new Page(); |
| 63 | + p["tag"] = title; |
| 64 | + return p; |
| 65 | + }; |
| 66 | + |
| 67 | + const parentPage = (title, innerPage) => { |
| 68 | + const parentPage = new Page(); |
| 69 | + parentPage["tag"] = title; |
| 70 | + |
| 71 | + const stack = new StackLayout(); |
| 72 | + innerFrame = new frame.Frame(); |
| 73 | + innerFrame.navigate({ create: () => innerPage }); |
| 74 | + stack.addChild(innerFrame); |
| 75 | + parentPage.content = stack; |
| 76 | + |
| 77 | + return parentPage; |
| 78 | + } |
| 79 | + |
| 80 | + const back = pages => topmostFrame().goBack(topmostFrame().backStack[topmostFrame().backStack.length - pages]); |
| 81 | + const currentPageMustBe = tag => TKUnit.assertEqual(topmostFrame().currentPage["tag"], tag, "Expected current page to be " + tag + " it was " + topmostFrame().currentPage["tag"] + " instead."); |
| 82 | + |
| 83 | + let parentPage1, parentPage2, innerPage1, innerPage2; |
| 84 | + innerPage1 = page("InnerPage1"); |
| 85 | + innerPage2 = page("InnerPage2"); |
| 86 | + parentPage1 = page("ParentPage1"); |
| 87 | + parentPage2 = parentPage("ParentPage2", innerPage1); |
| 88 | + |
| 89 | + helper.waitUntilNavigatedTo(parentPage1, () => topmost.navigate({ create: () => parentPage1 })); |
| 90 | + currentPageMustBe("ParentPage1"); |
| 91 | + |
| 92 | + helper.waitUntilNavigatedTo(parentPage2, () => topmost.navigate({ create: () => parentPage2 })); |
| 93 | + currentPageMustBe("ParentPage2"); |
| 94 | + |
| 95 | + helper.waitUntilNavigatedTo(innerPage2, () => innerFrame.navigate({ create: () => innerPage2 })); |
| 96 | + currentPageMustBe("InnerPage2"); |
| 97 | + |
| 98 | + helper.waitUntilNavigatedTo(innerPage1, () => frame.goBack()); |
| 99 | + currentPageMustBe("InnerPage1"); |
| 100 | + |
| 101 | + helper.waitUntilNavigatedTo(parentPage1, () => frame.goBack()); |
| 102 | + currentPageMustBe("ParentPage1"); |
| 103 | + |
| 104 | + helper.waitUntilNavigatedTo(parentPage2, () => topmost.navigate({ create: () => parentPage2 })); |
| 105 | + currentPageMustBe("ParentPage2"); |
| 106 | + |
| 107 | + back(2); |
| 108 | + TKUnit.waitUntilReady(() => topmostFrame().navigationQueueIsEmpty()); |
| 109 | + |
| 110 | + const frameStack = frame.stack(); |
| 111 | + TKUnit.assertEqual(frameStack.length, 1, "There should be only one frame left in the stack"); |
| 112 | + TKUnit.assertEqual(topmostFrame().currentPage, mainTestPage, "We should be on the main test page at the end of the test."); |
| 113 | +} |
| 114 | + |
54 | 115 | function _test_backToEntry(transition?: NavigationTransition) {
|
55 | 116 | const topmost = topmostFrame();
|
56 | 117 | const page = (tag) => () => {
|
@@ -362,10 +423,10 @@ function _test_NavigationEvents_WithClearHistory(transition?: NavigationTransiti
|
362 | 423 | // Go to second page
|
363 | 424 | helper.navigateWithEntry({ create: secondPageFactory, transition: transition, animated: !!transition, clearHistory: true });
|
364 | 425 |
|
365 |
| - const expectedMainPageEvents = [ "main-page navigatingFrom forward", "main-page navigatedFrom forward" ]; |
| 426 | + const expectedMainPageEvents = ["main-page navigatingFrom forward", "main-page navigatedFrom forward"]; |
366 | 427 | TKUnit.arrayAssert(actualMainPageEvents, expectedMainPageEvents, "Actual main-page events are different from expected.");
|
367 | 428 |
|
368 |
| - const expectedSecondPageEvents = [ "second-page navigatingTo forward", "second-page navigatedTo forward" ]; |
| 429 | + const expectedSecondPageEvents = ["second-page navigatingTo forward", "second-page navigatedTo forward"]; |
369 | 430 | TKUnit.arrayAssert(actualSecondPageEvents, expectedSecondPageEvents, "Actual main-page events are different from expected.");
|
370 | 431 |
|
371 | 432 | TKUnit.assertEqual(topmost.currentPage, secondPage, "We should be on the second page at the end of the test.");
|
@@ -393,7 +454,7 @@ function _test_Navigate_From_Page_Event_Handler(eventName: string) {
|
393 | 454 | const firstPageFactory = function (): Page {
|
394 | 455 | const firstPage = new Page();
|
395 | 456 | firstPage.id = "first-page";
|
396 |
| - firstPage.on(eventName, (args: EventData) => { |
| 457 | + firstPage.on(eventName, (args: EventData) => { |
397 | 458 | const page = <Page>args.object;
|
398 | 459 | const frame = page.frame;
|
399 | 460 |
|
|
0 commit comments