@@ -2134,7 +2134,7 @@ describe('directive',function(){
21342134
21352135
21362136
2137- it ( 'should default to "remove"' , function ( ) {
2137+ it ( 'should default to "remove"' , function ( done ) {
21382138
21392139 inject ( function ( $compile , $rootScope ) {
21402140 var scope = $rootScope . $new ( ) ;
@@ -2188,7 +2188,7 @@ describe('directive',function(){
21882188 scope . $apply ( ) ;
21892189
21902190 scope . person . should . deep . equal ( {
2191- "switch" : true ,
2191+ "switch" : false ,
21922192 "list" : [
21932193 {
21942194 "sub" : {
@@ -2200,15 +2200,15 @@ describe('directive',function(){
22002200 }
22012201 }
22022202 } ) ;
2203-
2203+ done ( ) ;
22042204 } ) ;
22052205
22062206 } ) ;
22072207 } ) ;
22082208
2209- it ( 'should default to " remove"' , function ( ) {
2209+ it ( 'should not remove anything if $destroy event comes from outside' , function ( done ) {
22102210
2211- inject ( function ( $compile , $rootScope ) {
2211+ inject ( function ( $compile , $rootScope ) {
22122212 var scope = $rootScope . $new ( ) ;
22132213 scope . person = {
22142214 "switch" : true ,
@@ -2276,7 +2276,85 @@ describe('directive',function(){
22762276 }
22772277 }
22782278 } ) ;
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 ( ) ;
22792356 } ) ;
2357+
22802358 } ) ;
22812359 } ) ;
22822360
0 commit comments