43eb3e0a6a09801d557b2ef4a922ed74863ac29e303349e3c57be9d3f2db52975e0a15abb569edc409345609992af729ec3b27e6f0b55a98ff67be9a8130f4 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. describe('Core.setCellMeta', () => {
  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. it('should set correct meta className for cell', () => {
  13. const className = 'htCenter htMiddle';
  14. handsontable({
  15. afterCellMetaReset() {
  16. this.setCellMeta(0, 0, 'className', className);
  17. }
  18. });
  19. let cellMeta = getCellMeta(0, 0);
  20. expect(cellMeta.className).not.toBeUndefined();
  21. expect(cellMeta.className).toEqual(className);
  22. });
  23. it('should set correct meta className for non existed cell', () => {
  24. const className = 'htCenter htMiddle';
  25. handsontable({
  26. data: Handsontable.helper.createSpreadsheetData(5, 5),
  27. afterCellMetaReset() {
  28. this.setCellMeta(100, 100, 'className', className);
  29. }
  30. });
  31. let cellMeta = getCellMeta(100, 100);
  32. expect(cellMeta.className).not.toBeUndefined();
  33. expect(cellMeta.className).toEqual(className);
  34. });
  35. it('should set correct meta classNames for cells using cell in configuration', function() {
  36. const classNames = [
  37. 'htCenter htTop',
  38. 'htRight htBottom'
  39. ];
  40. handsontable({
  41. cell: [
  42. {row: 0, col: 0, className: classNames[0] },
  43. {row: 1, col: 1, className: classNames[1] }
  44. ]
  45. });
  46. expect(this.$container.find('tbody tr:eq(0) td:eq(0)')[0].className).toEqual(classNames[0]);
  47. expect(this.$container.find('tbody tr:eq(1) td:eq(1)')[0].className).toEqual(classNames[1]);
  48. });
  49. it('should change cell meta data with updateSettings when the cell option is defined', function() {
  50. const classNames = [
  51. 'htCenter htTop',
  52. 'htRight htBottom'
  53. ];
  54. handsontable({
  55. cell: [
  56. {row: 0, col: 0, className: classNames[0] },
  57. {row: 1, col: 1, className: classNames[1] }
  58. ]
  59. });
  60. expect(this.$container.find('tbody tr:eq(0) td:eq(0)')[0].className).toEqual(classNames[0]);
  61. expect(this.$container.find('tbody tr:eq(1) td:eq(1)')[0].className).toEqual(classNames[1]);
  62. updateSettings({
  63. cell: []
  64. });
  65. expect(this.$container.find('tbody tr:eq(0) td:eq(0)')[0].className).toEqual('');
  66. expect(this.$container.find('tbody tr:eq(1) td:eq(1)')[0].className).toEqual('');
  67. updateSettings({
  68. cell: [
  69. {row: 0, col: 0, className: classNames[1] },
  70. {row: 1, col: 1, className: classNames[0] }
  71. ]
  72. });
  73. expect(this.$container.find('tbody tr:eq(0) td:eq(0)')[0].className).toEqual(classNames[1]);
  74. expect(this.$container.find('tbody tr:eq(1) td:eq(1)')[0].className).toEqual(classNames[0]);
  75. });
  76. it('should call afterSetCellMeta plugin hook', () => {
  77. const className = 'htCenter htMiddle';
  78. let res = {};
  79. handsontable({
  80. afterCellMetaReset() {
  81. this.setCellMeta(0, 1, 'className', className);
  82. },
  83. afterSetCellMeta(row, col, key, val) {
  84. res.row = row;
  85. res.col = col;
  86. res.key = key;
  87. res.val = val;
  88. }
  89. });
  90. expect(res.row).toEqual(0);
  91. expect(res.col).toEqual(1);
  92. expect(res.key).toEqual('className');
  93. expect(res.val).toEqual(className);
  94. });
  95. });