@@ -2207,197 +2207,49 @@ describe('sf-schema.directive.js', function() {
2207
2207
} ) ;
2208
2208
} ) ;
2209
2209
2210
- it ( 'should not add "has-success" class to radios field if a correct value is entered, but disableSuccessState is set on form' , function ( ) {
2211
- var field = {
2212
- name : 'radios' ,
2213
- property : {
2214
- type : 'boolean' ,
2215
- } ,
2216
- form : {
2217
- key : [ "field" ] ,
2218
- type : "radios" ,
2219
- titleMap : [
2220
- {
2221
- "value" : false ,
2222
- "name" : "No way" ,
2223
- } ,
2224
- {
2225
- "value" : true ,
2226
- "name" : "OK" ,
2227
- } ,
2228
- ] ,
2229
- } ,
2230
- } ;
2231
-
2232
- inject ( function ( $compile , $rootScope ) {
2210
+ /*
2211
+ TODO
2212
+ it('should handle onChange for array type', function () {
2213
+ inject(function($compile,$rootScope){
2233
2214
var scope = $rootScope.$new();
2234
- scope . model = { } ,
2235
- scope . schema = {
2236
- type : 'object' ,
2237
- properties : {
2238
- field : field . property ,
2239
- } ,
2240
- } ;
2241
- scope . form = [ field . form ] ;
2242
-
2243
- var tmpl = angular . element ( '<form name="theForm" sf-schema="schema" sf-form="form" sf-model="model"></form>' ) ;
2244
- $compile ( tmpl ) ( scope ) ;
2245
- runSync ( scope , tmpl ) ;
2246
- var ngModelCtrl = tmpl . find ( '.field' ) . scope ( ) . ngModel ;
2247
- ngModelCtrl . $valid = true ;
2248
- ngModelCtrl . $pristine = false ;
2249
- $rootScope . $apply ( ) ;
2250
- tmpl . find ( '.field' ) . hasClass ( 'has-success' ) . should . be . true ;
2251
- scope . form [ 0 ] . disableSuccessState = true ;
2252
- $rootScope . $apply ( ) ;
2253
- tmpl . find ( '.field' ) . hasClass ( 'has-success' ) . should . be . false ;
2254
- } ) ;
2255
- } ) ;
2256
-
2257
- it ( 'should not add "has-error" class to radios field if invalid value is entered, but disableErrorState is set on form' , function ( ) {
2258
- var field = {
2259
- name : 'radios' ,
2260
- property : {
2261
- type : 'boolean' ,
2262
- } ,
2263
- form : {
2264
- key : [ "field" ] ,
2265
- type : "radios" ,
2266
- titleMap : [
2267
- {
2268
- "value" : false ,
2269
- "name" : "No way" ,
2270
- } ,
2271
- {
2272
- "value" : true ,
2273
- "name" : "OK" ,
2274
- } ,
2275
- ] ,
2276
- } ,
2277
- } ;
2215
+ scope.obj = {};
2278
2216
2279
- inject ( function ( $compile , $rootScope ) {
2280
- var scope = $rootScope . $new ( ) ;
2281
- scope . model = {
2282
- field : field . errorValue ,
2283
- } ;
2284
2217
scope.schema = {
2285
- type : 'object' ,
2286
- properties : {
2287
- field : field . property ,
2288
- } ,
2218
+ "type": "object",
2219
+ "properties": {
2220
+ "arr" : {
2221
+ "type": "array",
2222
+ "items": {
2223
+ "type": "object",
2224
+ "properties": {
2225
+ "name": {
2226
+ "type": "string",
2227
+ "default": "Name"
2228
+ }
2229
+ }
2230
+ }
2231
+ }
2232
+ }
2289
2233
};
2290
- scope . form = [ field . form ] ;
2291
2234
2292
- var tmpl = angular . element ( '<form name="theForm" sf-schema="schema" sf-form="form" sf-model="model"></form>' ) ;
2293
- $compile ( tmpl ) ( scope ) ;
2294
- runSync ( scope , tmpl ) ;
2295
- var ngModelCtrl = tmpl . find ( '.field' ) . scope ( ) . ngModel ;
2296
- ngModelCtrl . $invalid = true ;
2297
- ngModelCtrl . $pristine = false ;
2298
- $rootScope . $apply ( ) ;
2299
- tmpl . find ( '.field' ) . hasClass ( 'has-error' ) . should . be . true ;
2300
- scope . form [ 0 ] . disableErrorState = true ;
2301
- $rootScope . $apply ( ) ;
2302
- tmpl . find ( '.field' ) . hasClass ( 'has-error' ) . should . be . false ;
2303
- } ) ;
2304
- } ) ;
2235
+ scope.form = [{key : "arr", startEmpty : true, onChange: sinon.spy()}];
2305
2236
2306
- it ( 'should not add "has-success" class to radios-inline field if a correct value is entered, but disableSuccessState is set on form' , function ( ) {
2307
- var field = {
2308
- name : 'radios' ,
2309
- property : {
2310
- type : 'boolean' ,
2311
- } ,
2312
- form : {
2313
- key : [ "field" ] ,
2314
- type : "radios" ,
2315
- titleMap : [
2316
- {
2317
- "value" : false ,
2318
- "name" : "No way" ,
2319
- } ,
2320
- {
2321
- "value" : true ,
2322
- "name" : "OK" ,
2323
- } ,
2324
- ] ,
2325
- } ,
2326
- } ;
2327
-
2328
- inject ( function ( $compile , $rootScope ) {
2329
- var scope = $rootScope . $new ( ) ;
2330
- scope . model = { } ,
2331
- scope . schema = {
2332
- type : 'object' ,
2333
- properties : {
2334
- field : field . property ,
2335
- } ,
2336
- } ;
2337
- scope . form = [ field . form ] ;
2237
+ var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="obj"></form>');
2338
2238
2339
- var tmpl = angular . element ( '<form name="theForm" sf-schema="schema" sf-form="form" sf-model="model"></form>' ) ;
2340
2239
$compile(tmpl)(scope);
2341
- runSync ( scope , tmpl ) ;
2342
- var ngModelCtrl = tmpl . find ( '.field' ) . scope ( ) . ngModel ;
2343
- ngModelCtrl . $valid = true ;
2344
- ngModelCtrl . $pristine = false ;
2345
2240
$rootScope.$apply();
2346
- tmpl . find ( '.field' ) . hasClass ( 'has-success' ) . should . be . true ;
2347
- scope . form [ 0 ] . disableSuccessState = true ;
2348
- $rootScope . $apply ( ) ;
2349
- tmpl . find ( '.field' ) . hasClass ( 'has-success' ) . should . be . false ;
2350
- } ) ;
2351
- } ) ;
2352
2241
2353
- it ( 'should not add "has-error" class to radios-inline field if invalid value is entered, but disableErrorState is set on form' , function ( ) {
2354
- var field = {
2355
- name : 'radios' ,
2356
- property : {
2357
- type : 'boolean' ,
2358
- } ,
2359
- form : {
2360
- key : [ "field" ] ,
2361
- type : "radios" ,
2362
- titleMap : [
2363
- {
2364
- "value" : false ,
2365
- "name" : "No way" ,
2366
- } ,
2367
- {
2368
- "value" : true ,
2369
- "name" : "OK" ,
2370
- } ,
2371
- ] ,
2372
- } ,
2373
- } ;
2242
+ scope.form[0].onChange.should.not.have.been.called;
2374
2243
2375
- inject ( function ( $compile , $rootScope ) {
2376
- var scope = $rootScope . $new ( ) ;
2377
- scope . model = {
2378
- field : field . errorValue ,
2379
- } ;
2380
- scope . schema = {
2381
- type : 'object' ,
2382
- properties : {
2383
- field : { type : 'boolean' } ,
2384
- } ,
2385
- } ;
2386
- scope . form = [ field . form ] ;
2244
+ tmpl.find('button.close').click();
2245
+ //scope.form[0].onChange.should.have.been.called;
2246
+ //scope.form[0].onChange.should.have.been.calledWith([]);
2387
2247
2388
- var tmpl = angular . element ( '<form name="theForm" sf-schema="schema" sf-form="form" sf-model="model"></form>' ) ;
2389
- $compile ( tmpl ) ( scope ) ;
2390
- runSync ( scope , tmpl ) ;
2391
- var ngModelCtrl = tmpl . find ( '.field' ) . scope ( ) . ngModel ;
2392
- ngModelCtrl . $invalid = true ;
2393
- ngModelCtrl . $pristine = false ;
2394
- $rootScope . $apply ( ) ;
2395
- tmpl . find ( '.field' ) . hasClass ( 'has-error' ) . should . be . true ;
2396
- scope . form [ 0 ] . disableErrorState = true ;
2397
- $rootScope . $apply ( ) ;
2398
- tmpl . find ( '.field' ) . hasClass ( 'has-error' ) . should . be . false ;
2248
+ tmpl.find('button.btn-default').click();
2249
+ //scope.form[0].onChange.should.have.been.calledWith([{name : "Name"}]);
2399
2250
});
2400
2251
});
2252
+ */
2401
2253
} ) ;
2402
2254
2403
2255
0 commit comments