teamStore.spec.jsx 2.8 KB

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