groupStore.spec.jsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import GroupStore from 'app/stores/groupStore';
  2. describe('GroupStore', function() {
  3. beforeEach(function() {
  4. GroupStore.reset();
  5. });
  6. describe('add()', function() {
  7. it('should add new entries', function() {
  8. GroupStore.items = [];
  9. GroupStore.add([{id: 1}, {id: 2}]);
  10. expect(GroupStore.items).toEqual([{id: 1}, {id: 2}]);
  11. });
  12. it('should update matching existing entries', function() {
  13. GroupStore.items = [{id: 1}, {id: 2}];
  14. GroupStore.add([{id: 1, foo: 'bar'}, {id: 3}]);
  15. expect(GroupStore.items).toEqual([{id: 1, foo: 'bar'}, {id: 2}, {id: 3}]);
  16. });
  17. });
  18. describe('onMergeSuccess()', function() {
  19. it('should remove the non-parent merged ids', function() {
  20. GroupStore.items = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
  21. GroupStore.onMergeSuccess(
  22. null,
  23. [2, 3, 4], // items merged
  24. {merge: {parent: 3}} // merge API response
  25. );
  26. expect(GroupStore.items).toEqual([
  27. {id: 1},
  28. {id: 3}, // parent
  29. ]);
  30. });
  31. });
  32. describe('update methods', function() {
  33. beforeAll(function() {
  34. jest.spyOn(GroupStore, 'trigger');
  35. });
  36. beforeEach(function() {
  37. GroupStore.trigger.mockReset();
  38. });
  39. beforeEach(function() {
  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. GroupStore.onUpdate(1337, undefined, 'somedata');
  45. expect(GroupStore.trigger).toHaveBeenCalledTimes(1);
  46. expect(GroupStore.trigger).toHaveBeenCalledWith(new Set([1, 2, 3]));
  47. });
  48. });
  49. describe('onUpdateSuccess()', function() {
  50. it("should treat undefined itemIds argument as 'all'", function() {
  51. GroupStore.onUpdateSuccess(1337, undefined, 'somedata');
  52. expect(GroupStore.trigger).toHaveBeenCalledTimes(1);
  53. expect(GroupStore.trigger).toHaveBeenCalledWith(new Set([1, 2, 3]));
  54. });
  55. });
  56. describe('onUpdateError()', function() {
  57. it("should treat undefined itemIds argument as 'all'", function() {
  58. GroupStore.onUpdateError(1337, undefined, 'something failed', false);
  59. expect(GroupStore.trigger).toHaveBeenCalledTimes(1);
  60. expect(GroupStore.trigger).toHaveBeenCalledWith(new Set([1, 2, 3]));
  61. });
  62. });
  63. describe('onDeleteSuccess()', function() {
  64. it("should treat undefined itemIds argument as 'all'", function() {
  65. GroupStore.onDeleteSuccess(1337, undefined, 'somedata');
  66. expect(GroupStore.trigger).toHaveBeenCalledTimes(1);
  67. expect(GroupStore.trigger).toHaveBeenCalledWith(new Set([1, 2, 3]));
  68. });
  69. });
  70. });
  71. });