organizationStore.spec.jsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {updateOrganization} from 'sentry/actionCreators/organizations';
  2. import OrganizationActions from 'sentry/actions/organizationActions';
  3. import OrganizationStore from 'sentry/stores/organizationStore';
  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', async function () {
  18. const organization = TestStubs.Organization();
  19. OrganizationActions.update(organization);
  20. await tick();
  21. expect(OrganizationStore.get()).toMatchObject({
  22. loading: false,
  23. error: null,
  24. errorType: null,
  25. organization,
  26. dirty: false,
  27. });
  28. // updates
  29. organization.slug = 'a new slug';
  30. OrganizationActions.update(organization);
  31. await tick();
  32. expect(OrganizationStore.get()).toMatchObject({
  33. loading: false,
  34. error: null,
  35. errorType: null,
  36. organization,
  37. dirty: false,
  38. });
  39. });
  40. it('updates correctly from setting changes', async function () {
  41. const organization = TestStubs.Organization();
  42. updateOrganization(organization);
  43. await tick();
  44. expect(OrganizationStore.get()).toMatchObject({
  45. loading: false,
  46. error: null,
  47. errorType: null,
  48. organization,
  49. dirty: false,
  50. });
  51. });
  52. it('errors correctly', async function () {
  53. const error = new Error('uh-oh');
  54. error.status = 404;
  55. OrganizationActions.fetchOrgError(error);
  56. await tick();
  57. expect(OrganizationStore.get()).toMatchObject({
  58. loading: false,
  59. error,
  60. errorType: 'ORG_NOT_FOUND',
  61. organization: null,
  62. dirty: false,
  63. });
  64. });
  65. });