teamStore.spec.jsx 2.8 KB

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