Advertisement
Guest User

Untitled

a guest
May 4th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. define(function(require) {
  2.  
  3. var BaseView = require('shared/views/BaseView');
  4.  
  5. var template = '\
  6. <div class="title">Click Me</div>\
  7. <div class="js-explanation hidden">\
  8. <p>An explanation</p>\
  9. </div>';
  10.  
  11. return BaseView.extend({
  12. template: template,
  13. events: {
  14. 'click .title': 'toggleExplanation'
  15. },
  16.  
  17. toggleExplanation: function () {
  18. var explainDiv = this.$('.js-explanation');
  19. if (explainDiv.is('.hidden')) {
  20. this._show(explainDiv);
  21. } else {
  22. this._hide(explainDiv);
  23. }
  24. },
  25.  
  26. _show: function (el) {
  27. el.slideDown(350, function() {
  28. el.removeClass('hidden');
  29. el.animate({opacity: 1}, 250);
  30. });
  31. },
  32.  
  33. _hide: function (el) {
  34. el.animate({opacity: 0}, 300, function() {
  35. el.slideUp(400, function () {
  36. el.addClass('hidden');
  37. });
  38. });
  39. }
  40.  
  41. });
  42. });
  43.  
  44. //==================================================
  45. //Test Code
  46.  
  47. describe('toggleExplanation', function () {
  48.  
  49. // THIS WILL SUCCEED
  50. it('is called when a user clicks the subtitle', function () {
  51. var view = new Summary({
  52. state: new StateMachine(),
  53. collection: Mock.Uptime.createCollection()
  54. });
  55. spyOn(view, '_show');
  56. view.render();
  57. view.$('.title').click();
  58. expect(view._show).toHaveBeenCalled();
  59. });
  60.  
  61. // THIS WILL FAIL
  62. it('is called when a user clicks the subtitle', function () {
  63. var view = new Summary({
  64. state: new StateMachine(),
  65. collection: Mock.Uptime.createCollection()
  66. });
  67. spyOn(view, 'toggleExplanation');
  68. view.render();
  69. view.$('.title').click();
  70. expect(view.toggleExplanation).toHaveBeenCalled();
  71. });
  72.  
  73. it('shows the explanation text when its hidden', function () {
  74. var view = new Summary({
  75. state: new StateMachine(),
  76. collection: Mock.Uptime.createCollection()
  77. });
  78. view.render();
  79. spyOn(view, '_show');
  80. view.toggleExplanation();
  81. expect(view._show).toHaveBeenCalled();
  82. });
  83.  
  84. it('hides the explanation text when its shown', function () {
  85. var view = new Summary({
  86. state: new StateMachine(),
  87. collection: Mock.Uptime.createCollection()
  88. });
  89. spyOn(view, '_hide');
  90. view.render();
  91. view.$('.js-explanation').removeClass('hidden');
  92. view.toggleExplanation();
  93. expect(view._hide).toHaveBeenCalled();
  94. });
  95.  
  96. });
  97.  
  98. describe('_hide', function () {
  99.  
  100. it('hides the explanation text', function () {
  101. var view = new Summary({
  102. state: new StateMachine(),
  103. collection: Mock.Uptime.createCollection()
  104. });
  105. view.render();
  106. var div = view.$('.js-explanation');
  107. spyOn(div, 'animate');
  108. view._hide(div);
  109. expect(div.animate).toHaveBeenCalled();
  110. });
  111.  
  112. });
  113.  
  114. describe('_show', function () {
  115.  
  116. it('hides the explanation text', function () {
  117. var view = new Summary({
  118. state: new StateMachine(),
  119. collection: Mock.Uptime.createCollection()
  120. });
  121. view.render();
  122. var div = view.$('.js-explanation');
  123. spyOn(div, 'slideDown');
  124. view._show(div);
  125. expect(div.slideDown).toHaveBeenCalled();
  126. });
  127.  
  128. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement