1fb03b6927f38b65c655dd86acf694489a9f3ef656c0782a8869f68c4708c84ba1b2c3d4654eae18df9fcf174a3f54defa9245e2b656b988491ccd2b19080c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. describe('Core_getCellMeta', () => {
  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 not allow manual editing of a read only cell', () => {
  13. var allCellsReadOnly = false;
  14. handsontable({
  15. cells() {
  16. return {readOnly: allCellsReadOnly};
  17. }
  18. });
  19. allCellsReadOnly = true;
  20. selectCell(2, 2);
  21. keyDown('enter');
  22. expect(isEditorVisible()).toEqual(false);
  23. });
  24. it('should allow manual editing of cell that is no longer read only', () => {
  25. var allCellsReadOnly = true;
  26. handsontable({
  27. cells() {
  28. return {readOnly: allCellsReadOnly};
  29. }
  30. });
  31. allCellsReadOnly = false;
  32. selectCell(2, 2);
  33. keyDown('enter');
  34. expect(isEditorVisible()).toEqual(true);
  35. });
  36. it('should move the selection to the cell below, when hitting the ENTER key on a read-only cell', () => {
  37. handsontable({
  38. data: Handsontable.helper.createSpreadsheetData(3, 3),
  39. cells() {
  40. return {readOnly: true};
  41. }
  42. });
  43. selectCell(0, 0);
  44. expect(getCellMeta(0, 0).readOnly).toBe(true);
  45. keyDown('enter');
  46. expect(getSelected()).toEqual([1, 0, 1, 0]);
  47. });
  48. it('should use default cell editor for a cell that has declared only cell renderer', () => {
  49. handsontable({
  50. cells() {
  51. return {
  52. renderer(instance, td, row, col, prop, value, cellProperties) {
  53. // taken from demo/renderers.html
  54. Handsontable.renderers.TextRenderer.apply(this, arguments);
  55. $(td).css({
  56. background: 'yellow'
  57. });
  58. }
  59. };
  60. }
  61. });
  62. selectCell(2, 2);
  63. keyDown('enter');
  64. document.activeElement.value = 'new value';
  65. destroyEditor();
  66. expect(getDataAtCell(2, 2)).toEqual('new value');
  67. });
  68. it('should allow to use type and renderer in `flat` notation', () => {
  69. handsontable({
  70. data: [
  71. [1, 2, 3, 4],
  72. [5, 6, 7, 8],
  73. [0, 9, 8, 7]
  74. ],
  75. cells(row, col) {
  76. if (row === 2 && col === 2) {
  77. return {
  78. type: 'checkbox',
  79. renderer(instance, td, row, col, prop, value, cellProperties) {
  80. // taken from demo/renderers.html
  81. Handsontable.renderers.TextRenderer.apply(this, arguments);
  82. td.style.backgroundColor = 'yellow';
  83. }
  84. };
  85. }
  86. }
  87. });
  88. expect(getCell(2, 2).style.backgroundColor).toEqual('yellow');
  89. expect(getCell(1, 1).style.backgroundColor).toEqual('');
  90. });
  91. it('this in cells should point to cellProperties', () => {
  92. var called = 0,
  93. _row,
  94. _this;
  95. handsontable({
  96. cells(row, col, prop) {
  97. called++;
  98. _row = row;
  99. _this = this;
  100. }
  101. });
  102. var HOT = getInstance();
  103. expect(called).toBeGreaterThan(0);
  104. expect(_this.row).toEqual(_row);
  105. expect(_this.instance).toBe(HOT);
  106. });
  107. it('should get proper cellProperties when order of displayed rows is different than order of stored data', function() {
  108. var hot = handsontable({
  109. data: [
  110. ['C'],
  111. ['A'],
  112. ['B']
  113. ],
  114. minSpareRows: 1,
  115. cells(row, col, prop) {
  116. var cellProperties = {};
  117. if (getSourceData()[row][col] === 'A') {
  118. cellProperties.readOnly = true;
  119. }
  120. return cellProperties;
  121. }
  122. });
  123. expect(this.$container.find('tbody tr:eq(0) td:eq(0)').text()).toEqual('C');
  124. expect(this.$container.find('tbody tr:eq(0) td:eq(0)').hasClass('htDimmed')).toBe(false);
  125. expect(this.$container.find('tbody tr:eq(1) td:eq(0)').text()).toEqual('A');
  126. expect(this.$container.find('tbody tr:eq(1) td:eq(0)').hasClass('htDimmed')).toBe(true);
  127. expect(this.$container.find('tbody tr:eq(2) td:eq(0)').text()).toEqual('B');
  128. expect(this.$container.find('tbody tr:eq(2) td:eq(0)').hasClass('htDimmed')).toBe(false);
  129. // Column sorting changes the order of displayed rows while keeping table data unchanged
  130. updateSettings({
  131. columnSorting: {
  132. column: 0,
  133. sortOrder: true
  134. }
  135. });
  136. expect(this.$container.find('tbody tr:eq(0) td:eq(0)').text()).toEqual('A');
  137. expect(this.$container.find('tbody tr:eq(0) td:eq(0)').hasClass('htDimmed')).toBe(true);
  138. expect(this.$container.find('tbody tr:eq(1) td:eq(0)').text()).toEqual('B');
  139. expect(this.$container.find('tbody tr:eq(1) td:eq(0)').hasClass('htDimmed')).toBe(false);
  140. expect(this.$container.find('tbody tr:eq(2) td:eq(0)').text()).toEqual('C');
  141. expect(this.$container.find('tbody tr:eq(2) td:eq(0)').hasClass('htDimmed')).toBe(false);
  142. });
  143. });