4de4fe13102c3fef1a617eb07dddd775617bf88f3d25fb1399557c7847c2360ae8fae8fb2e2d14f2526598f2c6ed5d2d00d4e744e27fc23ecc461e3da1306e 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. describe('Core_navigation', () => {
  2. var id = 'testContainer';
  3. beforeEach(function() {
  4. this.$container = $(`<div id="${id}"></div>`).appendTo('body');
  5. });
  6. afterEach(function() {
  7. if (this.$container) {
  8. destroy();
  9. this.$container.remove();
  10. }
  11. });
  12. it('should move to the next cell', () => {
  13. handsontable({
  14. startRows: 5,
  15. startCols: 5
  16. });
  17. selectCell(0, 0);
  18. keyDown('arrow_right');
  19. expect(getSelected()).toEqual([0, 1, 0, 1]);
  20. });
  21. it('should move to the previous cell', () => {
  22. handsontable({
  23. startRows: 5,
  24. startCols: 5
  25. });
  26. selectCell(1, 2);
  27. keyDown('arrow_left');
  28. expect(getSelected()).toEqual([1, 1, 1, 1]);
  29. });
  30. it('should move to the cell above', () => {
  31. handsontable({
  32. startRows: 5,
  33. startCols: 5
  34. });
  35. selectCell(1, 2);
  36. keyDown('arrow_up');
  37. expect(getSelected()).toEqual([0, 2, 0, 2]);
  38. });
  39. it('should move to the cell below', () => {
  40. handsontable({
  41. startRows: 5,
  42. startCols: 5
  43. });
  44. selectCell(1, 2);
  45. keyDown('arrow_down');
  46. expect(getSelected()).toEqual([2, 2, 2, 2]);
  47. });
  48. describe('autoWrap disabled', () => {
  49. it('should NOT move to the next cell, if already at the last cell in row', () => {
  50. handsontable({
  51. startRows: 5,
  52. startCols: 5,
  53. autoWrapRow: false
  54. });
  55. selectCell(0, 4);
  56. keyDown('arrow_right');
  57. expect(getSelected()).toEqual([0, 4, 0, 4]);
  58. });
  59. it('should NOT move to the previous cell, if already at the first cell in row', () => {
  60. handsontable({
  61. startRows: 5,
  62. startCols: 5,
  63. autoWrapRow: false
  64. });
  65. selectCell(1, 0);
  66. keyDown('arrow_left');
  67. expect(getSelected()).toEqual([1, 0, 1, 0]);
  68. });
  69. it('should NOT move to the cell below, if already at the last cell in column', () => {
  70. handsontable({
  71. startRows: 5,
  72. startCols: 5,
  73. autoWrapCol: false
  74. });
  75. selectCell(4, 0);
  76. keyDown('arrow_down');
  77. expect(getSelected()).toEqual([4, 0, 4, 0]);
  78. });
  79. it('should NOT move to the cell above, if already at the first cell in column', () => {
  80. handsontable({
  81. startRows: 5,
  82. startCols: 5,
  83. autoWrapCol: false
  84. });
  85. selectCell(0, 1);
  86. keyDown('arrow_up');
  87. expect(getSelected()).toEqual([0, 1, 0, 1]);
  88. });
  89. });
  90. describe('autoWrap enabled', () => {
  91. it('should move to the first cell of the next row, if already at the last cell in row', () => {
  92. handsontable({
  93. startRows: 5,
  94. startCols: 5,
  95. autoWrapRow: true
  96. });
  97. selectCell(0, 4);
  98. keyDown('arrow_right');
  99. expect(getSelected()).toEqual([1, 0, 1, 0]);
  100. });
  101. it('should move to the first cell of the previous row, if already at the first cell in row', () => {
  102. handsontable({
  103. startRows: 5,
  104. startCols: 5,
  105. autoWrapRow: true
  106. });
  107. selectCell(1, 0);
  108. keyDown('arrow_left');
  109. expect(getSelected()).toEqual([0, 4, 0, 4]);
  110. });
  111. it('should move to the first cell of the next column, if already at the last cell in column', () => {
  112. handsontable({
  113. startRows: 5,
  114. startCols: 5,
  115. autoWrapCol: true
  116. });
  117. selectCell(4, 1);
  118. keyDown('arrow_down');
  119. expect(getSelected()).toEqual([0, 2, 0, 2]);
  120. });
  121. it('should move to the last cell of the previous column, if already at the first cell in column', () => {
  122. handsontable({
  123. startRows: 5,
  124. startCols: 5,
  125. autoWrapCol: true
  126. });
  127. selectCell(0, 1);
  128. keyDown('arrow_up');
  129. expect(getSelected()).toEqual([4, 0, 4, 0]);
  130. });
  131. it('should move to the first cell of the first row, after trying to get to the next cell in row, being already at the last cell in table', () => {
  132. handsontable({
  133. startRows: 5,
  134. startCols: 5,
  135. autoWrapRow: true
  136. });
  137. selectCell(4, 4);
  138. keyDown('arrow_right');
  139. expect(getSelected()).toEqual([0, 0, 0, 0]);
  140. });
  141. it('should move to the first cell of the first row, after trying to get to the next cell in column, being already at the last cell in table', () => {
  142. handsontable({
  143. startRows: 5,
  144. startCols: 5,
  145. autoWrapCol: true
  146. });
  147. selectCell(4, 4);
  148. keyDown('arrow_down');
  149. expect(getSelected()).toEqual([0, 0, 0, 0]);
  150. });
  151. it('should move to the last cell of the last row, after trying to get to the previous cell in row, being already at the first cell in table', () => {
  152. handsontable({
  153. startRows: 5,
  154. startCols: 5,
  155. autoWrapRow: true
  156. });
  157. selectCell(0, 0);
  158. keyDown('arrow_left');
  159. expect(getSelected()).toEqual([4, 4, 4, 4]);
  160. });
  161. it('should move to the last cell of the last row, after trying to get to the previous cell in column, being already at the first cell in table', () => {
  162. handsontable({
  163. startRows: 5,
  164. startCols: 5,
  165. autoWrapCol: true
  166. });
  167. selectCell(0, 0);
  168. keyDown('arrow_up');
  169. expect(getSelected()).toEqual([4, 4, 4, 4]);
  170. });
  171. it('should traverse whole table by constantly selecting next cell in row', () => {
  172. handsontable({
  173. startRows: 5,
  174. startCols: 5,
  175. autoWrapRow: true
  176. });
  177. selectCell(0, 0);
  178. for (var row = 0, rlen = countRows(); row < rlen; row++) {
  179. for (var col = 0, clen = countCols(); col < clen; col++) {
  180. expect(getSelected()).toEqual([row, col, row, col]);
  181. keyDown('arrow_right');
  182. }
  183. }
  184. expect(getSelected()).toEqual([0, 0, 0, 0]);
  185. });
  186. it('should traverse whole table by constantly selecting previous cell in row', () => {
  187. handsontable({
  188. startRows: 5,
  189. startCols: 5,
  190. autoWrapRow: true
  191. });
  192. selectCell(4, 4);
  193. for (var row = countRows() - 1; row >= 0; row--) {
  194. for (var col = countCols() - 1; col >= 0; col--) {
  195. expect(getSelected()).toEqual([row, col, row, col]);
  196. keyDown('arrow_left');
  197. }
  198. }
  199. expect(getSelected()).toEqual([4, 4, 4, 4]);
  200. });
  201. it('should traverse whole table by constantly selecting next cell in column', () => {
  202. handsontable({
  203. startRows: 5,
  204. startCols: 5,
  205. autoWrapCol: true
  206. });
  207. selectCell(0, 0);
  208. for (var col = 0, clen = countCols(); col < clen; col++) {
  209. for (var row = 0, rlen = countRows(); row < rlen; row++) {
  210. expect(getSelected()).toEqual([row, col, row, col]);
  211. keyDown('arrow_down');
  212. }
  213. }
  214. expect(getSelected()).toEqual([0, 0, 0, 0]);
  215. });
  216. it('should traverse whole table by constantly selecting previous cell in column', () => {
  217. handsontable({
  218. startRows: 5,
  219. startCols: 5,
  220. autoWrapCol: true
  221. });
  222. selectCell(4, 4);
  223. for (var col = countCols() - 1; col >= 0; col--) {
  224. for (var row = countRows() - 1; row >= 0; row--) {
  225. expect(getSelected()).toEqual([row, col, row, col]);
  226. keyDown('arrow_up');
  227. }
  228. }
  229. expect(getSelected()).toEqual([4, 4, 4, 4]);
  230. });
  231. });
  232. });