@@ -44,30 +44,122 @@ describe('formlyMaterial - input type', () => {
44
44
$compile = _$compile_ ;
45
45
$rootScope = _$rootScope_ ;
46
46
} ) ;
47
-
48
- compile ( ) ;
49
47
} ) ;
50
48
51
- it ( 'should be input element' , ( ) => {
52
- expect ( element [ 0 ] . nodeName ) . toBe ( 'INPUT' ) ;
53
- } ) ;
49
+ describe ( 'basics' , ( ) => {
50
+ beforeEach ( ( ) => {
51
+ compile ( ) ;
52
+ } ) ;
54
53
55
- it ( 'should have proper type attribute ' , ( ) => {
56
- expect ( element . attr ( 'type' ) ) . toBe ( field . templateOptions . type ) ;
57
- } ) ;
54
+ it ( 'should be input element ' , ( ) => {
55
+ expect ( element [ 0 ] . nodeName ) . toBe ( 'INPUT' ) ;
56
+ } ) ;
58
57
59
- it ( 'should have messages wrapper ' , ( ) => {
60
- expect ( form . find ( '[ng-messages]' ) . length ) . toBe ( 1 ) ;
61
- } ) ;
58
+ it ( 'should have proper type attribute ' , ( ) => {
59
+ expect ( element . attr ( 'type' ) ) . toBe ( field . templateOptions . type ) ;
60
+ } ) ;
62
61
63
- it ( 'should have label wrapper' , ( ) => {
64
- const label = form . find ( 'label' ) ;
62
+ it ( 'should have messages wrapper' , ( ) => {
63
+ expect ( form . find ( '[ng-messages]' ) . length ) . toBe ( 1 ) ;
64
+ } ) ;
65
+
66
+ it ( 'should have label wrapper' , ( ) => {
67
+ const label = form . find ( 'label' ) ;
68
+
69
+ expect ( label . length ) . toBe ( 1 ) ;
70
+ expect ( label . html ( ) ) . toContain ( field . templateOptions . label ) ;
71
+ } ) ;
65
72
66
- expect ( label . length ) . toBe ( 1 ) ;
67
- expect ( label . html ( ) ) . toContain ( field . templateOptions . label ) ;
73
+ it ( 'should have inputContainer wrapper' , ( ) => {
74
+ expect ( form . find ( 'md-input-container' ) . length ) . toBe ( 1 ) ;
75
+ } ) ;
68
76
} ) ;
69
77
70
- it ( 'should have inputContainer wrapper' , ( ) => {
71
- expect ( form . find ( 'md-input-container' ) . length ) . toBe ( 1 ) ;
78
+ describe ( 'number type specific' , ( ) => {
79
+ describe ( 'step attribute' , ( ) => {
80
+ it ( 'should fail on non number type' , ( ) => {
81
+ expect ( ( ) => {
82
+ compile ( {
83
+ templateOptions : {
84
+ type : 'text' ,
85
+ step : 2
86
+ } ,
87
+ apiCheckFunction : 'throw'
88
+ } ) ;
89
+ } ) . toThrowError ( Error , / s t e p / i) ;
90
+ } ) ;
91
+
92
+ it ( 'should not be available on non number type' , ( ) => {
93
+ compile ( {
94
+ templateOptions : {
95
+ type : 'text' ,
96
+ step : 2
97
+ }
98
+ } ) ;
99
+
100
+ expect ( element . attr ( 'step' ) ) . toBeUndefined ( ) ;
101
+ } ) ;
102
+
103
+ it ( 'should be available on number type' , ( ) => {
104
+ compile ( {
105
+ templateOptions : {
106
+ type : 'number' ,
107
+ step : 2
108
+ }
109
+ } ) ;
110
+
111
+ expect ( parseInt ( element . attr ( 'step' ) ) ) . toEqual ( field . templateOptions . step ) ;
112
+ } ) ;
113
+ } ) ;
114
+
115
+ describe ( 'min attribute' , ( ) => {
116
+ it ( 'should fail on non number type' , ( ) => {
117
+ expect ( ( ) => {
118
+ compile ( {
119
+ templateOptions : {
120
+ type : 'text' ,
121
+ min : 2
122
+ } ,
123
+ apiCheckFunction : 'throw'
124
+ } ) ;
125
+ } ) . toThrowError ( Error , / m i n / i) ;
126
+ } ) ;
127
+
128
+ it ( 'should be available on number type' , ( ) => {
129
+ compile ( {
130
+ templateOptions : {
131
+ type : 'number' ,
132
+ min : 2
133
+ }
134
+ } ) ;
135
+
136
+ expect ( parseInt ( element . attr ( 'min' ) ) ) . toEqual ( field . templateOptions . min ) ;
137
+ } ) ;
138
+ } ) ;
139
+
140
+ describe ( 'max attribute' , ( ) => {
141
+ it ( 'should fail on non number type' , ( ) => {
142
+ expect ( ( ) => {
143
+ compile ( {
144
+ templateOptions : {
145
+ type : 'text' ,
146
+ max : 2
147
+ } ,
148
+ apiCheckFunction : 'throw'
149
+ } ) ;
150
+ } ) . toThrowError ( Error , / m a x / i) ;
151
+ } ) ;
152
+
153
+ it ( 'should be available on number type' , ( ) => {
154
+ compile ( {
155
+ templateOptions : {
156
+ type : 'number' ,
157
+ max : 2
158
+ }
159
+ } ) ;
160
+
161
+ expect ( parseInt ( element . attr ( 'max' ) ) ) . toEqual ( field . templateOptions . max ) ;
162
+ } ) ;
163
+ } ) ;
72
164
} ) ;
73
165
} ) ;
0 commit comments