@@ -2134,7 +2134,7 @@ describe('directive',function(){
2134
2134
2135
2135
2136
2136
2137
- it ( 'should default to "remove"' , function ( ) {
2137
+ it ( 'should default to "remove"' , function ( done ) {
2138
2138
2139
2139
inject ( function ( $compile , $rootScope ) {
2140
2140
var scope = $rootScope . $new ( ) ;
@@ -2188,7 +2188,7 @@ describe('directive',function(){
2188
2188
scope . $apply ( ) ;
2189
2189
2190
2190
scope . person . should . deep . equal ( {
2191
- "switch" : true ,
2191
+ "switch" : false ,
2192
2192
"list" : [
2193
2193
{
2194
2194
"sub" : {
@@ -2200,15 +2200,15 @@ describe('directive',function(){
2200
2200
}
2201
2201
}
2202
2202
} ) ;
2203
-
2203
+ done ( ) ;
2204
2204
} ) ;
2205
2205
2206
2206
} ) ;
2207
2207
} ) ;
2208
2208
2209
- it ( 'should default to " remove"' , function ( ) {
2209
+ it ( 'should not remove anything if $destroy event comes from outside' , function ( done ) {
2210
2210
2211
- inject ( function ( $compile , $rootScope ) {
2211
+ inject ( function ( $compile , $rootScope ) {
2212
2212
var scope = $rootScope . $new ( ) ;
2213
2213
scope . person = {
2214
2214
"switch" : true ,
@@ -2276,7 +2276,85 @@ describe('directive',function(){
2276
2276
}
2277
2277
}
2278
2278
} ) ;
2279
+ done ( ) ;
2280
+ } ) ;
2281
+ } ) ;
2282
+ } ) ;
2283
+
2284
+ it ( 'should "retain" model if asked to' , function ( done ) {
2285
+
2286
+ inject ( function ( $compile , $rootScope ) {
2287
+ var scope = $rootScope . $new ( ) ;
2288
+ scope . person = {
2289
+ "switch" : true ,
2290
+ "list" : [
2291
+ {
2292
+ "sub" : {
2293
+ "prop" : "subprop"
2294
+ } ,
2295
+ "name" : "Name"
2296
+ }
2297
+ ] ,
2298
+ "deep" : {
2299
+ "name" : "deepname" ,
2300
+ "sub" : {
2301
+ "prop" : "deepprop"
2302
+ }
2303
+ }
2304
+ } ;
2305
+
2306
+ scope . schema = schema ;
2307
+ scope . options = { destroyStrategy : 'retain' } ;
2308
+ scope . form = form ;
2309
+
2310
+ var tmpl = angular . element ( '<form sf-schema="schema" sf-options="options" sf-form="form" sf-model="person"></form>' ) ;
2311
+
2312
+ $compile ( tmpl ) ( scope ) ;
2313
+ $rootScope . $apply ( ) ;
2314
+
2315
+ scope . person . should . deep . equal ( {
2316
+ "switch" : true ,
2317
+ "list" : [
2318
+ {
2319
+ "sub" : {
2320
+ "prop" : "subprop"
2321
+ } ,
2322
+ "name" : "Name"
2323
+ }
2324
+ ] ,
2325
+ "deep" : {
2326
+ "name" : "deepname" ,
2327
+ "sub" : {
2328
+ "prop" : "deepprop"
2329
+ }
2330
+ }
2331
+ } ) ;
2332
+
2333
+ setTimeout ( function ( ) {
2334
+ scope . person . switch = false ;
2335
+ scope . $apply ( ) ;
2336
+ console . log ( JSON . stringify ( scope . person , undefined , 2 ) )
2337
+ scope . person . should . deep . equal ( {
2338
+ "switch" : false ,
2339
+ "list" : [
2340
+ {
2341
+ "sub" : {
2342
+ "prop" : "subprop"
2343
+ } ,
2344
+ "name" : "Name"
2345
+ }
2346
+ ] ,
2347
+ "deep" : {
2348
+ "name" : "deepname" ,
2349
+ "sub" : {
2350
+ "prop" : "deepprop"
2351
+ }
2352
+ }
2353
+ } ) ;
2354
+
2355
+ done ( ) ;
2279
2356
} ) ;
2357
+
2280
2358
} ) ;
2281
2359
} ) ;
2282
2360
0 commit comments