groupStore.spec.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import GroupStore from 'app/stores/groupStore';
  2. describe('GroupStore', function () {
  3. beforeEach(function () {
  4. GroupStore.reset();
  5. this.sandbox = sinon.sandbox.create();
  6. });
  7. afterEach(function() {
  8. this.sandbox.restore();
  9. });
  10. describe('onMergeSuccess()', function () {
  11. it('should remove the non-parent merged ids', function () {
  12. GroupStore.items = [
  13. {id: 1},
  14. {id: 2},
  15. {id: 3},
  16. {id: 4}
  17. ];
  18. GroupStore.onMergeSuccess(null,
  19. [2, 3, 4], // items merged
  20. {merge: {parent: 3}} // merge API response
  21. );
  22. expect(GroupStore.items).to.eql([
  23. {id: 1},
  24. {id: 3} // parent
  25. ]);
  26. });
  27. });
  28. describe('update methods', function () {
  29. beforeEach(function () {
  30. GroupStore.items = [
  31. {id: 1},
  32. {id: 2},
  33. {id: 3},
  34. ];
  35. });
  36. describe('onUpdate()', function () {
  37. it('should treat undefined itemIds argument as \'all\'', function () {
  38. this.sandbox.stub(GroupStore, 'trigger');
  39. GroupStore.onUpdate(1337, undefined, 'somedata');
  40. expect(GroupStore.trigger.calledOnce).to.be.ok;
  41. expect(GroupStore.trigger.firstCall.args[0]).to.eql(new Set([1,2,3]));
  42. });
  43. });
  44. describe('onUpdateSuccess()', function () {
  45. it('should treat undefined itemIds argument as \'all\'', function () {
  46. this.sandbox.stub(GroupStore, 'trigger');
  47. GroupStore.onUpdateSuccess(1337, undefined, 'somedata');
  48. expect(GroupStore.trigger.calledOnce).to.be.ok;
  49. expect(GroupStore.trigger.firstCall.args[0]).to.eql(new Set([1,2,3]));
  50. });
  51. });
  52. describe('onUpdateError()', function () {
  53. it('should treat undefined itemIds argument as \'all\'', function () {
  54. this.sandbox.stub(GroupStore, 'trigger');
  55. GroupStore.onUpdateError(1337, undefined, 'something failed', false);
  56. expect(GroupStore.trigger.calledOnce).to.be.ok;
  57. expect(GroupStore.trigger.firstCall.args[0]).to.eql(new Set([1,2,3]));
  58. });
  59. });
  60. });
  61. });