rowsMapper.unit.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import RowsMapper from 'handsontable/plugins/manualRowMove/rowsMapper';
  2. describe('manualRowMove', function () {
  3. describe('rowsMapper', function () {
  4. it('should set manualRowMove plugin while constructing', function () {
  5. var manualRowMoveMock = {};
  6. var mapper = new RowsMapper(manualRowMoveMock);
  7. expect(mapper.manualRowMove).toBe(manualRowMoveMock);
  8. });
  9. it('should be mixed with arrayMapper object', function () {
  10. expect(RowsMapper.MIXINS).toEqual(['arrayMapper']);
  11. });
  12. it('should destroy array after calling destroy method', function () {
  13. var mapper = new RowsMapper();
  14. expect(mapper._arrayMap).toEqual([]);
  15. mapper.destroy();
  16. expect(mapper._arrayMap).toBe(null);;
  17. });
  18. it('should create map with pairs index->value', function () {
  19. var mapper = new RowsMapper();
  20. mapper.createMap(6);
  21. expect(mapper._arrayMap[0]).toBe(0);
  22. expect(mapper._arrayMap[1]).toBe(1);
  23. expect(mapper._arrayMap[2]).toBe(2);
  24. expect(mapper._arrayMap[3]).toBe(3);
  25. expect(mapper._arrayMap[4]).toBe(4);
  26. expect(mapper._arrayMap[5]).toBe(5);
  27. });
  28. it('should change order after move action', function () {
  29. var mapper = new RowsMapper();
  30. mapper.createMap(6);
  31. mapper.moveRow(1, 0);
  32. mapper.clearNull();
  33. expect(mapper._arrayMap[0]).toBe(1);
  34. expect(mapper._arrayMap[1]).toBe(0);
  35. expect(mapper._arrayMap[2]).toBe(2);
  36. expect(mapper._arrayMap[3]).toBe(3);
  37. expect(mapper._arrayMap[4]).toBe(4);
  38. expect(mapper._arrayMap[5]).toBe(5);
  39. });
  40. it('should clean from null values', function () {
  41. var mapper = new RowsMapper();
  42. mapper.createMap(6);
  43. mapper.moveRow(1, 6);
  44. mapper.moveRow(2, 7);
  45. mapper.moveRow(4, 8);
  46. mapper.clearNull();
  47. expect(mapper._arrayMap.length).toBe(6);
  48. });
  49. });
  50. });