colWidths.spec.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. describe('settings', () => {
  2. describe('colWidths', () => {
  3. var 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('defined in constructor', () => {
  14. it('should consider colWidths provided as number', function() {
  15. handsontable({
  16. colWidths: 123
  17. });
  18. expect(colWidth(this.$container, 0)).toBe(123);
  19. });
  20. it('should consider colWidths provided as string', function() {
  21. handsontable({
  22. colWidths: '123'
  23. });
  24. expect(colWidth(this.$container, 0)).toBe(123);
  25. });
  26. it('should consider colWidths provided as array of numbers', function() {
  27. handsontable({
  28. colWidths: [123]
  29. });
  30. expect(colWidth(this.$container, 0)).toBe(123);
  31. });
  32. it('should consider colWidths provided as array of strings', function() {
  33. handsontable({
  34. colWidths: ['123']
  35. });
  36. expect(colWidth(this.$container, 0)).toBe(123);
  37. });
  38. it('should consider colWidth provided as function that returns number', function() {
  39. handsontable({
  40. colWidths(index) {
  41. if (index === 0) {
  42. return 123;
  43. }
  44. return 50;
  45. }
  46. });
  47. expect(colWidth(this.$container, 0)).toBe(123);
  48. });
  49. it('should consider colWidth provided as function that returns string', function() {
  50. handsontable({
  51. colWidths(index) {
  52. if (index === 0) {
  53. return '123';
  54. }
  55. return '50';
  56. }
  57. });
  58. expect(colWidth(this.$container, 0)).toBe(123);
  59. });
  60. });
  61. describe('defined in updateSettings', () => {
  62. it('should consider colWidths provided as number', function() {
  63. handsontable();
  64. updateSettings({
  65. colWidths: 123
  66. });
  67. expect(colWidth(this.$container, 0)).toBe(123);
  68. });
  69. it('should consider colWidths provided as string', function() {
  70. handsontable();
  71. updateSettings({
  72. colWidths: '123'
  73. });
  74. expect(colWidth(this.$container, 0)).toBe(123);
  75. });
  76. it('should consider colWidths provided as array of numbers', function() {
  77. handsontable();
  78. updateSettings({
  79. colWidths: [123]
  80. });
  81. expect(colWidth(this.$container, 0)).toBe(123);
  82. });
  83. it('should consider colWidths provided as array of strings', function() {
  84. handsontable();
  85. updateSettings({
  86. colWidths: ['123']
  87. });
  88. expect(colWidth(this.$container, 0)).toBe(123);
  89. });
  90. it('should consider colWidth provided as function that returns number', function() {
  91. handsontable();
  92. updateSettings({
  93. colWidths(index) {
  94. if (index === 0) {
  95. return 123;
  96. }
  97. return 50;
  98. }
  99. });
  100. expect(colWidth(this.$container, 0)).toBe(123);
  101. });
  102. it('should consider colWidth provided as function that returns string', function() {
  103. handsontable();
  104. updateSettings({
  105. colWidths(index) {
  106. if (index === 0) {
  107. return '123';
  108. }
  109. return '50';
  110. }
  111. });
  112. expect(colWidth(this.$container, 0)).toBe(123);
  113. });
  114. });
  115. describe('defined in columns', () => {
  116. it('should consider width provided as number', function() {
  117. handsontable({
  118. columns: [
  119. {
  120. width: 123
  121. }
  122. ]
  123. });
  124. expect(colWidth(this.$container, 0)).toBe(123);
  125. });
  126. it('should consider width provided as string', function() {
  127. handsontable({
  128. columns: [
  129. {
  130. width: '123'
  131. }
  132. ]
  133. });
  134. expect(colWidth(this.$container, 0)).toBe(123);
  135. });
  136. it('should consider width provided as array of numbers', function() {
  137. handsontable({
  138. columns: [
  139. {
  140. width: [123]
  141. }
  142. ]
  143. });
  144. expect(colWidth(this.$container, 0)).toBe(123);
  145. });
  146. it('should consider width provided as array of strings', function() {
  147. handsontable({
  148. columns: [
  149. {
  150. width: ['123']
  151. }
  152. ]
  153. });
  154. expect(colWidth(this.$container, 0)).toBe(123);
  155. });
  156. it('should consider width provided as function that returns number', function() {
  157. handsontable({
  158. columns: [
  159. {
  160. width(index) {
  161. if (index === 0) {
  162. return 123;
  163. }
  164. return 50;
  165. }
  166. }
  167. ]
  168. });
  169. expect(colWidth(this.$container, 0)).toBe(123);
  170. });
  171. it('should consider width provided as function that returns string', function() {
  172. handsontable({
  173. columns: [
  174. {
  175. width(index) {
  176. if (index === 0) {
  177. return '123';
  178. }
  179. return '50';
  180. }
  181. }
  182. ]
  183. });
  184. expect(colWidth(this.$container, 0)).toBe(123);
  185. });
  186. });
  187. describe('defined in cells', () => {
  188. it('should consider width provided as number', function() {
  189. handsontable({
  190. cells(row, col) {
  191. if (col === 0) {
  192. this.width = 123;
  193. }
  194. }
  195. });
  196. expect(colWidth(this.$container, 0)).toBe(123);
  197. });
  198. it('should consider width provided as string', function() {
  199. handsontable({
  200. cells(row, col) {
  201. if (col === 0) {
  202. this.width = '123';
  203. }
  204. }
  205. });
  206. expect(colWidth(this.$container, 0)).toBe(123);
  207. });
  208. });
  209. });
  210. });