projectLatestReleases.spec.tsx 4.1 KB

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