organizationsStore.spec.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import OrganizationsStore from 'sentry/stores/organizationsStore';
  3. describe('OrganizationsStore', () => {
  4. beforeEach(() => {
  5. OrganizationsStore.init();
  6. });
  7. it('starts with loading state', () => {
  8. expect(OrganizationsStore.getState()).toEqual({
  9. organizations: [],
  10. loaded: false,
  11. });
  12. });
  13. it('updates slug correctly', () => {
  14. const organization = OrganizationFixture();
  15. OrganizationsStore.load([organization]);
  16. expect(OrganizationsStore.getState()).toEqual({
  17. organizations: [organization],
  18. loaded: true,
  19. });
  20. const update = {...organization, slug: 'california'};
  21. OrganizationsStore.onChangeSlug(organization, update);
  22. expect(OrganizationsStore.getState()).toMatchObject({
  23. organizations: [update],
  24. loaded: true,
  25. });
  26. });
  27. it('updates property correctly', () => {
  28. const organization = OrganizationFixture();
  29. OrganizationsStore.load([organization]);
  30. expect(OrganizationsStore.getState()).toEqual({
  31. organizations: [organization],
  32. loaded: true,
  33. });
  34. const update = {...organization, something: true};
  35. OrganizationsStore.onUpdate(update);
  36. expect(OrganizationsStore.getState()).toMatchObject({
  37. organizations: [update],
  38. loaded: true,
  39. });
  40. });
  41. it('adds an organization', () => {
  42. const organization = OrganizationFixture();
  43. OrganizationsStore.load([organization]);
  44. const newOrg = OrganizationFixture({id: '2', slug: 'new'});
  45. OrganizationsStore.addOrReplace(newOrg);
  46. expect(OrganizationsStore.getState()).toMatchObject({
  47. organizations: [organization, newOrg],
  48. loaded: true,
  49. });
  50. });
  51. it('returns a stable reference with getState', () => {
  52. const state = OrganizationsStore.getState();
  53. expect(Object.is(state, OrganizationsStore.getState())).toBe(true);
  54. });
  55. });