1- import page = require ( "ui/page" ) ;
2- import layout = require ( "ui/layouts/stack-layout" ) ;
3- import button = require ( "ui/button" ) ;
1+ import { Page } from "ui/page" ;
2+ import { StackLayout } from "ui/layouts/stack-layout" ;
3+ import { Button } from "ui/button" ;
44import TKUnit = require( "../TKUnit" ) ;
55import helper = require( "./layout-helper" ) ;
66import navHelper = require( "../ui/helper" ) ;
@@ -9,7 +9,7 @@ import utils = require("utils/utils");
99
1010var ASYNC = 2 ;
1111
12- export class MyStackLayout extends layout . StackLayout {
12+ export class MyStackLayout extends StackLayout {
1313 public measureCount : number = 0 ;
1414 public arrangeCount : number = 0 ;
1515
@@ -32,16 +32,16 @@ export class MyStackLayout extends layout.StackLayout {
3232 }
3333}
3434
35- var tmp : button . Button ;
36- var newPage : page . Page ;
35+ var tmp : Button ;
36+ var newPage : Page ;
3737var rootLayout : MyStackLayout ;
3838var btn1 : helper . MyButton ;
3939var btn2 : helper . MyButton ;
4040
4141export function setUpModule ( ) {
4242 var pageFactory = function ( ) {
43- newPage = new page . Page ( ) ;
44- tmp = new button . Button ( ) ;
43+ newPage = new Page ( ) ;
44+ tmp = new Button ( ) ;
4545 tmp . text = "Loading test" ;
4646 newPage . content = tmp ;
4747 return newPage ;
@@ -65,7 +65,7 @@ export function setUp() {
6565 btn1 . text = "btn1" ;
6666 rootLayout . addChild ( btn1 ) ;
6767 btn2 = new helper . MyButton ( ) ;
68- btn2 . text = "btn 2 " ;
68+ btn2 . text = "btn2 " ;
6969 rootLayout . addChild ( btn2 ) ;
7070 newPage . content = rootLayout ;
7171}
@@ -206,11 +206,37 @@ export function test_StackLayout_Padding_Horizontal() {
206206 helper . assertLayout ( btn2 , 60 , 20 , 50 , 240 , "btn2" ) ;
207207}
208208
209+ function assertChildTexts ( expected , layout , message ) {
210+ let texts : Array < string > = [ ] ;
211+ layout . _eachChildView ( ( child : { text : string } ) => texts . push ( child . text ) ) ;
212+ TKUnit . assertEqual ( expected , texts . join ( '|' ) , message ) ;
213+ }
214+
215+ export function test_insertChildAtPosition ( ) {
216+ assertChildTexts ( "btn1|btn2" , rootLayout , "initial 2 buttons" ) ;
217+
218+ let newChild = new Button ( ) ;
219+ newChild . text = 'in-between' ;
220+ rootLayout . insertChild ( 1 , newChild ) ;
221+
222+ assertChildTexts ( "btn1|in-between|btn2" , rootLayout , "button inserted at correct location" ) ;
223+ }
224+
225+ export function test_getChildIndex ( ) {
226+ let lastChildIndex = rootLayout . getChildrenCount ( ) - 1 ;
227+ let lastButton = < Button > rootLayout . getChildAt ( lastChildIndex ) ;
228+ TKUnit . assertEqual ( "btn2" , lastButton . text ) ;
229+ TKUnit . assertEqual ( lastChildIndex , rootLayout . getChildIndex ( lastButton ) ) ;
230+
231+ let nonChild = new Button ( ) ;
232+ TKUnit . assertEqual ( - 1 , rootLayout . getChildIndex ( nonChild ) ) ;
233+ }
234+
209235export function test_codesnippets ( ) {
210236 // <snippet module="ui/layouts/stack-layout" title="stack-layout">
211237 // ### Create StackLayout
212238 // ``` JavaScript
213- var stackLayout = new layout . StackLayout ( ) ;
239+ var stackLayout = new StackLayout ( ) ;
214240 // ```
215241
216242 // ### Declaring a StackLayout.
@@ -225,7 +251,7 @@ export function test_codesnippets() {
225251
226252 // ### Add child view to layout
227253 // ``` JavaScript
228- var btn = new button . Button ( ) ;
254+ var btn = new Button ( ) ;
229255 stackLayout . addChild ( btn ) ;
230256 // ```
231257
@@ -240,4 +266,4 @@ export function test_codesnippets() {
240266 // ```
241267
242268 // </snippet>
243- } ;
269+ } ;
0 commit comments