cellDecorator.spec.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. describe('CellDecorator', () => {
  2. const 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. const arrayOfObjects = function() {
  13. return [
  14. { id: 1, name: 'Ted', lastName: 'Right' },
  15. { id: 2, name: 'Frank', lastName: 'Honest' },
  16. { id: 3, name: 'Joan', lastName: 'Well' }
  17. ];
  18. };
  19. it('should add an appropriate class name to every cell, if wordWrap=false is set to the whole table', () => {
  20. const hot = handsontable({
  21. data: arrayOfObjects(),
  22. columns: [
  23. { data: 'id' },
  24. { data: 'name' },
  25. { data: 'lastName' }
  26. ],
  27. wordWrap: false
  28. });
  29. const cols = countCols();
  30. const rows = countRows();
  31. for (let i = 0; i < cols; i++) {
  32. for (let j = 0; j < rows; j++) {
  33. expect($(getCell(i, j)).hasClass(hot.getSettings().noWordWrapClassName)).toBe(true);
  34. }
  35. }
  36. });
  37. it('should add an appropriate class name to every cell in a column, if wordWrap=false is set to the column settings', () => {
  38. const hot = handsontable({
  39. data: arrayOfObjects(),
  40. columns: [
  41. { data: 'id' },
  42. { data: 'name', wordWrap: false },
  43. { data: 'lastName' }
  44. ]
  45. });
  46. const rows = countRows();
  47. for (let i = 0; i < rows; i++) {
  48. expect($(getCell(i, 1)).hasClass(hot.getSettings().noWordWrapClassName)).toBe(true);
  49. }
  50. for (let i = 0; i < rows; i++) {
  51. expect($(getCell(i, 0)).hasClass(hot.getSettings().noWordWrapClassName)).toBe(false); // no class added to other columns
  52. expect($(getCell(i, 2)).hasClass(hot.getSettings().noWordWrapClassName)).toBe(false);
  53. }
  54. });
  55. it('should add an appropriate class to a cell, if wordWrap=false is set to a single cell', () => {
  56. const hot = handsontable({
  57. data: arrayOfObjects(),
  58. columns: [
  59. { data: 'id' },
  60. { data: 'name' },
  61. { data: 'lastName' }
  62. ]
  63. });
  64. expect($(getCell(1, 1)).hasClass(hot.getSettings().noWordWrapClassName)).toBe(false);
  65. getCellMeta(1, 1).wordWrap = false;
  66. render();
  67. expect($(getCell(1, 1)).hasClass(hot.getSettings().noWordWrapClassName)).toBe(true);
  68. });
  69. it('should set "white-space" css parameter to "nowrap" if htNoWrap class is added to a cell', () => {
  70. handsontable({
  71. data: arrayOfObjects(),
  72. columns: [
  73. { data: 'id' },
  74. { data: 'name' },
  75. { data: 'lastName' }
  76. ]
  77. });
  78. expect(window.getComputedStyle(getCell(1, 1)).whiteSpace).not.toEqual('nowrap');
  79. getCellMeta(1, 1).wordWrap = false;
  80. render();
  81. expect(window.getComputedStyle(getCell(1, 1)).whiteSpace).toEqual('nowrap');
  82. });
  83. it('should not add cell `htInvalid` class when trying to add not proper value', (done) => {
  84. const hot = handsontable({
  85. data: arrayOfObjects(),
  86. columns: [
  87. { data: 'id' },
  88. { data: 'name' },
  89. { data: 'salary', type: 'numeric', allowInvalid: false }
  90. ]
  91. });
  92. setDataAtCell(0, 2, 'non-numeric value');
  93. setTimeout(() => {
  94. expect($(getCell(0, 2)).hasClass(hot.getSettings().invalidCellClassName)).toBe(false);
  95. done();
  96. }, 200);
  97. });
  98. });