mixer-remove.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. require('jsdom-global')();
  3. const chai = require('chai');
  4. const dom = require('../mock/dom');
  5. const mixitup = require('../../dist/mixitup.js');
  6. chai.use(require('chai-shallow-deep-equal'));
  7. chai.use(require('chai-as-promised'));
  8. describe('mixitup.Mixer', () => {
  9. describe('#remove()', () => {
  10. it('should accept an element as an argument', () => {
  11. const container = dom.getContainer();
  12. const mixer = mixitup(container);
  13. const toRemove = container.children[3];
  14. return mixer.remove(toRemove)
  15. .then(state => {
  16. chai.assert.notEqual(state.show[3].id, 'target-4');
  17. chai.assert.equal(state.show[3].id, 'target-5');
  18. chai.assert.equal(state.totalShow, '5');
  19. mixer.destroy();
  20. });
  21. });
  22. it('should accept a collection of elements as an argument', () => {
  23. const container = dom.getContainer();
  24. const mixer = mixitup(container);
  25. const toRemove = [container.children[3], container.children[0]];
  26. return mixer.remove(toRemove)
  27. .then(state => {
  28. chai.assert.equal(state.show[0].id, 'target-2');
  29. chai.assert.equal(state.show[3].id, 'target-6');
  30. chai.assert.equal(state.totalShow, '4');
  31. mixer.destroy();
  32. });
  33. });
  34. it('should accept an index as an argument', () => {
  35. const container = dom.getContainer();
  36. const mixer = mixitup(container);
  37. return mixer.remove(3)
  38. .then(state => {
  39. chai.assert.equal(state.show[3].id, 'target-5');
  40. chai.assert.equal(state.totalShow, '5');
  41. mixer.destroy();
  42. });
  43. });
  44. it('should accept a selector as an argument', () => {
  45. const container = dom.getContainer();
  46. const mixer = mixitup(container);
  47. return mixer.remove('.category-a')
  48. .then(state => {
  49. chai.assert.equal(state.totalShow, '3');
  50. mixer.destroy();
  51. });
  52. });
  53. it('should allow no elements to be removed with a warning', () => {
  54. const container = dom.getContainer();
  55. const mixer = mixitup(container);
  56. return mixer.remove()
  57. .then(state => {
  58. chai.assert.equal(state.totalShow, '6');
  59. mixer.destroy();
  60. });
  61. });
  62. it('should accept a callback function which is invoked after removal', () => {
  63. const container = dom.getContainer();
  64. const mixer = mixitup(container);
  65. const toRemove = container.children[0];
  66. const promise = new Promise(resolve => mixer.insert(mixer.remove(toRemove), resolve));
  67. chai.assert.isFulfilled(promise);
  68. return promise
  69. .then(() => {
  70. chai.assert.notEqual(toRemove, container);
  71. mixer.destroy();
  72. });
  73. });
  74. it('should accept a boolean allowing toggling off of animation', () => {
  75. const container = dom.getContainer();
  76. const mixer = mixitup(container);
  77. const toRemove = container.children[0];
  78. return mixer.remove(toRemove, false)
  79. .then(() => {
  80. chai.assert.notEqual(toRemove, container);
  81. mixer.destroy();
  82. });
  83. });
  84. });
  85. });