testing.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * @license Angular v8.1.0
  3. * (c) 2010-2019 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { __extends } from 'tslib';
  7. import { AUTO_STYLE, NoopAnimationPlayer } from '@angular/animations';
  8. import { ɵvalidateStyleProperty, ɵmatchesElement, ɵcontainsElement, ɵinvokeQuery, ɵallowPreviousPlayerStylesMerge } from '@angular/animations/browser';
  9. /**
  10. * @publicApi
  11. */
  12. var MockAnimationDriver = /** @class */ (function () {
  13. function MockAnimationDriver() {
  14. }
  15. MockAnimationDriver.prototype.validateStyleProperty = function (prop) { return ɵvalidateStyleProperty(prop); };
  16. MockAnimationDriver.prototype.matchesElement = function (element, selector) {
  17. return ɵmatchesElement(element, selector);
  18. };
  19. MockAnimationDriver.prototype.containsElement = function (elm1, elm2) { return ɵcontainsElement(elm1, elm2); };
  20. MockAnimationDriver.prototype.query = function (element, selector, multi) {
  21. return ɵinvokeQuery(element, selector, multi);
  22. };
  23. MockAnimationDriver.prototype.computeStyle = function (element, prop, defaultValue) {
  24. return defaultValue || '';
  25. };
  26. MockAnimationDriver.prototype.animate = function (element, keyframes, duration, delay, easing, previousPlayers) {
  27. if (previousPlayers === void 0) { previousPlayers = []; }
  28. var player = new MockAnimationPlayer(element, keyframes, duration, delay, easing, previousPlayers);
  29. MockAnimationDriver.log.push(player);
  30. return player;
  31. };
  32. MockAnimationDriver.log = [];
  33. return MockAnimationDriver;
  34. }());
  35. /**
  36. * @publicApi
  37. */
  38. var MockAnimationPlayer = /** @class */ (function (_super) {
  39. __extends(MockAnimationPlayer, _super);
  40. function MockAnimationPlayer(element, keyframes, duration, delay, easing, previousPlayers) {
  41. var _this = _super.call(this, duration, delay) || this;
  42. _this.element = element;
  43. _this.keyframes = keyframes;
  44. _this.duration = duration;
  45. _this.delay = delay;
  46. _this.easing = easing;
  47. _this.previousPlayers = previousPlayers;
  48. _this.__finished = false;
  49. _this.__started = false;
  50. _this.previousStyles = {};
  51. _this._onInitFns = [];
  52. _this.currentSnapshot = {};
  53. if (ɵallowPreviousPlayerStylesMerge(duration, delay)) {
  54. previousPlayers.forEach(function (player) {
  55. if (player instanceof MockAnimationPlayer) {
  56. var styles_1 = player.currentSnapshot;
  57. Object.keys(styles_1).forEach(function (prop) { return _this.previousStyles[prop] = styles_1[prop]; });
  58. }
  59. });
  60. }
  61. return _this;
  62. }
  63. /* @internal */
  64. MockAnimationPlayer.prototype.onInit = function (fn) { this._onInitFns.push(fn); };
  65. /* @internal */
  66. MockAnimationPlayer.prototype.init = function () {
  67. _super.prototype.init.call(this);
  68. this._onInitFns.forEach(function (fn) { return fn(); });
  69. this._onInitFns = [];
  70. };
  71. MockAnimationPlayer.prototype.finish = function () {
  72. _super.prototype.finish.call(this);
  73. this.__finished = true;
  74. };
  75. MockAnimationPlayer.prototype.destroy = function () {
  76. _super.prototype.destroy.call(this);
  77. this.__finished = true;
  78. };
  79. /* @internal */
  80. MockAnimationPlayer.prototype.triggerMicrotask = function () { };
  81. MockAnimationPlayer.prototype.play = function () {
  82. _super.prototype.play.call(this);
  83. this.__started = true;
  84. };
  85. MockAnimationPlayer.prototype.hasStarted = function () { return this.__started; };
  86. MockAnimationPlayer.prototype.beforeDestroy = function () {
  87. var _this = this;
  88. var captures = {};
  89. Object.keys(this.previousStyles).forEach(function (prop) {
  90. captures[prop] = _this.previousStyles[prop];
  91. });
  92. if (this.hasStarted()) {
  93. // when assembling the captured styles, it's important that
  94. // we build the keyframe styles in the following order:
  95. // {other styles within keyframes, ... previousStyles }
  96. this.keyframes.forEach(function (kf) {
  97. Object.keys(kf).forEach(function (prop) {
  98. if (prop != 'offset') {
  99. captures[prop] = _this.__finished ? kf[prop] : AUTO_STYLE;
  100. }
  101. });
  102. });
  103. }
  104. this.currentSnapshot = captures;
  105. };
  106. return MockAnimationPlayer;
  107. }(NoopAnimationPlayer));
  108. /**
  109. * @license
  110. * Copyright Google Inc. All Rights Reserved.
  111. *
  112. * Use of this source code is governed by an MIT-style license that can be
  113. * found in the LICENSE file at https://angular.io/license
  114. */
  115. /**
  116. * @license
  117. * Copyright Google Inc. All Rights Reserved.
  118. *
  119. * Use of this source code is governed by an MIT-style license that can be
  120. * found in the LICENSE file at https://angular.io/license
  121. */
  122. /**
  123. * @license
  124. * Copyright Google Inc. All Rights Reserved.
  125. *
  126. * Use of this source code is governed by an MIT-style license that can be
  127. * found in the LICENSE file at https://angular.io/license
  128. */
  129. /**
  130. * Generated bundle index. Do not edit.
  131. */
  132. export { MockAnimationDriver, MockAnimationPlayer };
  133. //# sourceMappingURL=testing.js.map