9d3af4d5364f1af77fb3f83efb7281ed4b73c679dc1df7b95474179663a735c261d0feda481b35e73bccbcb8518268ccf19316efc8ce393d71e4566b328dc2 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. describe('Core_splice', () => {
  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. describe('spliceCol', () => {
  21. it('should remove data from specified col', () => {
  22. handsontable({
  23. data: arrayOfArrays(),
  24. minSpareRows: 1
  25. });
  26. expect(spliceCol(1, 0, 2)).toEqual(['Kia', 10]);
  27. expect(getData(0, 1, 3, 1)).toEqual([[20], [30], [null], [null]]);
  28. });
  29. it('should insert data into specified col', () => {
  30. handsontable({
  31. data: arrayOfArrays(),
  32. minSpareRows: 1
  33. });
  34. expect(spliceCol(1, 1, 0, 'test', 'test', 'test')).toEqual([]);
  35. expect(getData(0, 1, 6, 1)).toEqual([['Kia'], ['test'], ['test'], ['test'], [10], [20], [30]]);
  36. });
  37. it('should remove and insert data into specified col', () => {
  38. handsontable({
  39. data: arrayOfArrays(),
  40. minSpareRows: 1
  41. });
  42. expect(spliceCol(1, 0, 2, 'test', 'test', 'test')).toEqual(['Kia', 10]);
  43. expect(getData(0, 1, 4, 1)).toEqual([['test'], ['test'], ['test'], [20], [30]]);
  44. });
  45. });
  46. describe('spliceRow', () => {
  47. it('should remove data from specified row', () => {
  48. handsontable({
  49. data: arrayOfArrays(),
  50. minSpareCols: 1
  51. });
  52. expect(spliceRow(0, 0, 3)).toEqual(['', 'Kia', 'Nissan']);
  53. expect(getData(0, 0, 0, 4)).toEqual([['Toyota', 'Honda', null, null, null]]);
  54. });
  55. it('should insert data into specified row', () => {
  56. handsontable({
  57. data: arrayOfArrays(),
  58. minSpareCols: 1
  59. });
  60. expect(spliceRow(0, 0, 0, 'test', 'test', 'test')).toEqual([]);
  61. expect(getData(0, 0, 0, 7)).toEqual([['test', 'test', 'test', '', 'Kia', 'Nissan', 'Toyota', 'Honda']]);
  62. });
  63. it('should remove and insert data into specified row', () => {
  64. handsontable({
  65. data: arrayOfArrays(),
  66. minSpareCols: 1
  67. });
  68. expect(spliceRow(0, 0, 2, 'test', 'test', 'test')).toEqual(['', 'Kia']);
  69. expect(getData(0, 0, 0, 5)).toEqual([['test', 'test', 'test', 'Nissan', 'Toyota', 'Honda']]);
  70. });
  71. });
  72. });