organizationStore.spec.jsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import OrganizationActions from 'sentry/actions/organizationActions';
  2. import OrganizationStore from 'sentry/stores/organizationStore';
  3. describe('OrganizationStore', function () {
  4. beforeEach(function () {
  5. OrganizationStore.reset();
  6. });
  7. it('starts with loading state', function () {
  8. expect(OrganizationStore.get()).toMatchObject({
  9. loading: true,
  10. error: null,
  11. errorType: null,
  12. organization: null,
  13. dirty: false,
  14. });
  15. });
  16. it('updates correctly', async function () {
  17. const organization = TestStubs.Organization();
  18. OrganizationActions.update(organization);
  19. await tick();
  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. OrganizationActions.update(organization);
  30. await tick();
  31. expect(OrganizationStore.get()).toMatchObject({
  32. loading: false,
  33. error: null,
  34. errorType: null,
  35. organization,
  36. dirty: false,
  37. });
  38. });
  39. it('updates correctly from setting changes', async function () {
  40. const organization = TestStubs.Organization();
  41. OrganizationStore.onUpdate(organization);
  42. await tick();
  43. expect(OrganizationStore.get()).toMatchObject({
  44. loading: false,
  45. error: null,
  46. errorType: null,
  47. organization,
  48. dirty: false,
  49. });
  50. });
  51. it('errors correctly', async function () {
  52. const error = new Error('uh-oh');
  53. error.status = 404;
  54. OrganizationActions.fetchOrgError(error);
  55. await tick();
  56. expect(OrganizationStore.get()).toMatchObject({
  57. loading: false,
  58. error,
  59. errorType: 'ORG_NOT_FOUND',
  60. organization: null,
  61. dirty: false,
  62. });
  63. });
  64. });