@@ -2,74 +2,86 @@ import testUtils from './../test-utils';
2
2
3
3
describe ( "formlyMaterial - chips type" , ( ) => {
4
4
5
- //
6
- // vars
7
- //
8
- let formlyConfig ;
9
- let $compile ;
10
- let $rootScope ;
11
- let $scope ;
12
- let element ;
13
- let field ;
14
- //
15
- // helpers
16
- //
17
-
18
- function compile ( options ) {
19
- $scope = $rootScope . $new ( ) ;
20
- $scope . fields = [ angular . merge ( { } , {
21
- key : 'testField' ,
22
- type : 'chips' ,
23
- templateOptions : {
24
- label : 'test field' ,
25
- placeholder : "+tags" ,
26
- secondaryPlaceholder : "Add tag" ,
27
- deleteButtonLabel : "Remove" ,
28
- deleteHint : "Remove tag"
29
- }
30
- } , options ) ] ;
31
-
32
- let form = $compile ( testUtils . getFormTemplate ( ) ) ( $scope ) ;
33
-
34
- $scope . $digest ( ) ;
35
- field = $scope . fields [ 0 ] ;
36
- element = form . find ( '[ng-model]' ) ;
37
- }
38
-
39
- //
40
- // tests
41
- //
42
-
43
- beforeEach ( ( ) => {
44
- window . module ( 'formlyMaterial' ) ;
45
-
46
- inject ( ( _$compile_ , _$rootScope_ , _formlyConfig_ ) => {
47
- $compile = _$compile_ ;
48
- $rootScope = _$rootScope_ ;
49
- formlyConfig = _formlyConfig_ ;
50
- } ) ;
51
-
52
- compile ( ) ;
53
- } ) ;
5
+ //
6
+ // vars
7
+ //
8
+ let formlyConfig ;
9
+ let $compile ;
10
+ let $rootScope ;
11
+ let $scope ;
12
+ let element ;
13
+ let field ;
54
14
55
- it ( 'should be md-chips element' , ( ) => {
56
- expect ( element [ 0 ] . nodeName ) . toBe ( 'MD-CHIPS' ) ;
57
- } ) ;
15
+ function onAdd ( ) {
16
+ return true ;
17
+ }
18
+ //
19
+ // helpers
20
+ //
58
21
59
- it ( 'should have placeholder' , ( ) => {
60
- expect ( element . attr ( 'placeholder' ) ) . toBe ( field . templateOptions . placeholder ) ;
61
- } ) ;
22
+ function compile ( options ) {
23
+ $scope = $rootScope . $new ( ) ;
24
+ $scope . fields = [ angular . merge ( { } , {
25
+ key : 'testField' ,
26
+ type : 'chips' ,
27
+ templateOptions : {
28
+ label : 'test field' ,
29
+ placeholder : "+tags" ,
30
+ secondaryPlaceholder : "Add tag" ,
31
+ deleteButtonLabel : "Remove" ,
32
+ deleteHint : "Remove tag" ,
33
+ onAdd : onAdd
34
+ }
35
+ } , options ) ] ;
62
36
63
- it ( 'should have secondary placeholder' , ( ) => {
64
- expect ( element . attr ( 'secondary-placeholder' ) ) . toBe ( field . templateOptions . secondaryPlaceholder ) ;
65
- } ) ;
37
+ let form = $compile ( testUtils . getFormTemplate ( ) ) ( $scope ) ;
66
38
67
- it ( 'should have delete button label' , ( ) => {
68
- expect ( element . attr ( 'delete-button-label' ) ) . toBe ( field . templateOptions . deleteButtonLabel ) ;
69
- } ) ;
39
+ $scope . $digest ( ) ;
40
+ field = $scope . fields [ 0 ] ;
41
+ element = form . find ( '[ng-model]' ) ;
42
+ }
43
+
44
+ //
45
+ // tests
46
+ //
70
47
71
- it ( 'should have delete hint' , ( ) => {
72
- expect ( element . attr ( 'delete-hint' ) ) . toBe ( field . templateOptions . deleteHint ) ;
48
+ beforeEach ( ( ) => {
49
+ window . module ( 'formlyMaterial' ) ;
50
+
51
+ inject ( ( _$compile_ , _$rootScope_ , _formlyConfig_ ) => {
52
+ $compile = _$compile_ ;
53
+ $rootScope = _$rootScope_ ;
54
+ formlyConfig = _formlyConfig_ ;
73
55
} ) ;
74
56
75
- } ) ;
57
+ compile ( ) ;
58
+ } ) ;
59
+
60
+ it ( 'should be md-chips element' , ( ) => {
61
+ expect ( element [ 0 ] . nodeName ) . toBe ( 'MD-CHIPS' ) ;
62
+ } ) ;
63
+
64
+ it ( 'should have placeholder' , ( ) => {
65
+ expect ( element . attr ( 'placeholder' ) ) . toBe ( field . templateOptions . placeholder ) ;
66
+ } ) ;
67
+
68
+ it ( 'should have secondary placeholder' , ( ) => {
69
+ expect ( element . attr ( 'secondary-placeholder' ) ) . toBe ( field . templateOptions . secondaryPlaceholder ) ;
70
+ } ) ;
71
+
72
+ it ( 'should have delete button label' , ( ) => {
73
+ expect ( element . attr ( 'delete-button-label' ) ) . toBe ( field . templateOptions . deleteButtonLabel ) ;
74
+ } ) ;
75
+
76
+ it ( 'should have delete hint' , ( ) => {
77
+ expect ( element . attr ( 'delete-hint' ) ) . toBe ( field . templateOptions . deleteHint ) ;
78
+ } ) ;
79
+
80
+ it ( 'should have onAdd callback' , ( ) => {
81
+ const scope = angular . element ( element ) . scope ( ) ;
82
+
83
+ expect ( element . attr ( 'md-on-add' ) ) . toBe ( "options.templateOptions['onAdd']" ) ;
84
+ expect ( scope . options . templateOptions . onAdd ) . toBe ( onAdd ) ;
85
+ } ) ;
86
+
87
+ } ) ;
0 commit comments