1
+ describe ( "formlyMaterial - label wrapper" , ( ) => {
2
+
3
+ //
4
+ // vars
5
+ //
6
+ let formlyConfig ;
7
+ let $compile ;
8
+ let $rootScope ;
9
+ let $scope ;
10
+ let element ;
11
+ let field ;
12
+
13
+ //
14
+ // helpers
15
+ //
16
+
17
+ function compile ( ) {
18
+ $scope = $rootScope . $new ( ) ;
19
+ $scope . fields = [ {
20
+ key : 'testField' ,
21
+ type : 'checkbox' ,
22
+ wrapper : [ 'label' ] ,
23
+ templateOptions : {
24
+ label : 'test field'
25
+ }
26
+ } ] ;
27
+
28
+ let form = $compile ( testUtils . formTemplate ) ( $scope ) ;
29
+ $scope . $digest ( ) ;
30
+ element = form . find ( 'label' ) ;
31
+ field = $scope . fields [ 0 ] ;
32
+ }
33
+
34
+ //
35
+ // tests
36
+ //
37
+
38
+ beforeEach ( ( ) => {
39
+ angular . module ( 'testApp' , [ 'angular-meteor' , 'formly' , 'formlyMaterial' ] ) ;
40
+ module ( 'testApp' ) ;
41
+
42
+ inject ( ( _$compile_ , _$rootScope_ , _formlyConfig_ ) => {
43
+ $compile = _$compile_ ;
44
+ $rootScope = _$rootScope_ ;
45
+ formlyConfig = _formlyConfig_ ;
46
+ } ) ;
47
+
48
+ const types = [ 'checkbox' ] ;
49
+ const wrappers = [ 'label' ] ;
50
+
51
+ types . forEach ( ( name ) => {
52
+ testUtils . fixTypeTemplateUrl ( formlyConfig , name ) ;
53
+ } ) ;
54
+ wrappers . forEach ( ( name ) => {
55
+ testUtils . fixWrapperTemplateUrl ( formlyConfig , name ) ;
56
+ } ) ;
57
+
58
+ compile ( ) ;
59
+ } ) ;
60
+
61
+ it ( 'should exist' , ( ) => {
62
+ expect ( element . length ) . toBe ( 1 ) ;
63
+ } ) ;
64
+
65
+ it ( 'should have proper value' , ( ) => {
66
+ expect ( element [ 0 ] . innerText ) . toContain ( field . templateOptions . label ) ;
67
+ } ) ;
68
+
69
+ it ( "should be before the field" , ( ) => {
70
+ expect ( element . find ( 'md-checkbox' ) . length ) . toBe ( 0 ) ;
71
+ expect ( element . next ( ) . children ( ) [ 0 ] . nodeName ) . toBe ( 'MD-CHECKBOX' ) ;
72
+ } ) ;
73
+
74
+ } ) ;
0 commit comments