Нет описания

animationSpec.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* eslint-disable */
  2. describe('Animation: ', function() {
  3. var event = document.createEvent('HTMLEvents');
  4. var granimInstance, gradientColor, canvas,
  5. canvasWidthMiddle, canvasHeightMiddle;
  6. var validOptions = {
  7. element: '#granim-canvas',
  8. name: 'granim',
  9. direction: 'left-right',
  10. opacity: [1, 1],
  11. states : {
  12. "default-state": {
  13. gradients: [
  14. ['hsl(333, 56%,89%)', '#181818', 'rgba(25,63, 48, .75)'],
  15. ['#7b4397', 'hsla(126,0%, 19%,.9)', 'rgb(69, 89,169)'],
  16. [{ color: '#833ab4', pos: .2 }, { color: 'rgb(255, 0,25)', pos: .6 }, { color: '#ff0080', pos: .95 }],
  17. ['#222', 'hsl(0, 5%, 5%)', 'rgb(255, 0,0)'],
  18. ],
  19. transitionSpeed: 100,
  20. loop: true
  21. }
  22. }
  23. };
  24. var newGranimInstance = function(options) { return new Granim(options) };
  25. beforeEach(function(done) {
  26. setTimeout(function() {
  27. value = 0;
  28. done();
  29. }, 1);
  30. });
  31. it('should support async execution of test preparation and expectations', function(done) {
  32. canvas = setCanvas();
  33. granimInstance = newGranimInstance(validOptions);
  34. event.initEvent('resize', true, false);
  35. window.dispatchEvent(event);
  36. canvasWidthMiddle = (canvas.width - 50) / 2;
  37. canvasHeightMiddle = (canvas.height - 50) / 2;
  38. gradientColor = granimInstance.context.getImageData(canvasWidthMiddle, canvasHeightMiddle, 5, 5);
  39. expect(granimInstance).toBeDefined();
  40. done();
  41. });
  42. describe('Asynchronous specs:', function() {
  43. var originalTimeout;
  44. beforeEach(function() {
  45. originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
  46. jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
  47. });
  48. it('Gradient animation is working', function(done) {
  49. setTimeout(function() {
  50. var isSameGradientImage = compareImages(gradientColor, granimInstance.context.getImageData(canvasWidthMiddle, canvasHeightMiddle, 5, 5));
  51. expect(isSameGradientImage).toBe(false);
  52. done();
  53. }, 300);
  54. });
  55. it('Gradient animation with custom direction is working', function(done) {
  56. granimInstance.destroy();
  57. granimInstance = newGranimInstance(Object.assign(
  58. Object.assign({}, validOptions),
  59. {
  60. direction: 'custom',
  61. customDirection: {
  62. x0: '10%',
  63. y0: '25px',
  64. x1: '30%',
  65. y1: '322px'
  66. }
  67. }
  68. ));
  69. setTimeout(function() {
  70. expect(granimInstance).toBeDefined();
  71. done();
  72. }, 300);
  73. });
  74. afterEach(function() {
  75. jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
  76. });
  77. });
  78. });