projectLatestReleases.spec.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import {Fragment} from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import GlobalModal from 'sentry/components/globalModal';
  5. import ProjectLatestReleases from 'sentry/views/projectDetail/projectLatestReleases';
  6. describe('ProjectDetail > ProjectLatestReleases', function () {
  7. let endpointMock, endpointOlderReleasesMock;
  8. const {organization, project, router} = initializeOrg();
  9. beforeEach(function () {
  10. endpointMock = MockApiClient.addMockResponse({
  11. url: `/projects/${organization.slug}/${project.slug}/releases/`,
  12. body: [
  13. TestStubs.Release({version: '1.0.0'}),
  14. TestStubs.Release({version: '1.0.1'}),
  15. ],
  16. });
  17. endpointOlderReleasesMock = MockApiClient.addMockResponse({
  18. url: `/organizations/${organization.slug}/releases/stats/`,
  19. body: [TestStubs.Release({version: '1.0.0'})],
  20. });
  21. });
  22. afterEach(function () {
  23. MockApiClient.clearMockResponses();
  24. });
  25. it('renders a list', function () {
  26. const wrapper = mountWithTheme(
  27. <ProjectLatestReleases
  28. organization={organization}
  29. projectSlug={project.slug}
  30. location={router.location}
  31. projectId={project.slug}
  32. isProjectStabilized
  33. />
  34. );
  35. expect(endpointMock).toHaveBeenCalledTimes(1);
  36. expect(endpointMock).toHaveBeenCalledWith(
  37. expect.anything(),
  38. expect.objectContaining({
  39. query: {per_page: 5},
  40. })
  41. );
  42. expect(endpointOlderReleasesMock).toHaveBeenCalledTimes(0);
  43. expect(wrapper.find('SectionHeading').text()).toBe('Latest Releases');
  44. expect(wrapper.find('Version').length).toBe(2);
  45. expect(wrapper.find('DateTime').at(0).text()).toBe('Mar 23, 2020 1:02 AM');
  46. expect(wrapper.find('Version').at(1).text()).toBe('1.0.1');
  47. });
  48. it('shows the empty state', async function () {
  49. MockApiClient.addMockResponse({
  50. url: `/projects/${organization.slug}/${project.slug}/releases/`,
  51. body: [],
  52. });
  53. const wrapper = mountWithTheme(
  54. <ProjectLatestReleases
  55. organization={organization}
  56. projectSlug={project.slug}
  57. location={router.location}
  58. projectId={project.slug}
  59. isProjectStabilized
  60. />
  61. );
  62. await tick();
  63. wrapper.update();
  64. expect(endpointOlderReleasesMock).toHaveBeenCalledTimes(1);
  65. expect(wrapper.find('Version').length).toBe(0);
  66. expect(wrapper.text()).toContain('No releases found');
  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. const wrapper = mountWithTheme(
  78. <Fragment>
  79. <GlobalModal />
  80. <ProjectLatestReleases
  81. organization={organization}
  82. projectSlug={project.slug}
  83. location={router.location}
  84. projectId={project.slug}
  85. isProjectStabilized
  86. />
  87. </Fragment>
  88. );
  89. await tick();
  90. wrapper.update();
  91. expect(wrapper.find('Version').length).toBe(0);
  92. const docsButton = wrapper.find('Button').at(0);
  93. const tourButton = wrapper.find('Button').at(1);
  94. expect(docsButton.text()).toBe('Start Setup');
  95. expect(docsButton.prop('href')).toBe('https://docs.sentry.io/product/releases/');
  96. expect(tourButton.text()).toBe('Get Tour');
  97. expect(wrapper.find('GlobalModal').props().visible).toEqual(false);
  98. tourButton.simulate('click');
  99. await tick();
  100. wrapper.update();
  101. expect(wrapper.find('GlobalModal').props().visible).toEqual(true);
  102. });
  103. it('calls API with the right params', function () {
  104. mountWithTheme(
  105. <ProjectLatestReleases
  106. organization={organization}
  107. projectSlug={project.slug}
  108. location={{
  109. query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
  110. }}
  111. projectId={project.slug}
  112. isProjectStabilized
  113. />
  114. );
  115. expect(endpointMock).toHaveBeenCalledTimes(1);
  116. expect(endpointMock).toHaveBeenCalledWith(
  117. expect.anything(),
  118. expect.objectContaining({
  119. query: {per_page: 5, statsPeriod: '7d', environment: 'staging'},
  120. })
  121. );
  122. });
  123. it('does not call API if project is not stabilized yet', function () {
  124. mountWithTheme(
  125. <ProjectLatestReleases
  126. organization={organization}
  127. projectSlug={project.slug}
  128. location={{
  129. query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
  130. }}
  131. projectId={project.slug}
  132. isProjectStabilized={false}
  133. />
  134. );
  135. expect(endpointMock).toHaveBeenCalledTimes(0);
  136. });
  137. });