teamStore.spec.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import TeamStore from 'sentry/stores/teamStore';
  2. describe('TeamStore', function () {
  3. const teamFoo = TestStubs.Team({
  4. id: '1',
  5. slug: 'team-foo',
  6. });
  7. const teamBar = TestStubs.Team({
  8. id: '2',
  9. slug: 'team-bar',
  10. });
  11. beforeEach(function () {
  12. TeamStore.reset();
  13. });
  14. describe('setting data', function () {
  15. it('populate teams correctly', function () {
  16. expect(TeamStore.getState()).toMatchObject({
  17. teams: [],
  18. loading: true,
  19. hasMore: null,
  20. cursor: null,
  21. loadedUserTeams: false,
  22. });
  23. TeamStore.loadInitialData([teamFoo, teamBar]);
  24. expect(TeamStore.getState()).toMatchObject({
  25. teams: [teamBar, teamFoo],
  26. loading: false,
  27. hasMore: null,
  28. cursor: null,
  29. loadedUserTeams: false,
  30. });
  31. });
  32. it('loads user teams', function () {
  33. expect(TeamStore.getState()).toMatchObject({
  34. teams: [],
  35. loadedUserTeams: false,
  36. });
  37. TeamStore.loadUserTeams([teamFoo]);
  38. expect(TeamStore.getState()).toMatchObject({
  39. teams: [teamFoo],
  40. loadedUserTeams: true,
  41. });
  42. });
  43. it('stores cursor and hasMore correctly', function () {
  44. expect(TeamStore.getState()).toMatchObject({
  45. teams: [],
  46. hasMore: null,
  47. cursor: null,
  48. loadedUserTeams: false,
  49. });
  50. TeamStore.loadInitialData([teamFoo], false, null);
  51. expect(TeamStore.getState()).toMatchObject({
  52. teams: [teamFoo],
  53. hasMore: false,
  54. cursor: null,
  55. loadedUserTeams: true,
  56. });
  57. });
  58. });
  59. describe('updating teams', function () {
  60. it('adds new teams', async function () {
  61. TeamStore.loadInitialData([teamFoo]);
  62. await tick();
  63. expect(TeamStore.getState()).toMatchObject({
  64. teams: [teamFoo],
  65. });
  66. TeamStore.onCreateSuccess(teamBar);
  67. await tick();
  68. expect(TeamStore.getState()).toMatchObject({
  69. teams: [teamBar, teamFoo],
  70. });
  71. });
  72. it('removes teams', async function () {
  73. TeamStore.loadInitialData([teamFoo]);
  74. await tick();
  75. expect(TeamStore.getState()).toMatchObject({
  76. teams: [teamFoo],
  77. });
  78. TeamStore.onRemoveSuccess(teamFoo.slug);
  79. await tick();
  80. expect(TeamStore.getState()).toMatchObject({
  81. teams: [],
  82. });
  83. });
  84. it('updates teams', async function () {
  85. TeamStore.loadInitialData([teamFoo]);
  86. await tick();
  87. expect(TeamStore.getState()).toMatchObject({
  88. teams: [teamFoo],
  89. });
  90. TeamStore.onUpdateSuccess(teamFoo.slug, teamBar);
  91. await tick();
  92. expect(TeamStore.getState()).toMatchObject({
  93. teams: [teamBar],
  94. });
  95. });
  96. });
  97. });