@@ -770,4 +770,91 @@ describe('Test lib.js:', function() {
770
770
} ) ;
771
771
} ) ;
772
772
773
+ fdescribe ( 'getTranslate' , function ( ) {
774
+
775
+ it ( 'should work with regular DOM elements' , function ( ) {
776
+ var el = document . createElement ( 'div' ) ;
777
+
778
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 0 , y : 0 } ) ;
779
+
780
+ el . setAttribute ( 'transform' , 'translate(123.45px, 67)' ) ;
781
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 123.45 , y : 67 } ) ;
782
+
783
+ el . setAttribute ( 'transform' , 'translate(123.45)' ) ;
784
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 123.45 , y : 0 } ) ;
785
+
786
+ el . setAttribute ( 'transform' , 'translate(1 2)' ) ;
787
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 1 , y : 2 } ) ;
788
+
789
+ el . setAttribute ( 'transform' , 'translate(1 2); rotate(20deg)' ) ;
790
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 1 , y : 2 } ) ;
791
+
792
+ el . setAttribute ( 'transform' , 'rotate(20deg)' ) ;
793
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 0 , y : 0 } ) ;
794
+ } ) ;
795
+
796
+ it ( 'should work with d3 elements' , function ( ) {
797
+ var el = d3 . select ( document . createElement ( 'div' ) ) ;
798
+
799
+ el . attr ( 'transform' , 'translate(123.45px, 67)' ) ;
800
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 123.45 , y : 67 } ) ;
801
+
802
+ el . attr ( 'transform' , 'translate(123.45)' ) ;
803
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 123.45 , y : 0 } ) ;
804
+
805
+ el . attr ( 'transform' , 'translate(1 2)' ) ;
806
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 1 , y : 2 } ) ;
807
+
808
+ el . attr ( 'transform' , 'translate(1 2); rotate(20)' ) ;
809
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 1 , y : 2 } ) ;
810
+
811
+ el . attr ( 'transform' , 'rotate(20)' ) ;
812
+ expect ( Lib . getTranslate ( el ) ) . toEqual ( { x : 0 , y : 0 } ) ;
813
+ } ) ;
814
+
815
+ } ) ;
816
+
817
+ fdescribe ( 'setTranslate' , function ( ) {
818
+
819
+ it ( 'should work with regular DOM elements' , function ( ) {
820
+ var el = document . createElement ( 'div' ) ;
821
+
822
+ Lib . setTranslate ( el , 5 ) ;
823
+ expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'translate(5, 0)' ) ;
824
+
825
+ Lib . setTranslate ( el , 10 , 20 ) ;
826
+ expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'translate(10, 20)' ) ;
827
+
828
+ Lib . setTranslate ( el , 30 , 40 ) ;
829
+ expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'translate(30, 40)' ) ;
830
+
831
+ Lib . setTranslate ( el ) ;
832
+ expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'translate(0, 0)' ) ;
833
+
834
+ el . setAttribute ( 'transform' , 'translate(0, 0); rotate(30)' ) ;
835
+ Lib . setTranslate ( el , 30 , 40 ) ;
836
+ expect ( el . getAttribute ( 'transform' ) ) . toBe ( 'rotate(30) translate(30, 40)' ) ;
837
+ } ) ;
838
+
839
+ it ( 'should work with d3 elements' , function ( ) {
840
+ var el = d3 . select ( document . createElement ( 'div' ) ) ;
841
+
842
+ Lib . setTranslate ( el , 5 ) ;
843
+ expect ( el . attr ( 'transform' ) ) . toBe ( 'translate(5, 0)' ) ;
844
+
845
+ Lib . setTranslate ( el , 10 , 20 ) ;
846
+ expect ( el . attr ( 'transform' ) ) . toBe ( 'translate(10, 20)' ) ;
847
+
848
+ Lib . setTranslate ( el , 30 , 40 ) ;
849
+ expect ( el . attr ( 'transform' ) ) . toBe ( 'translate(30, 40)' ) ;
850
+
851
+ Lib . setTranslate ( el ) ;
852
+ expect ( el . attr ( 'transform' ) ) . toBe ( 'translate(0, 0)' ) ;
853
+
854
+ el . attr ( 'transform' , 'translate(0, 0); rotate(30)' ) ;
855
+ Lib . setTranslate ( el , 30 , 40 ) ;
856
+ expect ( el . attr ( 'transform' ) ) . toBe ( 'rotate(30) translate(30, 40)' ) ;
857
+ } ) ;
858
+ } ) ;
859
+
773
860
} ) ;
0 commit comments