Bez popisu

methodsSpec.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* eslint-disable */
  2. describe('Methods: ', function() {
  3. var granimInstance;
  4. beforeEach(function(done) {
  5. setTimeout(function() {
  6. value = 0;
  7. done();
  8. }, 1);
  9. });
  10. it('should support async execution of test preparation and expectations', function(done) {
  11. setCanvas();
  12. granimInstance = new Granim({
  13. element: '#granim-canvas',
  14. direction: 'left-right',
  15. //isPausedWhenNotInView: true,
  16. opacity: [1, 1],
  17. states: {
  18. "default-state": {
  19. gradients: [
  20. ['#BA8B02', '#181818'],
  21. ['#111', '#252525'],
  22. ['#7b4397', '#dc2430']
  23. ],
  24. transitionSpeed: 100,
  25. loop: false
  26. },
  27. "second-state": {
  28. gradients: [['#00bf8f', '#001510']],
  29. transitionSpeed: 100,
  30. loop: false
  31. }
  32. }
  33. });
  34. expect(granimInstance).toBeDefined();
  35. done();
  36. });
  37. describe('Asynchronous specs:', function() {
  38. var originalTimeout;
  39. beforeEach(function() {
  40. originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
  41. jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
  42. });
  43. it('Pause method is working', function(done) {
  44. setTimeout(function() {
  45. granimInstance.pause();
  46. expect(granimInstance.isPaused).toBe(true);
  47. done();
  48. }, 105);
  49. });
  50. it('Play method is working', function(done) {
  51. setTimeout(function() {
  52. granimInstance.play();
  53. expect(granimInstance.isPaused).toBe(false);
  54. done();
  55. }, 10);
  56. });
  57. it('ChangeState method is working', function(done) {
  58. setTimeout(function() {
  59. granimInstance.changeState('default-state');
  60. granimInstance.changeState('second-state');
  61. expect(granimInstance.activeState).toEqual('second-state');
  62. done();
  63. }, 200);
  64. });
  65. it('ChangeDirection method is working', function(done) {
  66. setTimeout(function() {
  67. granimInstance.changeDirection('left-right');
  68. expect(granimInstance.direction).toEqual('left-right');
  69. done();
  70. }, 200);
  71. });
  72. it('Clear method is working', function(done) {
  73. setTimeout(function() {
  74. granimInstance.clear();
  75. expect(granimInstance.context.getImageData(1, 1, 1, 1).data[0]).toEqual(0);
  76. done();
  77. }, 10);
  78. });
  79. it('ChangeDirection should throw an error when passed \'custom\' value without a customDirection object', function(done) {
  80. setTimeout(function() {
  81. var func = function() { return granimInstance.changeDirection('custom'); };
  82. expect(func).toThrowError(errorMessage('customDirection'));
  83. done();
  84. }, 200);
  85. });
  86. it('ChangeDirection should throw an error when passed \'custom\' value with a poorly formatted customDirection object', function(done) {
  87. setTimeout(function() {
  88. granimInstance.customDirection = {
  89. x0: '1px1',
  90. y0: '1px1',
  91. x1: '1%na',
  92. y1: '1%na'
  93. };
  94. var func = function() { return granimInstance.changeDirection('custom'); };
  95. expect(func).toThrowError(errorMessage('customDirection'));
  96. done();
  97. }, 200);
  98. });
  99. it('ChangeDirection should throw an error when passed \'custom\' value with a customDirection object which has number values', function(done) {
  100. setTimeout(function() {
  101. granimInstance.customDirection = {
  102. x0: 0,
  103. y0: 2,
  104. x1: 1,
  105. y1: 3
  106. };
  107. var func = function() { return granimInstance.changeDirection('custom'); };
  108. expect(func).toThrowError(errorMessage('customDirection'));
  109. done();
  110. }, 200);
  111. });
  112. it('ChangeDirection should throw an error when passed \'custom\' value with a customDirection object which has no number values in front of unit', function(done) {
  113. setTimeout(function() {
  114. granimInstance.customDirection = {
  115. x0: 'px',
  116. y0: '%',
  117. x1: 'px',
  118. y1: 'px'
  119. };
  120. var func = function() { return granimInstance.changeDirection('custom'); };
  121. expect(func).toThrowError(errorMessage('customDirection'));
  122. done();
  123. }, 200);
  124. });
  125. it('ChangeDirection should throw an error when passed \'custom\' value with a customDirection object which has only one good value', function(done) {
  126. setTimeout(function() {
  127. granimInstance.customDirection = {
  128. x0: '50px',
  129. y0: '00',
  130. x1: '0',
  131. y1: '0'
  132. };
  133. var func = function() { return granimInstance.changeDirection('custom'); };
  134. expect(func).toThrowError(errorMessage('customDirection'));
  135. done();
  136. }, 200);
  137. });
  138. it('ChangeDirection method to a custom direction with valid \'customDirection\' inputs is working', function(done) {
  139. setTimeout(function() {
  140. granimInstance.customDirection = {
  141. x0: '20%',
  142. y0: '200px',
  143. x1: '30%',
  144. y1: '400px'
  145. };
  146. granimInstance.changeDirection('custom');
  147. expect(granimInstance.direction).toEqual('custom');
  148. done();
  149. }, 200);
  150. });
  151. afterEach(function() {
  152. jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
  153. });
  154. });
  155. });