@@ -798,6 +798,74 @@ describe('Test lib.js:', function() {
798
798
expect ( sizeOut ) . toBe ( outObj . testMarker . testSize ) ;
799
799
} ) ;
800
800
801
+ it ( 'should set the user input' , function ( ) {
802
+ var colVal = 'red' ;
803
+ var sizeVal = '1e2' ;
804
+ var attrs = {
805
+ testMarker : {
806
+ testColor : { valType : 'color' , dflt : 'rgba(0, 0, 0, 0)' } ,
807
+ testSize : { valType : 'number' , dflt : 20 }
808
+ }
809
+ } ;
810
+ var obj = { testMarker : { testColor : colVal , testSize : sizeVal } } ;
811
+ var outObj = { } ;
812
+ var colOut = coerce2 ( obj , outObj , attrs , 'testMarker.testColor' ) ;
813
+ var sizeOut = coerce2 ( obj , outObj , attrs , 'testMarker.testSize' ) ;
814
+
815
+ expect ( colOut ) . toBe ( 'red' ) ;
816
+ expect ( colOut ) . toBe ( outObj . testMarker . testColor ) ;
817
+ expect ( sizeOut ) . toBe ( 100 ) ;
818
+ expect ( sizeOut ) . toBe ( outObj . testMarker . testSize ) ;
819
+ } ) ;
820
+
821
+ it ( 'should set to template if the container input is not valid' , function ( ) {
822
+ var attrs = {
823
+ testMarker : {
824
+ testColor : { valType : 'color' , dflt : 'rgba(0, 0, 0, 0)' } ,
825
+ testSize : { valType : 'number' , dflt : 20 }
826
+ }
827
+ } ;
828
+ var obj = {
829
+ testMarker : { testColor : 'invalid' , testSize : 'invalid' }
830
+ } ;
831
+ var outObj = {
832
+ _template : {
833
+ testMarker : { testColor : 'red' , testSize : '1e2' }
834
+ }
835
+ } ;
836
+ var colOut = coerce2 ( obj , outObj , attrs , 'testMarker.testColor' ) ;
837
+ var sizeOut = coerce2 ( obj , outObj , attrs , 'testMarker.testSize' ) ;
838
+
839
+ expect ( colOut ) . toBe ( 'red' ) ;
840
+ expect ( colOut ) . toBe ( outObj . testMarker . testColor ) ;
841
+ expect ( sizeOut ) . toBe ( 100 ) ;
842
+ expect ( sizeOut ) . toBe ( outObj . testMarker . testSize ) ;
843
+ } ) ;
844
+
845
+ it ( 'should set to default if the both container and template inputs are not valid' , function ( ) {
846
+ var attrs = {
847
+ testMarker : {
848
+ testColor : { valType : 'color' , dflt : 'rgba(0, 0, 0, 0)' } ,
849
+ testSize : { valType : 'number' , dflt : 20 }
850
+ }
851
+ } ;
852
+ var obj = {
853
+ testMarker : { testColor : 'invalid' , testSize : 'invalid' }
854
+ } ;
855
+ var outObj = {
856
+ _template : {
857
+ testMarker : { testColor : 'invalid' , testSize : 'invalid' }
858
+ }
859
+ } ;
860
+ var colOut = coerce2 ( obj , outObj , attrs , 'testMarker.testColor' ) ;
861
+ var sizeOut = coerce2 ( obj , outObj , attrs , 'testMarker.testSize' ) ;
862
+
863
+ expect ( colOut ) . toBe ( 'rgba(0, 0, 0, 0)' ) ;
864
+ expect ( colOut ) . toBe ( outObj . testMarker . testColor ) ;
865
+ expect ( sizeOut ) . toBe ( 20 ) ;
866
+ expect ( sizeOut ) . toBe ( outObj . testMarker . testSize ) ;
867
+ } ) ;
868
+
801
869
it ( 'should return false if there is no user input' , function ( ) {
802
870
var colVal = null ;
803
871
var sizeVal ; // undefined
0 commit comments