projectLatestReleases.spec.jsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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, endpointOlderReleasesMock;
  11. const {organization, project, router} = initializeOrg();
  12. beforeEach(function () {
  13. endpointMock = MockApiClient.addMockResponse({
  14. url: `/projects/${organization.slug}/${project.slug}/releases/`,
  15. body: [
  16. TestStubs.Release({version: '1.0.0'}),
  17. TestStubs.Release({version: '1.0.1'}),
  18. ],
  19. });
  20. endpointOlderReleasesMock = MockApiClient.addMockResponse({
  21. url: `/organizations/${organization.slug}/releases/stats/`,
  22. body: [TestStubs.Release({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. projectId={project.slug}
  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. projectId={project.slug}
  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. projectId={project.slug}
  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={{
  99. query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
  100. }}
  101. projectId={project.slug}
  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={{
  119. query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
  120. }}
  121. projectId={project.slug}
  122. isProjectStabilized={false}
  123. />
  124. );
  125. expect(endpointMock).toHaveBeenCalledTimes(0);
  126. });
  127. });