AnimationObjectGroup.tests.js 3.9 KB

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