1+ var Transformable = require ( '../../../../src/common/overlay/levelRenderer/Transformable' ) . Transformable ;
2+
3+ describe ( 'Transformable' , function ( ) {
4+ var canvas , ctx ;
5+ beforeAll ( function ( ) {
6+ canvas = window . document . createElement ( 'CANVAS' ) ;
7+ canvas . width = 400 ;
8+ canvas . height = 400 ;
9+ canvas . style . border = "1px solid #000000" ;
10+ ctx = canvas . getContext ( '2d' ) ;
11+ window . document . body . appendChild ( canvas ) ;
12+ } ) ;
13+ afterAll ( function ( ) {
14+ window . document . body . removeChild ( canvas ) ;
15+ } ) ;
16+ it ( 'updateNeedTransform, updateTransform' , function ( ) {
17+ var transformable = new Transformable ( ) ;
18+ transformable . lookAt ( [ 1 , 1 ] ) ;
19+ transformable . lookAt ( [ 0 , 0 ] ) ;
20+ transformable . position = [ 1 , 1 ] ;
21+ transformable . rotation = [ 1 , 2 ] ;
22+ transformable . scale = [ 1 , 1 , 2 , 2 ] ;
23+ spyOn ( transformable , 'updateNeedTransform' ) . and . callThrough ( ) ;
24+ expect ( transformable . needLocalTransform ) . toBeFalsy ( ) ;
25+ expect ( transformable . needTransform ) . toBeFalsy ( ) ;
26+ transformable . updateTransform ( ) ;
27+ expect ( transformable . needLocalTransform ) . toBeTruthy ( ) ;
28+ expect ( transformable . needTransform ) . toBeTruthy ( ) ;
29+ expect ( transformable . transform ) . not . toBeNull ( ) ;
30+ transformable . rotation = 3 ;
31+ transformable . updateTransform ( ) ;
32+ expect ( transformable . needLocalTransform ) . toBeTruthy ( ) ;
33+ expect ( transformable . needTransform ) . toBeTruthy ( ) ;
34+ expect ( transformable . rotation ) . toEqual ( 3 ) ;
35+ expect ( transformable . transform ) . not . toBeNull ( ) ;
36+ expect ( transformable . updateNeedTransform ) . toHaveBeenCalled ( ) ;
37+ expect ( transformable . updateNeedTransform . calls . count ( ) ) . toEqual ( 2 ) ;
38+ transformable . destroy ( ) ;
39+ } ) ;
40+
41+ it ( 'setTransform' , function ( ) {
42+ var transformable = new Transformable ( ) ;
43+ transformable . position = [ 1 , 1 ] ;
44+ spyOn ( ctx , 'transform' ) . and . callThrough ( ) ;
45+ transformable . updateTransform ( ) ;
46+ transformable . setTransform ( ctx ) ;
47+ expect ( ctx . transform ) . toHaveBeenCalled ( ) ;
48+ transformable . destroy ( ) ;
49+ } ) ;
50+
51+ it ( 'decomposeTransform' , function ( ) {
52+ var transformable = new Transformable ( ) ;
53+ transformable . decomposeTransform ( ) ;
54+ transformable . position = [ 12 , 10 ] ;
55+ transformable . rotation = [ 10 , 20 ] ;
56+ transformable . scale = [ 10 , 10 , 20 , 20 ] ;
57+ transformable . updateTransform ( ) ;
58+ expect ( transformable . position [ 0 ] ) . toEqual ( 12 ) ;
59+ expect ( transformable . position [ 1 ] ) . toEqual ( 10 ) ;
60+ expect ( transformable . rotation [ 0 ] ) . toEqual ( 10 ) ;
61+ expect ( transformable . rotation [ 1 ] ) . toEqual ( 20 ) ;
62+ expect ( transformable . scale [ 0 ] ) . toEqual ( 10 ) ;
63+ expect ( transformable . scale [ 1 ] ) . toEqual ( 10 ) ;
64+ expect ( transformable . scale [ 2 ] ) . toEqual ( 20 ) ;
65+ expect ( transformable . scale [ 3 ] ) . toEqual ( 20 ) ;
66+ transformable . decomposeTransform ( ) ;
67+ expect ( transformable . position [ 0 ] ) . not . toBe ( 12 ) ;
68+ expect ( transformable . position [ 1 ] ) . not . toBe ( 10 ) ;
69+ expect ( transformable . rotation [ 0 ] ) . not . toBe ( 10 ) ;
70+ expect ( transformable . rotation [ 1 ] ) . not . toBe ( 20 ) ;
71+ expect ( transformable . scale [ 0 ] ) . not . toBe ( 10 ) ;
72+ expect ( transformable . scale [ 1 ] ) . not . toBe ( 10 ) ;
73+ expect ( transformable . scale [ 2 ] ) . not . toBe ( 20 ) ;
74+ expect ( transformable . scale [ 3 ] ) . not . toBe ( 20 ) ;
75+ transformable . destroy ( ) ;
76+ } ) ;
77+ } ) ;
0 commit comments