organizationEnvironmentsStore.spec.jsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import OrganizationEnvironmentsStore from 'sentry/stores/organizationEnvironmentsStore';
  2. describe('OrganizationEnvironmentsStore', function () {
  3. beforeEach(() => {
  4. OrganizationEnvironmentsStore.init();
  5. });
  6. afterEach(() => {
  7. OrganizationEnvironmentsStore.teardown();
  8. });
  9. it('get()', function () {
  10. expect(OrganizationEnvironmentsStore.getState()).toEqual({
  11. environments: null,
  12. error: null,
  13. });
  14. });
  15. it('loads data from a fetch', async function () {
  16. OrganizationEnvironmentsStore.onFetchEnvironmentsSuccess(TestStubs.Environments());
  17. await tick();
  18. const {environments} = OrganizationEnvironmentsStore.getState();
  19. expect(environments).toHaveLength(3);
  20. expect(environments.map(env => env.name)).toEqual([
  21. 'production',
  22. 'staging',
  23. 'STAGING',
  24. ]);
  25. expect(environments.map(env => env.displayName)).toEqual([
  26. 'production',
  27. 'staging',
  28. 'STAGING',
  29. ]);
  30. });
  31. it('has the correct loading state', function () {
  32. OrganizationEnvironmentsStore.onFetchEnvironments();
  33. const {environments, error} = OrganizationEnvironmentsStore.getState();
  34. expect(environments).toBeNull();
  35. expect(error).toBeNull();
  36. });
  37. it('has the correct error state', function () {
  38. OrganizationEnvironmentsStore.onFetchEnvironmentsError(Error('bad'));
  39. const {environments, error} = OrganizationEnvironmentsStore.getState();
  40. expect(environments).toBeNull();
  41. expect(error).not.toBeNull();
  42. });
  43. });