maxCols.spec.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. describe('settings', () => {
  2. describe('maxCols', () => {
  3. const id = 'testContainer';
  4. beforeEach(function() {
  5. this.$container = $(`<div id="${id}"></div>`).appendTo('body');
  6. });
  7. afterEach(function() {
  8. if (this.$container) {
  9. destroy();
  10. this.$container.remove();
  11. }
  12. });
  13. describe('works on init', () => {
  14. it('should show data properly when `maxCols` is set to 0', () => {
  15. handsontable({
  16. data: Handsontable.helper.createSpreadsheetData(10, 10),
  17. maxCols: 0
  18. });
  19. expect(getSourceDataAtRow(0).length).toEqual(10);
  20. expect(countSourceCols()).toEqual(10);
  21. expect(getData().length).toEqual(0);
  22. expect(getDataAtRow(0)).toEqual([]);
  23. expect(countCols()).toEqual(0);
  24. expect(countEmptyCols()).toEqual(0);
  25. expect(getDataAtCol(0)).toEqual([]);
  26. expect(getDataAtCol(1)).toEqual([]);
  27. });
  28. it('should show data properly when `maxCols` is set to value > 0', () => {
  29. handsontable({
  30. data: Handsontable.helper.createSpreadsheetData(10, 10),
  31. maxCols: 5
  32. });
  33. expect(getSourceDataAtRow(0).length).toEqual(10);
  34. expect(countSourceCols()).toEqual(10);
  35. expect(getData()[0].length).toEqual(5);
  36. expect(getDataAtRow(0).length).toEqual(5);
  37. expect(countCols()).toEqual(5);
  38. expect(countEmptyCols()).toEqual(0);
  39. expect(getDataAtCol(6)).toEqual([]);
  40. });
  41. it('should show data properly when `maxCols` is set to infinity value', () => {
  42. handsontable({
  43. data: Handsontable.helper.createSpreadsheetData(10, 10),
  44. maxCols: Infinity
  45. });
  46. expect(getSourceDataAtRow(0).length).toEqual(10);
  47. expect(countSourceCols()).toEqual(10);
  48. expect(getData()[0].length).toEqual(10);
  49. expect(getDataAtRow(0).length).toEqual(10);
  50. expect(countCols()).toEqual(10);
  51. expect(countEmptyCols()).toEqual(0);
  52. expect(getDataAtCol(0)).toEqual(['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10']);
  53. });
  54. describe('when `columns` property was set', () => {
  55. it('should show data properly when `maxCols` is set to value > 0', () => {
  56. handsontable({
  57. columns: [
  58. {type: 'text'},
  59. {type: 'text'},
  60. {type: 'text'},
  61. {type: 'text'},
  62. {type: 'text'},
  63. ],
  64. minRows: 10,
  65. maxCols: 2
  66. });
  67. expect(getSourceDataAtRow(0).length).toEqual(5);
  68. expect(countSourceCols()).toEqual(5);
  69. expect(getData()[0].length).toEqual(2);
  70. expect(getDataAtRow(0).length).toEqual(2);
  71. expect(countCols()).toEqual(2);
  72. expect(getDataAtCol(3)).toEqual([]);
  73. });
  74. });
  75. });
  76. describe('update settings works', () => {
  77. it('should show data properly after maxCols is updated to 0', () => {
  78. handsontable({
  79. data: Handsontable.helper.createSpreadsheetData(10, 10)
  80. });
  81. updateSettings({
  82. maxCols: 0
  83. });
  84. expect(getSourceDataAtRow(0).length).toEqual(10);
  85. expect(countSourceCols()).toEqual(10);
  86. expect(getData().length).toEqual(0);
  87. expect(getDataAtRow(0)).toEqual([]);
  88. expect(countCols()).toEqual(0);
  89. expect(getDataAtCol(0)).toEqual([]);
  90. expect(getDataAtCol(1)).toEqual([]);
  91. });
  92. it('should show data properly after maxCols is updated to value > 0 -> test no. 1', () => {
  93. handsontable({
  94. data: Handsontable.helper.createSpreadsheetData(10, 10)
  95. });
  96. updateSettings({
  97. maxCols: 2
  98. });
  99. expect(getSourceDataAtRow(0).length).toEqual(10);
  100. expect(countSourceCols()).toEqual(10);
  101. expect(getData()[0].length).toEqual(2);
  102. expect(getDataAtRow(0).length).toEqual(2);
  103. expect(countCols()).toEqual(2);
  104. expect(countEmptyCols()).toEqual(0);
  105. expect(getDataAtCol(3)).toEqual([]);
  106. });
  107. it('should show data properly after maxCols is updated to value > 0 -> test no. 2', () => {
  108. handsontable({
  109. data: Handsontable.helper.createSpreadsheetData(10, 10),
  110. maxCols: 5
  111. });
  112. updateSettings({
  113. maxCols: 2
  114. });
  115. expect(getSourceDataAtRow(0).length).toEqual(10);
  116. expect(countSourceCols()).toEqual(10);
  117. expect(getData()[0].length).toEqual(2);
  118. expect(getDataAtRow(0).length).toEqual(2);
  119. expect(countCols()).toEqual(2);
  120. expect(countEmptyCols()).toEqual(0);
  121. expect(getDataAtCol(3)).toEqual([]);
  122. });
  123. it('should show data properly after maxCols is updated to value > 0 -> test no. 3', () => {
  124. handsontable({
  125. data: Handsontable.helper.createSpreadsheetData(10, 10),
  126. maxCols: 2
  127. });
  128. updateSettings({
  129. maxCols: 5
  130. });
  131. expect(getSourceDataAtRow(0).length).toEqual(10);
  132. expect(countSourceCols()).toEqual(10);
  133. expect(getData()[0].length).toEqual(5);
  134. expect(getDataAtRow(0).length).toEqual(5);
  135. expect(countCols()).toEqual(5);
  136. expect(countEmptyCols()).toEqual(0);
  137. expect(getDataAtCol(6)).toEqual([]);
  138. });
  139. it('should show data properly after maxCols is updated to infinity value -> test no. 1', () => {
  140. handsontable({
  141. data: Handsontable.helper.createSpreadsheetData(10, 10)
  142. });
  143. updateSettings({
  144. maxCols: Infinity
  145. });
  146. expect(getSourceDataAtRow(0).length).toEqual(10);
  147. expect(countSourceCols()).toEqual(10);
  148. expect(getData()[0].length).toEqual(10);
  149. expect(getDataAtRow(0).length).toEqual(10);
  150. expect(countCols()).toEqual(10);
  151. expect(countEmptyCols()).toEqual(0);
  152. expect(getDataAtCol(0)).toEqual(['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10']);
  153. });
  154. it('should show data properly after maxCols is updated to infinity value -> test no. 2', () => {
  155. handsontable({
  156. data: Handsontable.helper.createSpreadsheetData(10, 10),
  157. maxCols: 2
  158. });
  159. updateSettings({
  160. maxCols: Infinity
  161. });
  162. expect(getSourceDataAtRow(0).length).toEqual(10);
  163. expect(countSourceCols()).toEqual(10);
  164. expect(getData()[0].length).toEqual(10);
  165. expect(getDataAtRow(0).length).toEqual(10);
  166. expect(countCols()).toEqual(10);
  167. expect(countEmptyCols()).toEqual(0);
  168. expect(getDataAtCol(0)).toEqual(['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10']);
  169. });
  170. describe('works when `columns` property was set', () => {
  171. it('should show data properly when `maxCols` is updated to value > 0', () => {
  172. handsontable({
  173. columns: [
  174. {type: 'text'},
  175. {type: 'text'},
  176. {type: 'text'},
  177. {type: 'text'},
  178. {type: 'text'},
  179. ],
  180. minRows: 10
  181. });
  182. updateSettings({
  183. maxCols: 2
  184. });
  185. expect(getSourceDataAtRow(0).length).toEqual(5);
  186. expect(countSourceCols()).toEqual(5);
  187. expect(getData()[0].length).toEqual(2);
  188. expect(getDataAtRow(0).length).toEqual(2);
  189. expect(countCols()).toEqual(2);
  190. expect(getDataAtCol(0).length).toEqual(10);
  191. });
  192. });
  193. });
  194. });
  195. });