useReleases.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {PageFilters} from 'sentry/types';
  4. import {ReleasesProvider, useReleases} from 'sentry/utils/releases/releasesProvider';
  5. function TestComponent({other}: {other: string}) {
  6. const {releases, loading} = useReleases();
  7. return (
  8. <div>
  9. <span>{other}</span>
  10. {releases &&
  11. releases.map(release => <em key={release.version}>{release.version}</em>)}
  12. {`loading: ${loading}`}
  13. </div>
  14. );
  15. }
  16. describe('useReleases', function () {
  17. const {organization} = initializeOrg();
  18. const selection = {
  19. projects: [1],
  20. environments: ['prod'],
  21. datetime: {
  22. period: '14d',
  23. start: null,
  24. end: null,
  25. utc: false,
  26. },
  27. } as PageFilters;
  28. it("fetches releases and save values in the context's state", async function () {
  29. const mockReleases = MockApiClient.addMockResponse({
  30. url: '/organizations/org-slug/releases/',
  31. body: [
  32. TestStubs.Release({
  33. shortVersion: 'sentry-android-shop@1.2.0',
  34. version: 'sentry-android-shop@1.2.0',
  35. }),
  36. TestStubs.Release({
  37. shortVersion: 'sentry-android-shop@1.3.0',
  38. version: 'sentry-android-shop@1.3.0',
  39. }),
  40. TestStubs.Release({
  41. shortVersion: 'sentry-android-shop@1.4.0',
  42. version: 'sentry-android-shop@1.4.0',
  43. }),
  44. ],
  45. });
  46. render(
  47. <ReleasesProvider organization={organization} selection={selection}>
  48. <TestComponent other="value" />
  49. </ReleasesProvider>
  50. );
  51. // Should forward prop
  52. expect(screen.getByText('value')).toBeInTheDocument();
  53. expect(mockReleases).toHaveBeenCalledTimes(1);
  54. expect(await screen.findByText('loading: false')).toBeInTheDocument();
  55. expect(screen.getByText('sentry-android-shop@1.2.0')).toBeInTheDocument();
  56. expect(screen.getByText('sentry-android-shop@1.3.0')).toBeInTheDocument();
  57. });
  58. });