organizationStore.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import OrganizationStore from 'sentry/stores/organizationStore';
  3. import RequestError from 'sentry/utils/requestError/requestError';
  4. describe('OrganizationStore', function () {
  5. beforeEach(function () {
  6. OrganizationStore.reset();
  7. });
  8. it('starts with loading state', function () {
  9. expect(OrganizationStore.get()).toMatchObject({
  10. loading: true,
  11. error: null,
  12. errorType: null,
  13. organization: null,
  14. dirty: false,
  15. });
  16. });
  17. it('updates correctly', function () {
  18. const organization = OrganizationFixture();
  19. OrganizationStore.onUpdate(organization);
  20. expect(OrganizationStore.get()).toMatchObject({
  21. loading: false,
  22. error: null,
  23. errorType: null,
  24. organization,
  25. dirty: false,
  26. });
  27. // updates
  28. organization.slug = 'a new slug';
  29. OrganizationStore.onUpdate(organization);
  30. expect(OrganizationStore.get()).toMatchObject({
  31. loading: false,
  32. error: null,
  33. errorType: null,
  34. organization,
  35. dirty: false,
  36. });
  37. });
  38. it('updates correctly from setting changes', function () {
  39. const organization = OrganizationFixture();
  40. OrganizationStore.onUpdate(organization);
  41. expect(OrganizationStore.get()).toMatchObject({
  42. loading: false,
  43. error: null,
  44. errorType: null,
  45. organization,
  46. dirty: false,
  47. });
  48. });
  49. it('errors correctly', function () {
  50. const error = new RequestError('GET', '/some/path', new Error('uh oh'));
  51. error.status = 404;
  52. OrganizationStore.onFetchOrgError(error);
  53. expect(OrganizationStore.get()).toMatchObject({
  54. loading: false,
  55. error,
  56. errorType: 'ORG_NOT_FOUND',
  57. organization: null,
  58. dirty: false,
  59. });
  60. });
  61. it('returns a stable reference from getState', function () {
  62. const organization = OrganizationFixture();
  63. OrganizationStore.onUpdate(organization);
  64. const state = OrganizationStore.getState();
  65. expect(Object.is(state, OrganizationStore.getState())).toBe(true);
  66. });
  67. });