spinner_input_view_test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. var view;
  20. var e;
  21. function getView() {
  22. return App.SpinnerInputView.create({});
  23. }
  24. describe('App.SpinnerInputView', function () {
  25. beforeEach(function () {
  26. view = getView();
  27. e = {
  28. preventDefault: Em.K
  29. };
  30. sinon.spy(e, 'preventDefault');
  31. });
  32. afterEach(function () {
  33. e.preventDefault.restore();
  34. });
  35. App.TestAliases.testAsComputedOr(getView(), 'computedDisabled', ['!content.enabled', 'disabled']);
  36. describe('#keyDown', function () {
  37. Em.A([
  38. {
  39. charCode: 46,
  40. ctrlKey: true,
  41. e: {
  42. preventDefault: false
  43. }
  44. },
  45. {
  46. charCode: 8,
  47. ctrlKey: true,
  48. e: {
  49. preventDefault: false
  50. }
  51. },
  52. {
  53. charCode: 9,
  54. ctrlKey: true,
  55. e: {
  56. preventDefault: false
  57. }
  58. },
  59. {
  60. charCode: 27,
  61. ctrlKey: true,
  62. e: {
  63. preventDefault: false
  64. }
  65. },
  66. {
  67. charCode: 13,
  68. ctrlKey: true,
  69. e: {
  70. preventDefault: false
  71. }
  72. },
  73. {
  74. charCode: 110,
  75. ctrlKey: true,
  76. e: {
  77. preventDefault: false
  78. }
  79. },
  80. {
  81. charCode: 65,
  82. ctrlKey: true,
  83. e: {
  84. preventDefault: false
  85. }
  86. },
  87. {
  88. charCode: 67,
  89. ctrlKey: true,
  90. e: {
  91. preventDefault: false
  92. }
  93. },
  94. {
  95. charCode: 88,
  96. ctrlKey: true,
  97. e: {
  98. preventDefault: false
  99. }
  100. },
  101. {
  102. charCode: 35,
  103. ctrlKey: true,
  104. e: {
  105. preventDefault: false
  106. }
  107. }
  108. ]).forEach(function (test) {
  109. it('charCode: ' + test.charCode + ', ctrlKey: ' + test.ctrlKey, function () {
  110. e.charCode = test.charCode;
  111. e.ctrlKey = test.ctrlKey;
  112. view.keyDown(e);
  113. expect(e.preventDefault.called).to.equal(test.e.preventDefault);
  114. });
  115. });
  116. Em.A([
  117. {
  118. charCode: 35,
  119. e: {
  120. preventDefault: false
  121. }
  122. },
  123. {
  124. charCode: 36,
  125. e: {
  126. preventDefault: false
  127. }
  128. },
  129. {
  130. charCode: 37,
  131. e: {
  132. preventDefault: false
  133. }
  134. },
  135. {
  136. charCode: 38,
  137. e: {
  138. preventDefault: false
  139. }
  140. },
  141. {
  142. charCode: 39,
  143. e: {
  144. preventDefault: false
  145. }
  146. }
  147. ]).forEach(function (test) {
  148. it('charCode: ' + test.charCode, function () {
  149. e.charCode = test.charCode;
  150. view.keyDown(e);
  151. expect(e.preventDefault.called).to.equal(test.e.preventDefault);
  152. });
  153. });
  154. Em.A([
  155. {
  156. charCode: 190,
  157. shiftKey: false,
  158. e: {
  159. preventDefault: true
  160. }
  161. },
  162. {
  163. charCode: 190,
  164. shiftKey: true,
  165. e: {
  166. preventDefault: true
  167. }
  168. }
  169. ]).forEach(function (test) {
  170. it('charCode: ' + test.charCode + ', shiftKey: ' + test.shiftKey, function () {
  171. e.charCode = test.charCode;
  172. e.shiftKey = test.shiftKey;
  173. view.keyDown(e);
  174. expect(e.preventDefault.calledOnce).to.equal(test.e.preventDefault);
  175. });
  176. });
  177. });
  178. });