1
1
//make sure you import mocha-config before @angular/core
2
2
import { assert } from "./test-config" ;
3
- import { bootstrap } from "nativescript-angular/application" ;
4
- import { Component } from "@angular/core" ;
5
3
import { View } from "ui/core/view" ;
6
4
import { ViewUtil } from "nativescript-angular/view-util" ;
7
5
import { NgView , ViewExtensions , ViewClassMeta } from "nativescript-angular/element-registry" ;
8
6
import { Red } from "color/known-colors" ;
9
- import { device , Device , platformNames } from "platform" ;
7
+ import { device , platformNames } from "platform" ;
10
8
import { createDevice } from "./test-utils" ;
11
9
12
10
class TestView extends View implements ViewExtensions {
13
11
public nodeName : string = "TestView" ;
14
12
public templateParent : NgView = null ;
15
13
public meta : ViewClassMeta = { skipAddToDom : false } ;
16
- public cssClasses : Map < string , boolean > = new Map < string , boolean > ( ) ;
14
+ public ngCssClasses : Map < string , boolean > = new Map < string , boolean > ( ) ;
17
15
18
16
public stringValue : string = "" ;
19
17
public numValue : number = 0 ;
@@ -26,91 +24,91 @@ const iosDevice = createDevice(platformNames.ios);
26
24
const androidDevice = createDevice ( platformNames . android ) ;
27
25
28
26
describe ( 'setting View properties' , ( ) => {
29
- var viewUtil : ViewUtil ;
27
+ let viewUtil : ViewUtil ;
30
28
before ( ( ) => {
31
29
viewUtil = new ViewUtil ( device ) ;
32
- } )
30
+ } ) ;
33
31
34
32
it ( 'preserves string values' , ( ) => {
35
33
let view = new TestView ( ) ;
36
- viewUtil . setProperty ( view , "stringValue" , "blah" )
34
+ viewUtil . setProperty ( view , "stringValue" , "blah" ) ;
37
35
assert . equal ( "blah" , view . stringValue ) ;
38
36
} ) ;
39
37
40
38
it ( 'converts number values' , ( ) => {
41
39
let view = new TestView ( ) ;
42
- viewUtil . setProperty ( view , "numValue" , "42" )
40
+ viewUtil . setProperty ( view , "numValue" , "42" ) ;
43
41
assert . strictEqual ( 42 , view . numValue ) ;
44
- viewUtil . setProperty ( view , "numValue" , 0 )
42
+ viewUtil . setProperty ( view , "numValue" , 0 ) ;
45
43
assert . strictEqual ( 0 , view . numValue ) ;
46
44
} ) ;
47
45
48
46
it ( 'converts boolean values' , ( ) => {
49
47
let view = new TestView ( ) ;
50
- viewUtil . setProperty ( view , "boolValue" , "true" )
48
+ viewUtil . setProperty ( view , "boolValue" , "true" ) ;
51
49
assert . strictEqual ( true , view . boolValue ) ;
52
- viewUtil . setProperty ( view , "boolValue" , "false" )
50
+ viewUtil . setProperty ( view , "boolValue" , "false" ) ;
53
51
assert . strictEqual ( false , view . boolValue ) ;
54
52
} ) ;
55
53
56
54
it ( 'sets style values' , ( ) => {
57
55
let view = new TestView ( ) ;
58
- viewUtil . setProperty ( view , "style" , "color: red" )
56
+ viewUtil . setProperty ( view , "style" , "color: red" ) ;
59
57
assert . equal ( Red , view . style . color . hex ) ;
60
58
} ) ;
61
59
62
60
it ( 'doesn\'t convert blank strings' , ( ) => {
63
61
let view = new TestView ( ) ;
64
- viewUtil . setProperty ( view , "stringValue" , "" )
62
+ viewUtil . setProperty ( view , "stringValue" , "" ) ;
65
63
assert . strictEqual ( "" , view . stringValue ) ;
66
64
} ) ;
67
65
68
66
it ( 'doesn\'t convert booleans' , ( ) => {
69
67
let view = new TestView ( ) ;
70
- viewUtil . setProperty ( view , "boolValue" , true )
68
+ viewUtil . setProperty ( view , "boolValue" , true ) ;
71
69
assert . strictEqual ( true , view . boolValue ) ;
72
- viewUtil . setProperty ( view , "boolValue" , false )
70
+ viewUtil . setProperty ( view , "boolValue" , false ) ;
73
71
assert . strictEqual ( false , view . boolValue ) ;
74
72
} ) ;
75
73
76
74
it ( 'preserves objects' , ( ) => {
77
75
let value = { name : "Jim" , age : 23 } ;
78
76
let view = new TestView ( ) ;
79
- viewUtil . setProperty ( view , "anyValue" , value )
77
+ viewUtil . setProperty ( view , "anyValue" , value ) ;
80
78
assert . deepEqual ( value , view . anyValue ) ;
81
79
} ) ;
82
80
83
81
it ( 'sets nested properties' , ( ) => {
84
82
let view = new TestView ( ) ;
85
- viewUtil . setProperty ( view , "nested.property" , "blah" )
83
+ viewUtil . setProperty ( view , "nested.property" , "blah" ) ;
86
84
assert . strictEqual ( "blah" , view . nested . property ) ;
87
85
} ) ;
88
86
89
87
it ( 'sets ios property in ios' , ( ) => {
90
88
let view = new TestView ( ) ;
91
89
let testUtil = new ViewUtil ( iosDevice ) ;
92
- testUtil . setProperty ( view , "@ios:anyValue" , "blah" )
90
+ testUtil . setProperty ( view , "@ios:anyValue" , "blah" ) ;
93
91
assert . strictEqual ( "blah" , view . anyValue ) ;
94
92
} ) ;
95
93
96
94
it ( 'doesn\'t set android property in ios' , ( ) => {
97
95
let view = new TestView ( ) ;
98
96
let testUtil = new ViewUtil ( iosDevice ) ;
99
- testUtil . setProperty ( view , "@android:anyValue" , "blah" )
97
+ testUtil . setProperty ( view , "@android:anyValue" , "blah" ) ;
100
98
assert . isUndefined ( view . anyValue ) ;
101
99
} ) ;
102
100
103
101
it ( 'sets android property in android' , ( ) => {
104
102
let view = new TestView ( ) ;
105
103
let testUtil = new ViewUtil ( androidDevice ) ;
106
- testUtil . setProperty ( view , "@android:anyValue" , "blah" )
104
+ testUtil . setProperty ( view , "@android:anyValue" , "blah" ) ;
107
105
assert . strictEqual ( "blah" , view . anyValue ) ;
108
106
} ) ;
109
107
110
108
it ( 'doesn\'t set ios property in android' , ( ) => {
111
109
let view = new TestView ( ) ;
112
110
let testUtil = new ViewUtil ( androidDevice ) ;
113
- testUtil . setProperty ( view , "@ios:anyValue" , "blah" )
111
+ testUtil . setProperty ( view , "@ios:anyValue" , "blah" ) ;
114
112
assert . isUndefined ( view . anyValue ) ;
115
113
} ) ;
116
114
} ) ;
0 commit comments