mixer-get-state.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. describe('mixitup.Mixer', () => {
  8. describe('#getState()', () => {
  9. let container = dom.getContainer();
  10. let id = container.id = 'test-id';
  11. let mixer = mixitup(container);
  12. let state = mixer.getState();
  13. after(() => mixer.destroy());
  14. it('should contain an id equal to the container id', () => {
  15. chai.assert.equal(state.container.id, id);
  16. });
  17. it('should contain a reference to the container element', () => {
  18. chai.assert.equal(state.container, container);
  19. });
  20. it('should contain a reference to the container element', () => {
  21. chai.assert.equal(state.container, container);
  22. });
  23. it('should contain an activeFilter object with the default selector active', () => {
  24. chai.assert.instanceOf(state.activeFilter, mixitup.CommandFilter);
  25. chai.assert.equal(state.activeFilter.selector, '.mix');
  26. });
  27. it('should contain an activeSort object with the default sort string active', () => {
  28. chai.assert.instanceOf(state.activeSort, mixitup.CommandSort);
  29. chai.assert.equal(state.activeSort.sortString, 'default:asc');
  30. });
  31. it('should contain an empty activeContainerClassName string', () => {
  32. chai.assert.equal(state.activeContainerClassName, '');
  33. });
  34. it('should contain a null activeDataset', () => {
  35. chai.assert.deepEqual(state.activeDataset, null);
  36. });
  37. it('should contain a hasFailed boolean, set to false', () => {
  38. chai.assert.deepEqual(state.hasFailed, false);
  39. });
  40. it('should contain a list of targets deeply equaling the contents of the container', () => {
  41. chai.assert.deepEqual(state.targets, Array.prototype.slice.apply(container.children));
  42. });
  43. it('should contain a totalTargets integer, equal to the number of targets in the container', () => {
  44. chai.assert.equal(state.totalTargets, container.children.length);
  45. });
  46. it('should contain a list of targets currently shown', () => {
  47. chai.assert.deepEqual(state.show, Array.prototype.slice.apply(container.children));
  48. chai.assert.deepEqual(state.show, state.targets);
  49. });
  50. it('should contain a totalShow integer, equal to the number of targets shown', () => {
  51. chai.assert.equal(state.totalShow, container.children.length);
  52. });
  53. it('should contain a list of targets matching the active selector', () => {
  54. chai.assert.deepEqual(state.matching, Array.prototype.slice.apply(container.children));
  55. chai.assert.deepEqual(state.matching, state.targets);
  56. });
  57. it('should contain a totalMatching integer, equal to the number of targets matching the active selector', () => {
  58. chai.assert.equal(state.totalMatching, container.children.length);
  59. });
  60. it('should contain a list of targets currently hidden', () => {
  61. chai.assert.deepEqual(state.hide, []);
  62. });
  63. it('should contain a totalShow integer, equal to the number of targets hidden', () => {
  64. chai.assert.equal(state.totalHide, 0);
  65. });
  66. it('should contain a null triggerElement reference', () => {
  67. chai.assert.equal(state.triggerElement, null);
  68. });
  69. });
  70. });