application_test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('views/application');
  20. var view,
  21. modals = [],
  22. removed = false,
  23. events = [
  24. {
  25. event: 'keyup',
  26. which: 27,
  27. key: 'Esc',
  28. html: '<div id="modal"><div class="modal-header"><span class="close"></span></div></div>',
  29. particle: '',
  30. length: 0
  31. },
  32. {
  33. event: 'keyup',
  34. keyCode: 27,
  35. key: 'Esc',
  36. html: '<div id="modal"><div class="modal-header"><span class="close"></span></div></div>',
  37. particle: '',
  38. length: 0
  39. },
  40. {
  41. event: 'keydown',
  42. which: 13,
  43. key: 'Enter',
  44. html: '<div id="modal"><div class="modal-footer"><span></span></div></div>',
  45. particle: 'not ',
  46. length: 1
  47. },
  48. {
  49. event: 'keydown',
  50. keyCode: 13,
  51. key: 'Enter',
  52. html: '<div id="modal"><div class="modal-footer"><span></span></div></div>',
  53. particle: 'not ',
  54. length: 1
  55. },
  56. {
  57. event: 'keyup',
  58. which: 27,
  59. key: 'Esc',
  60. html: '<div id="modal"><div class="modal-header"><span></span></div></div>',
  61. particle: 'not ',
  62. length: 1
  63. },
  64. {
  65. event: 'keyup',
  66. keyCode: 27,
  67. key: 'Esc',
  68. html: '<div id="modal"><div class="modal-header"><span></span></div></div>',
  69. particle: 'not ',
  70. length: 1
  71. },
  72. {
  73. event: 'keydown',
  74. which: 13,
  75. key: 'Enter',
  76. html: '<div id="modal"><div class="modal-footer"><span class="btn-success" disabled="disabled"></span></div></div>',
  77. particle: 'not ',
  78. length: 1
  79. },
  80. {
  81. event: 'keydown',
  82. keyCode: 13,
  83. key: 'Enter',
  84. html: '<div id="modal"><div class="modal-footer"><span class="btn-success" disabled="disabled"></span></div></div>',
  85. particle: 'not ',
  86. length: 1
  87. },
  88. {
  89. event: 'keydown',
  90. key: 'Enter',
  91. html: '<div id="modal"><div class="modal-footer"><span class="btn-success"></span></div></div>',
  92. particle: 'not ',
  93. length: 1
  94. },
  95. {
  96. event: 'keyup',
  97. key: 'Esc',
  98. html: '<div id="modal"><div class="modal-footer"><span class="close"></span></div></div>',
  99. particle: 'not ',
  100. length: 1
  101. }
  102. ];
  103. describe.skip('App.ApplicationView', function () {
  104. before(function () {
  105. if($('#modal').length) {
  106. removed = true;
  107. }
  108. while($('#modal').length) {
  109. modals.push({
  110. modal: $('#modal'),
  111. parent: $('modal').parent()
  112. });
  113. $('#modal').remove();
  114. }
  115. });
  116. beforeEach(function () {
  117. view = App.ApplicationView.create({
  118. template: null
  119. });
  120. });
  121. afterEach(function () {
  122. $('#modal').remove();
  123. });
  124. after(function () {
  125. if (removed) {
  126. modals.forEach(function (item) {
  127. item.parent.append(item.modal);
  128. });
  129. }
  130. });
  131. describe('#didInsertElement', function () {
  132. events.forEach(function (item) {
  133. it('should ' + item.particle + 'close modal window on ' + item.key + ' press', function () {
  134. $('body').append(item.html);
  135. $('span').click(function () {
  136. $('#modal').remove();
  137. });
  138. view.didInsertElement();
  139. var e = $.Event(item.event);
  140. e.which = item.which;
  141. e.keyCode = item.keyCode;
  142. $(document).trigger(e);
  143. expect($('#modal')).to.have.length(item.length);
  144. });
  145. });
  146. });
  147. });