projectLatestReleases.spec.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {ReleaseFixture} from 'sentry-fixture/release';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {
  5. render,
  6. renderGlobalModal,
  7. screen,
  8. userEvent,
  9. } from 'sentry-test/reactTestingLibrary';
  10. import ProjectLatestReleases from 'sentry/views/projectDetail/projectLatestReleases';
  11. describe('ProjectDetail > ProjectLatestReleases', function () {
  12. let endpointMock: jest.Mock;
  13. let endpointOlderReleasesMock: jest.Mock;
  14. const {organization, project, router} = initializeOrg();
  15. beforeEach(function () {
  16. endpointMock = MockApiClient.addMockResponse({
  17. url: `/projects/${organization.slug}/${project.slug}/releases/`,
  18. body: [ReleaseFixture({version: '1.0.0'}), ReleaseFixture({version: '1.0.1'})],
  19. });
  20. endpointOlderReleasesMock = MockApiClient.addMockResponse({
  21. url: `/organizations/${organization.slug}/releases/stats/`,
  22. body: [ReleaseFixture({version: '1.0.0'})],
  23. });
  24. });
  25. afterEach(function () {
  26. MockApiClient.clearMockResponses();
  27. });
  28. it('renders a list', function () {
  29. render(
  30. <ProjectLatestReleases
  31. organization={organization}
  32. projectSlug={project.slug}
  33. location={router.location}
  34. project={project}
  35. isProjectStabilized
  36. />
  37. );
  38. expect(endpointMock).toHaveBeenCalledTimes(1);
  39. expect(endpointMock).toHaveBeenCalledWith(
  40. expect.anything(),
  41. expect.objectContaining({
  42. query: {per_page: 5},
  43. })
  44. );
  45. expect(endpointOlderReleasesMock).toHaveBeenCalledTimes(0);
  46. expect(screen.getByText('Latest Releases')).toBeInTheDocument();
  47. expect(screen.getByText('1.0.0')).toBeInTheDocument();
  48. expect(screen.getByText('1.0.1')).toBeInTheDocument();
  49. expect(screen.getAllByText('Mar 23, 2020 1:02 AM')).toHaveLength(2);
  50. });
  51. it('shows the empty state', async function () {
  52. MockApiClient.addMockResponse({
  53. url: `/projects/${organization.slug}/${project.slug}/releases/`,
  54. body: [],
  55. });
  56. render(
  57. <ProjectLatestReleases
  58. organization={organization}
  59. projectSlug={project.slug}
  60. location={router.location}
  61. project={project}
  62. isProjectStabilized
  63. />
  64. );
  65. expect(await screen.findByText('No releases found')).toBeInTheDocument();
  66. });
  67. it('shows configure releases buttons', async function () {
  68. MockApiClient.addMockResponse({
  69. url: `/projects/${organization.slug}/${project.slug}/releases/`,
  70. body: [],
  71. });
  72. MockApiClient.addMockResponse({
  73. url: `/organizations/${organization.slug}/releases/stats/`,
  74. body: [],
  75. });
  76. render(
  77. <ProjectLatestReleases
  78. organization={organization}
  79. projectSlug={project.slug}
  80. location={router.location}
  81. project={project}
  82. isProjectStabilized
  83. />
  84. );
  85. expect(await screen.findByRole('button', {name: 'Start Setup'})).toHaveAttribute(
  86. 'href',
  87. 'https://docs.sentry.io/product/releases/'
  88. );
  89. await userEvent.click(screen.getByRole('button', {name: 'Get Tour'}));
  90. renderGlobalModal();
  91. expect(screen.getByRole('dialog')).toBeInTheDocument();
  92. });
  93. it('calls API with the right params', function () {
  94. render(
  95. <ProjectLatestReleases
  96. organization={organization}
  97. projectSlug={project.slug}
  98. location={LocationFixture({
  99. query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
  100. })}
  101. project={project}
  102. isProjectStabilized
  103. />
  104. );
  105. expect(endpointMock).toHaveBeenCalledTimes(1);
  106. expect(endpointMock).toHaveBeenCalledWith(
  107. expect.anything(),
  108. expect.objectContaining({
  109. query: {per_page: 5, statsPeriod: '7d', environment: 'staging'},
  110. })
  111. );
  112. });
  113. it('does not call API if project is not stabilized yet', function () {
  114. render(
  115. <ProjectLatestReleases
  116. organization={organization}
  117. projectSlug={project.slug}
  118. location={LocationFixture({
  119. query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
  120. })}
  121. project={project}
  122. isProjectStabilized={false}
  123. />
  124. );
  125. expect(endpointMock).toHaveBeenCalledTimes(0);
  126. });
  127. });