d0911c33f629d6db0ded314c419692d407df1364c22b5a79121964d2ae38d17178129abbdcc869feb6dbf4afb6bf61cb79a880fd52741a472330ac9733267e 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. describe('Core_getDataType', () => {
  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. var arrayOfArrays = function() {
  13. return [
  14. ['', 'Kia', 'Nissan', 'Toyota', 'Honda'],
  15. ['2008', 10, 11, 12, 13],
  16. ['2009', 20, 11, 14, 13],
  17. ['2010', 30, 15, 12, 13]
  18. ];
  19. };
  20. it('should return data type at specyfied range (default type)', () => {
  21. handsontable({
  22. data: arrayOfArrays()
  23. });
  24. expect(getDataType(0, 0)).toEqual('text');
  25. expect(getDataType(0, 0, 1, 1)).toEqual('text');
  26. });
  27. it('should return data type at specyfied range (type defined in columns)', () => {
  28. handsontable({
  29. data: arrayOfArrays(),
  30. columns: [
  31. {type: 'numeric'},
  32. {type: 'text'},
  33. {type: 'date'},
  34. {type: 'autocomplete'},
  35. {type: 'dropdown'},
  36. ]
  37. });
  38. expect(getDataType(0, 0)).toEqual('numeric');
  39. expect(getDataType(0, 0, 1, 1)).toEqual('mixed');
  40. expect(getDataType(0, 1, 1, 1)).toEqual('text');
  41. expect(getDataType(0, 2, 1, 2)).toEqual('date');
  42. expect(getDataType(3, 3, 3, 3)).toEqual('autocomplete');
  43. expect(getDataType(3, 4, 3, 4)).toEqual('dropdown');
  44. });
  45. it('should return data type at specyfied range (type defined in columns) when columns is a function', () => {
  46. handsontable({
  47. data: arrayOfArrays(),
  48. columns(column) {
  49. var colMeta = {};
  50. if (column === 0) {
  51. colMeta.type = 'numeric';
  52. } else if (column === 1) {
  53. colMeta.type = 'text';
  54. } else if (column === 2) {
  55. colMeta.type = 'date';
  56. } else if (column === 3) {
  57. colMeta.type = 'autocomplete';
  58. } else if (column === 4) {
  59. colMeta.type = 'dropdown';
  60. } else {
  61. colMeta = null;
  62. }
  63. return colMeta;
  64. }
  65. });
  66. expect(getDataType(0, 0)).toEqual('numeric');
  67. expect(getDataType(0, 0, 1, 1)).toEqual('mixed');
  68. expect(getDataType(0, 1, 1, 1)).toEqual('text');
  69. expect(getDataType(0, 2, 1, 2)).toEqual('date');
  70. expect(getDataType(3, 3, 3, 3)).toEqual('autocomplete');
  71. expect(getDataType(3, 4, 3, 4)).toEqual('dropdown');
  72. });
  73. it('should return data type at specyfied range (type defined in cells)', () => {
  74. handsontable({
  75. data: arrayOfArrays(),
  76. cells(row, column) {
  77. var cellMeta = {};
  78. if (row === 1 && column === 1) {
  79. cellMeta.type = 'date';
  80. }
  81. if (column === 2) {
  82. cellMeta.type = 'checkbox';
  83. }
  84. return cellMeta;
  85. }
  86. });
  87. expect(getDataType(0, 0)).toEqual('text');
  88. expect(getDataType(1, 1)).toEqual('date');
  89. expect(getDataType(1, 2)).toEqual('checkbox');
  90. expect(getDataType(0, 0, 1, 1)).toEqual('mixed');
  91. });
  92. });