@@ -23,6 +23,7 @@ import { Frame, stack } from "tns-core-modules/ui/frame";
2323import { Label } from "tns-core-modules/ui/label" ;
2424import { Color } from "tns-core-modules/color" ;
2525import { TabView , TabViewItem } from "tns-core-modules/ui/tab-view/tab-view" ;
26+ import { _resetRootView , getRootView } from "tns-core-modules/application" ;
2627
2728export function addLabelToPage ( page : Page , text ?: string ) {
2829 const label = new Label ( ) ;
@@ -874,6 +875,71 @@ export function test_WhenModalPageShownShowModalEventsRaisedOnRootModalPage() {
874875 TKUnit . assertTrue ( shownModallyCount === 1 ) ;
875876}
876877
878+ export function test_WhenModalPageShownShowModalEventsRaisedOnRootModalTabView ( ) {
879+ let showingModallyCount = 0 ;
880+ let shownModallyCount = 0 ;
881+
882+ let ready = false ;
883+
884+ const modalCloseCallback = function ( returnValue : any ) {
885+ TKUnit . assertEqual ( stack ( ) . length , 1 , "Single host frame should be instantiated at this point!" ) ;
886+
887+ ready = true ;
888+ }
889+
890+ const modalTabViewShowingModallyEventHandler = function ( args : ShownModallyData ) {
891+ showingModallyCount ++ ;
892+ }
893+
894+ const modalTabViewShownModallyEventHandler = function ( args : ShownModallyData ) {
895+ shownModallyCount ++ ;
896+ }
897+
898+ const hostNavigatedToEventHandler = function ( args ) {
899+ const page = < Page > args . object ;
900+ page . off ( Page . navigatedToEvent , hostNavigatedToEventHandler ) ;
901+
902+ const basePath = "ui/page/" ;
903+ const entry : NavigationEntry = {
904+ moduleName : basePath + "modal-tab-root"
905+ } ;
906+
907+ TKUnit . assertEqual ( stack ( ) . length , 1 , "Single host frame should be instantiated at this point!" ) ;
908+
909+ const modalTabView = createViewFromEntry ( entry ) as TabView ;
910+ modalTabView . on ( TabView . showingModallyEvent , modalTabViewShowingModallyEventHandler ) ;
911+ modalTabView . on ( TabView . shownModallyEvent , modalTabViewShownModallyEventHandler ) ;
912+
913+ TKUnit . assertEqual ( stack ( ) . length , 2 , "Host and tab modal frame should be instantiated at this point!" ) ;
914+
915+ page . showModal ( modalTabView , { } , modalCloseCallback , false , false ) ;
916+ }
917+
918+ const masterPageFactory = function ( ) : Page {
919+ const masterPage = new Page ( ) ;
920+ masterPage . id = "masterPage_test_WhenModalPageShownShowModalEventsRaisedOnRootModalTabView" ;
921+ masterPage . on ( Page . navigatedToEvent , hostNavigatedToEventHandler ) ;
922+
923+ const label = new Label ( ) ;
924+ label . text = "Text" ;
925+ masterPage . content = label ;
926+ return masterPage ;
927+ } ;
928+
929+ TKUnit . assertEqual ( stack ( ) . length , 1 , "Single host frame should be instantiated at this point!" ) ;
930+
931+ helper . navigate ( masterPageFactory ) ;
932+
933+ TKUnit . assertEqual ( stack ( ) . length , 2 , "Host and modal tab frame should be instantiated at this point!" ) ;
934+
935+ TKUnit . waitUntilReady ( ( ) => ready ) ;
936+
937+ TKUnit . assertEqual ( stack ( ) . length , 1 , "Single host frame should be instantiated at this point!" ) ;
938+
939+ TKUnit . assertTrue ( showingModallyCount === 1 ) ;
940+ TKUnit . assertTrue ( shownModallyCount === 1 ) ;
941+ }
942+
877943export function test_percent_width_and_height_support ( ) {
878944 const testPage = new Page ( ) ;
879945 testPage . id = "test_percent_width_and_height_support" ;
@@ -935,40 +1001,3 @@ export function test_percent_margin_support() {
9351001 TKUnit . assertEqual ( bounds . right , parentWidth , "Stack RIGHT position incorrect" ) ;
9361002 TKUnit . assertEqual ( bounds . bottom , parentHeight , "Stack BOTTOM position incorrect" ) ;
9371003}
938-
939- //export function test_ModalPage_Layout_is_Correct() {
940- // const testPage: Page;
941- // const label: Label;
942- // const pageFactory = function () {
943- // testPage = new Page();
944- // label = new Label();
945- // label.text = "Will Show modal page";
946- // testPage.content = label;
947- // return testPage;
948- // };
949-
950- // helper.navigate(pageFactory);
951- // const basePath = "ui/page/";
952- // testPage.showModal(basePath + "page21", testPage, () => { }, false);
953-
954- // // TODO: Remove this once navigate and showModal returns Promise<Page>.
955- // TKUnit.wait(0.350);
956- // const childPage = (<any>testPage).childPage;
957- // const closeCallback: Function = (<any>testPage).close;
958-
959- // try {
960- // const layout = <StackLayout>childPage.content;
961- // const repeater = layout.getChildAt(1);
962- // TKUnit.assertTrue(repeater.isLayoutValid, "layout should be valid.");
963- // const bounds = repeater._getCurrentLayoutBounds();
964- // const height = bounds.bottom - bounds.top;
965- // TKUnit.assertTrue(height > 0, "Layout should be >0.");
966-
967- // closeCallback();
968- // TKUnit.wait(0.150);
969- // }
970- // finally {
971- // helper.goBack
972- // helper.goBack();
973- // }
974- //}
0 commit comments