tags.spec.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {TagsFixture} from 'sentry-fixture/tags';
  2. import * as indicators from 'sentry/actionCreators/indicator';
  3. import TagStore from 'sentry/stores/tagStore';
  4. import {loadOrganizationTags} from './tags';
  5. describe('loadOrganizationTags', () => {
  6. const api = new MockApiClient();
  7. const selection = {
  8. datetime: {
  9. end: new Date().toISOString(),
  10. period: null,
  11. start: new Date().toISOString(),
  12. utc: null,
  13. },
  14. environments: [],
  15. projects: [],
  16. };
  17. afterEach(() => {
  18. TagStore.reset();
  19. jest.resetAllMocks();
  20. });
  21. it('should load tags into the store', async () => {
  22. MockApiClient.addMockResponse({
  23. url: '/organizations/org-slug/tags/',
  24. body: TagsFixture(),
  25. });
  26. expect(TagStore.getState().device).toBeUndefined();
  27. await loadOrganizationTags(api, 'org-slug', selection);
  28. expect(TagStore.getState().device).toBeTruthy();
  29. });
  30. it('should show an alert on failure', async () => {
  31. jest.spyOn(indicators, 'addErrorMessage');
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/tags/',
  34. statusCode: 403,
  35. });
  36. await loadOrganizationTags(api, 'org-slug', selection);
  37. expect(indicators.addErrorMessage).toHaveBeenCalledWith('Unable to load tags');
  38. });
  39. });