textRenderer.spec.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. describe('TextRenderer', () => {
  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 render string', () => {
  13. handsontable();
  14. setDataAtCell(2, 2, 'string');
  15. expect(getCell(2, 2).innerHTML).toEqual('string');
  16. });
  17. it('should render number', () => {
  18. handsontable();
  19. setDataAtCell(2, 2, 13);
  20. expect(getCell(2, 2).innerHTML).toEqual('13');
  21. });
  22. it('should render boolean true', () => {
  23. handsontable();
  24. setDataAtCell(2, 2, true);
  25. expect(getCell(2, 2).innerHTML).toEqual('true');
  26. });
  27. it('should render boolean false', () => {
  28. handsontable();
  29. setDataAtCell(2, 2, false);
  30. expect(getCell(2, 2).innerHTML).toEqual('false');
  31. });
  32. it('should render null', () => {
  33. handsontable();
  34. setDataAtCell(2, 2, null);
  35. expect(getCell(2, 2).innerHTML).toEqual('');
  36. });
  37. it('should render undefined', () => {
  38. handsontable();
  39. /* eslint-disable wrap-iife */
  40. setDataAtCell(2, 2, (function() {})());
  41. expect(getCell(2, 2).innerHTML).toEqual('');
  42. });
  43. it('should add class name `htDimmed` to a read only cell', () => {
  44. var DIV = document.createElement('DIV');
  45. var instance = new Handsontable.Core(DIV, {});
  46. var TD = document.createElement('TD');
  47. TD.className = 'someClass';
  48. Handsontable.renderers.TextRenderer(instance, TD, 0, 0, 0, '', {readOnly: true, readOnlyCellClassName: 'htDimmed'});
  49. expect(TD.className).toEqual('someClass htDimmed');
  50. instance.destroy();
  51. });
  52. it('should render a multiline string', () => {
  53. handsontable();
  54. setDataAtCell(1, 2, 'a b');
  55. setDataAtCell(2, 2, 'a\nb');
  56. expect($(getCell(2, 2)).height()).toBeGreaterThan($(getCell(1, 2)).height());
  57. });
  58. it('should wrap text when column width is limited', () => {
  59. handsontable({
  60. colWidths: [100]
  61. });
  62. setDataAtCell(0, 0, 'short text');
  63. setDataAtCell(1, 0, 'long long long long long long long text');
  64. expect($(getCell(1, 0)).height()).toBeGreaterThan($(getCell(0, 0)).height());
  65. });
  66. });