getSourceDataAtCol.spec.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. describe('Core.getSourceDataAtCol', () => {
  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 return col values when data is provided by dataSchema', () => {
  13. handsontable({
  14. data: [
  15. model({ id: 1, name: 'Ted Right', address: '' }),
  16. model({ id: 2, name: 'Frank Honest', address: '' }),
  17. model({ id: 3, name: 'Joan Well', address: '' }),
  18. model({ id: 4, name: 'Gail Polite', address: '' }),
  19. model({ id: 5, name: 'Michael Fair', address: '' })
  20. ],
  21. dataSchema: model,
  22. columns: [
  23. { data: property('id') },
  24. { data: property('name') },
  25. { data: property('address') }
  26. ]
  27. });
  28. function model(opts) {
  29. const _pub = {};
  30. const _priv = {
  31. id: undefined,
  32. name: undefined,
  33. address: undefined
  34. };
  35. Handsontable.helper.objectEach(opts, (value, key) => {
  36. _priv[key] = value;
  37. });
  38. _pub.attr = function(attr, val) {
  39. if (typeof val === 'undefined') {
  40. return _priv[attr];
  41. }
  42. _priv[attr] = val;
  43. return _pub;
  44. };
  45. return _pub;
  46. }
  47. function property(attr) {
  48. return function(row, value) {
  49. return row.attr(attr, value);
  50. };
  51. }
  52. expect(getSourceDataAtCol(0)).toEqual([1, 2, 3, 4, 5]);
  53. });
  54. });