11import * as TKUnit from "../../TKUnit" ;
22// >> article-creating-view
3- import * as platform from "tns-core-modules/platform" ;
4- //var utils = require("utils/utils");
3+ import { isIOS , isAndroid } from "tns-core-modules/platform" ;
54import * as utils from "tns-core-modules/utils/utils" ;
65import * as helper from "../helper" ;
76import * as viewModule from "tns-core-modules/ui/core/view" ;
@@ -11,56 +10,57 @@ import * as placeholderModule from "tns-core-modules/ui/placeholder";
1110// << article-require-placeholder-module
1211
1312function creatingView ( args ) {
14- var nativeView ;
15- if ( platform . device . os === platform . platformNames . ios ) {
16- nativeView = UITextView . new ( ) ;
17- nativeView . text = "Native" ;
18- } else if ( platform . device . os === platform . platformNames . android ) {
19- nativeView = new android . widget . TextView ( utils . ad . getApplicationContext ( ) ) ;
20- nativeView . setText ( "Native" ) ;
21- }
13+ let nativeView ;
14+ if ( isIOS ) {
15+ nativeView = UITextView . new ( ) ;
16+ nativeView . text = "Native" ;
17+ } else if ( isAndroid ) {
18+ nativeView = new android . widget . TextView ( utils . ad . getApplicationContext ( ) ) ;
19+ nativeView . setText ( "Native" ) ;
20+ }
2221
23- args . view = nativeView ;
22+ args . view = nativeView ;
2423}
2524
2625exports . creatingView = creatingView ;
2726// << article-creating-view
2827
2928export function test_placeholder_creatingView ( ) {
30- var nativeView ;
31-
32- var p = new placeholderModule . Placeholder ( ) ;
33- p . id = "test" ;
29+ const p = new placeholderModule . Placeholder ( ) ;
3430 p . on ( placeholderModule . Placeholder . creatingViewEvent , ( args : placeholderModule . CreateViewEventData ) => {
35- if ( platform . device . os === platform . platformNames . ios ) {
36- nativeView = UITextView . new ( ) ;
31+ let nativeView ;
32+ if ( isIOS ) {
33+ nativeView = UITextView . new ( ) ;
3734 nativeView . text = "Native" ;
38- } else if ( platform . device . os === platform . platformNames . android ) {
35+ } else if ( isAndroid ) {
3936 nativeView = new android . widget . TextView ( utils . ad . getApplicationContext ( ) ) ;
4037 nativeView . setText ( "Native" ) ;
4138 }
42-
39+
4340 args . view = nativeView ;
4441 } ) ;
4542
46- if ( platform . device . os === platform . platformNames . ios ) {
47- TKUnit . assert ( p . ios instanceof UITextView , "ios property should be UITextView. Current value: " + p . ios ) ;
48- } else if ( platform . device . os === platform . platformNames . android ) {
49- p . _emit ( "creatingView" ) ;
50- TKUnit . assert ( nativeView instanceof android . widget . TextView , "Native view should be android.widget.TextView. Current value: " + nativeView ) ;
51- }
43+ function testAction ( views : Array < viewModule . View > ) {
44+ if ( isIOS ) {
45+ TKUnit . assert ( p . nativeView instanceof UITextView , "nativeView property should be UITextView. Current value: " + p . nativeView ) ;
46+ } else if ( isAndroid ) {
47+ TKUnit . assert ( p . nativeView instanceof android . widget . TextView , "Native view should be android.widget.TextView. Current value: " + p . nativeView ) ;
48+ }
49+ } ;
50+
51+ helper . buildUIAndRunTest ( p , testAction ) ;
5252}
5353
5454export function test_placeholder_will_not_crash_wihout_creatingView ( ) {
55- var p = new placeholderModule . Placeholder ( ) ;
55+ const p = new placeholderModule . Placeholder ( ) ;
5656
5757 function testAction ( views : Array < viewModule . View > ) {
58- if ( platform . device . os === platform . platformNames . ios ) {
58+ if ( isIOS ) {
5959 TKUnit . assert ( p . ios === undefined , "ios property should be undefined. Current value: " + p . ios ) ;
60- } else if ( platform . device . os === platform . platformNames . android ) {
60+ } else if ( isAndroid ) {
6161 TKUnit . assert ( p . android === undefined , "android view should be undefined. Current value: " + p . android ) ;
6262 }
6363 } ;
6464
6565 helper . buildUIAndRunTest ( p , testAction ) ;
66- }
66+ }
0 commit comments