File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -1955,6 +1955,56 @@ describe('sf-schema.directive.js', function() {
1955
1955
} ) ;
1956
1956
} ) ;
1957
1957
1958
+ it ( 'should handle onChange for array type' , function ( ) {
1959
+ //TODO confirmt the logic is sound
1960
+ inject ( function ( $compile , $rootScope ) {
1961
+ var scope = $rootScope . $new ( ) ;
1962
+ scope . obj = { } ;
1963
+
1964
+ scope . schema = {
1965
+ "type" : "object" ,
1966
+ "properties" : {
1967
+ "arr" : {
1968
+ "type" : "array" ,
1969
+ "items" : {
1970
+ "type" : "object" ,
1971
+ "properties" : {
1972
+ "name" : {
1973
+ "type" : "string" ,
1974
+ "default" : "Name"
1975
+ }
1976
+ }
1977
+ }
1978
+ }
1979
+ }
1980
+ } ;
1981
+
1982
+ var spy = sinon . spy ( ) ;
1983
+ scope . form = [ { key : "arr" , startEmpty : true , onChange : spy } ] ;
1984
+
1985
+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="obj"></form>' ) ;
1986
+
1987
+ $compile ( tmpl ) ( scope ) ;
1988
+ runSync ( scope , tmpl ) ;
1989
+
1990
+ spy . should . have . been . called . once ;
1991
+
1992
+ tmpl . find ( 'button.btn-default' ) . click ( ) ;
1993
+
1994
+ // Test that "[{name: 'Name'}]" exists even if $$hashKey is defined
1995
+ var test = sinon . match ( function ( value ) {
1996
+ if ( value && value [ 0 ] && value [ 0 ] . name === "Name" ) return true ;
1997
+ return false ;
1998
+ } , "[{name: 'Name'}]" ) ;
1999
+
2000
+ spy . should . have . been . calledWith ( test ) ;
2001
+
2002
+ tmpl . find ( 'button.close' ) . click ( ) ;
2003
+ spy . should . have . been . calledWith ( [ ] ) ;
2004
+
2005
+ } ) ;
2006
+ } ) ;
2007
+
1958
2008
it ( 'should load template by templateUrl, with template field type' , function ( ) {
1959
2009
1960
2010
inject ( function ( $compile , $rootScope , $httpBackend ) {
You can’t perform that action at this time.
0 commit comments