AnimationObjectGroup.tests.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /**
  2. * @author tschw
  3. * @author TristanVALCKE / https://github.com/Itee
  4. */
  5. /* global QUnit */
  6. import { AnimationObjectGroup } from '../../../../src/animation/AnimationObjectGroup';
  7. import { Object3D } from '../../../../src/core/Object3D';
  8. import { PropertyBinding } from '../../../../src/animation/PropertyBinding';
  9. export default QUnit.module( "Animation", () => {
  10. QUnit.module( "AnimationObjectGroup", () => {
  11. var ObjectA = new Object3D(),
  12. ObjectB = new Object3D(),
  13. ObjectC = new Object3D(),
  14. PathA = 'object.position',
  15. PathB = 'object.rotation',
  16. PathC = 'object.scale',
  17. ParsedPathA = PropertyBinding.parseTrackName( PathA ),
  18. ParsedPathB = PropertyBinding.parseTrackName( PathB ),
  19. ParsedPathC = PropertyBinding.parseTrackName( PathC );
  20. // INSTANCING
  21. QUnit.todo( "Instancing", ( assert ) => {
  22. assert.ok( false, "everything's gonna be alright" );
  23. } );
  24. // PUBLIC STUFF
  25. QUnit.todo( "isAnimationObjectGroup", ( assert ) => {
  26. assert.ok( false, "everything's gonna be alright" );
  27. } );
  28. QUnit.todo( "add", ( assert ) => {
  29. assert.ok( false, "everything's gonna be alright" );
  30. } );
  31. QUnit.todo( "remove", ( assert ) => {
  32. assert.ok( false, "everything's gonna be alright" );
  33. } );
  34. QUnit.todo( "uncache", ( assert ) => {
  35. assert.ok( false, "everything's gonna be alright" );
  36. } );
  37. // OTHERS
  38. QUnit.test( "smoke test", ( assert ) => {
  39. var expect = function expect( testIndex, group, bindings, path, cached, roots ) {
  40. var rootNodes = [], pathsOk = true, nodesOk = true;
  41. for ( var i = group.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  42. if ( bindings[ i ].path !== path ) pathsOk = false;
  43. rootNodes.push( bindings[ i ].rootNode );
  44. }
  45. for ( var i = 0, n = roots.length; i !== n; ++ i ) {
  46. if ( rootNodes.indexOf( roots[ i ] ) === - 1 ) nodesOk = false;
  47. }
  48. assert.ok( pathsOk, QUnit.testIndex + " paths" );
  49. assert.ok( nodesOk, QUnit.testIndex + " nodes" );
  50. assert.ok( group.nCachedObjects_ === cached, QUnit.testIndex + " cache size" );
  51. assert.ok( bindings.length - group.nCachedObjects_ === roots.length, QUnit.testIndex + " object count" );
  52. };
  53. // initial state
  54. var groupA = new AnimationObjectGroup();
  55. assert.ok( groupA instanceof AnimationObjectGroup, "constructor (w/o args)" );
  56. var bindingsAA = groupA.subscribe_( PathA, ParsedPathA );
  57. expect( 0, groupA, bindingsAA, PathA, 0, [] );
  58. var groupB = new AnimationObjectGroup( ObjectA, ObjectB );
  59. assert.ok( groupB instanceof AnimationObjectGroup, "constructor (with args)" );
  60. var bindingsBB = groupB.subscribe_( PathB, ParsedPathB );
  61. expect( 1, groupB, bindingsBB, PathB, 0, [ ObjectA, ObjectB ] );
  62. // add
  63. groupA.add( ObjectA, ObjectB );
  64. expect( 2, groupA, bindingsAA, PathA, 0, [ ObjectA, ObjectB ] );
  65. groupB.add( ObjectC );
  66. expect( 3, groupB, bindingsBB, PathB, 0, [ ObjectA, ObjectB, ObjectC ] );
  67. // remove
  68. groupA.remove( ObjectA, ObjectC );
  69. expect( 4, groupA, bindingsAA, PathA, 1, [ ObjectB ] );
  70. groupB.remove( ObjectA, ObjectB, ObjectC );
  71. expect( 5, groupB, bindingsBB, PathB, 3, [] );
  72. // subscribe after re-add
  73. groupA.add( ObjectC );
  74. expect( 6, groupA, bindingsAA, PathA, 1, [ ObjectB, ObjectC ] );
  75. var bindingsAC = groupA.subscribe_( PathC, ParsedPathC );
  76. expect( 7, groupA, bindingsAC, PathC, 1, [ ObjectB, ObjectC ] );
  77. // re-add after subscribe
  78. var bindingsBC = groupB.subscribe_( PathC, ParsedPathC );
  79. groupB.add( ObjectA, ObjectB );
  80. expect( 8, groupB, bindingsBB, PathB, 1, [ ObjectA, ObjectB ] );
  81. // unsubscribe
  82. var copyOfBindingsBC = bindingsBC.slice();
  83. groupB.unsubscribe_( PathC );
  84. groupB.add( ObjectC );
  85. assert.deepEqual( bindingsBC, copyOfBindingsBC, "no more update after unsubscribe" );
  86. // uncache active
  87. groupB.uncache( ObjectA );
  88. expect( 9, groupB, bindingsBB, PathB, 0, [ ObjectB, ObjectC ] );
  89. // uncache cached
  90. groupA.uncache( ObjectA );
  91. expect( 10, groupA, bindingsAC, PathC, 0, [ ObjectB, ObjectC ] );
  92. } );
  93. } );
  94. } );