teamStore.spec.tsx 2.7 KB

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