projectLatestReleases.spec.tsx 4.2 KB

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