organizationEnvironmentsStore.spec.jsx 1.4 KB

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