groupStore.spec.jsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import GroupStore from 'app/stores/groupStore';
  2. describe('GroupStore', function() {
  3. let sandbox;
  4. beforeEach(function() {
  5. GroupStore.reset();
  6. sandbox = sinon.sandbox.create();
  7. });
  8. afterEach(function() {
  9. sandbox.restore();
  10. });
  11. describe('add()', function() {
  12. it('should add new entries', function() {
  13. GroupStore.items = [];
  14. GroupStore.add([{id: 1}, {id: 2}]);
  15. expect(GroupStore.items).toEqual([{id: 1}, {id: 2}]);
  16. });
  17. it('should update matching existing entries', function() {
  18. GroupStore.items = [{id: 1}, {id: 2}];
  19. GroupStore.add([{id: 1, foo: 'bar'}, {id: 3}]);
  20. expect(GroupStore.items).toEqual([{id: 1, foo: 'bar'}, {id: 2}, {id: 3}]);
  21. });
  22. });
  23. describe('onMergeSuccess()', function() {
  24. it('should remove the non-parent merged ids', function() {
  25. GroupStore.items = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
  26. GroupStore.onMergeSuccess(
  27. null,
  28. [2, 3, 4], // items merged
  29. {merge: {parent: 3}} // merge API response
  30. );
  31. expect(GroupStore.items).toEqual([
  32. {id: 1},
  33. {id: 3}, // parent
  34. ]);
  35. });
  36. });
  37. describe('update methods', function() {
  38. beforeEach(function() {
  39. GroupStore.reset();
  40. GroupStore.items = [{id: 1}, {id: 2}, {id: 3}];
  41. });
  42. describe('onUpdate()', function() {
  43. it("should treat undefined itemIds argument as 'all'", function() {
  44. sandbox.stub(GroupStore, 'trigger');
  45. GroupStore.onUpdate(1337, undefined, 'somedata');
  46. expect(GroupStore.trigger.calledOnce).toBeTruthy();
  47. expect(GroupStore.trigger.firstCall.args[0]).toEqual(new Set([1, 2, 3]));
  48. });
  49. });
  50. describe('onUpdateSuccess()', function() {
  51. it("should treat undefined itemIds argument as 'all'", function() {
  52. sandbox.stub(GroupStore, 'trigger');
  53. GroupStore.onUpdateSuccess(1337, undefined, 'somedata');
  54. expect(GroupStore.trigger.calledOnce).toBeTruthy();
  55. expect(GroupStore.trigger.firstCall.args[0]).toEqual(new Set([1, 2, 3]));
  56. });
  57. });
  58. describe('onUpdateError()', function() {
  59. it("should treat undefined itemIds argument as 'all'", function() {
  60. sandbox.stub(GroupStore, 'trigger');
  61. GroupStore.onUpdateError(1337, undefined, 'something failed', false);
  62. expect(GroupStore.trigger.calledOnce).toBeTruthy();
  63. expect(GroupStore.trigger.firstCall.args[0]).toEqual(new Set([1, 2, 3]));
  64. });
  65. });
  66. describe('onDeleteSuccess()', function() {
  67. it("should treat undefined itemIds argument as 'all'", function() {
  68. sandbox.stub(GroupStore, 'trigger');
  69. GroupStore.onDeleteSuccess(1337, undefined, 'somedata');
  70. expect(GroupStore.trigger.calledOnce).toBeTruthy();
  71. expect(GroupStore.trigger.firstCall.args[0]).toEqual(new Set([1, 2, 3]));
  72. });
  73. });
  74. });
  75. });