commits.spec.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import {CommitFixture} from 'sentry-fixture/commit';
  2. import {ReleaseFixture} from 'sentry-fixture/release';
  3. import {ReleaseProjectFixture} from 'sentry-fixture/releaseProject';
  4. import {RepositoryFixture} from 'sentry-fixture/repository';
  5. import {initializeOrg} from 'sentry-test/initializeOrg';
  6. import {render, screen} from 'sentry-test/reactTestingLibrary';
  7. import selectEvent from 'sentry-test/selectEvent';
  8. import type {ReleaseProject} from 'sentry/types/release';
  9. import {ReleaseContext} from 'sentry/views/releases/detail';
  10. import Commits from './commits';
  11. describe('Commits', () => {
  12. const release = ReleaseFixture();
  13. const project = ReleaseProjectFixture() as Required<ReleaseProject>;
  14. const {router, organization} = initializeOrg({
  15. router: {params: {release: release.version}},
  16. });
  17. const repos = [RepositoryFixture({integrationId: '1'})];
  18. function renderComponent() {
  19. return render(
  20. <ReleaseContext.Provider
  21. value={{
  22. release,
  23. project,
  24. deploys: [],
  25. refetchData: () => {},
  26. hasHealthData: false,
  27. releaseBounds: {} as any,
  28. releaseMeta: {} as any,
  29. }}
  30. >
  31. <Commits />
  32. </ReleaseContext.Provider>,
  33. {router}
  34. );
  35. }
  36. beforeEach(() => {
  37. MockApiClient.clearMockResponses();
  38. MockApiClient.addMockResponse({
  39. url: `/organizations/${organization.slug}/repos/`,
  40. body: repos,
  41. });
  42. MockApiClient.addMockResponse({
  43. url: `/projects/${organization.slug}/${project.slug}/releases/${encodeURIComponent(
  44. release.version
  45. )}/repositories/`,
  46. body: repos,
  47. });
  48. });
  49. it('should render no repositories message', async () => {
  50. MockApiClient.addMockResponse({
  51. url: `/organizations/${organization.slug}/repos/`,
  52. body: [],
  53. });
  54. renderComponent();
  55. expect(
  56. await screen.findByText('Releases are better with commit data!')
  57. ).toBeInTheDocument();
  58. });
  59. it('should render no commits', async () => {
  60. MockApiClient.addMockResponse({
  61. url: `/projects/${organization.slug}/${project.slug}/releases/${encodeURIComponent(
  62. release.version
  63. )}/repositories/`,
  64. body: repos,
  65. });
  66. MockApiClient.addMockResponse({
  67. url: `/projects/org-slug/project-slug/releases/${encodeURIComponent(
  68. release.version
  69. )}/commits/`,
  70. body: [],
  71. });
  72. renderComponent();
  73. expect(await screen.findByText(/There are no commits/)).toBeInTheDocument();
  74. });
  75. it('should render list of commits', async () => {
  76. MockApiClient.addMockResponse({
  77. url: `/projects/${organization.slug}/${project.slug}/releases/${encodeURIComponent(
  78. release.version
  79. )}/repositories/`,
  80. body: repos,
  81. });
  82. MockApiClient.addMockResponse({
  83. url: `/projects/org-slug/project-slug/releases/${encodeURIComponent(
  84. release.version
  85. )}/commits/`,
  86. body: [CommitFixture()],
  87. });
  88. renderComponent();
  89. expect(
  90. await screen.findByText('(improve) Add Links to Spike-Protection Email (#2408)')
  91. ).toBeInTheDocument();
  92. expect(screen.getByText('f7f395d')).toBeInTheDocument();
  93. });
  94. it('should render repo picker', async () => {
  95. MockApiClient.addMockResponse({
  96. url: `/projects/${organization.slug}/${project.slug}/releases/${encodeURIComponent(
  97. release.version
  98. )}/repositories/`,
  99. body: [
  100. repos[0]!,
  101. RepositoryFixture({
  102. id: '5',
  103. name: 'getsentry/sentry-frontend',
  104. integrationId: '1',
  105. }),
  106. ],
  107. });
  108. MockApiClient.addMockResponse({
  109. url: `/projects/org-slug/project-slug/releases/${encodeURIComponent(
  110. release.version
  111. )}/commits/`,
  112. body: [CommitFixture()],
  113. });
  114. renderComponent();
  115. expect(await screen.findByRole('button')).toHaveTextContent('example/repo-name');
  116. expect(screen.queryByText('getsentry/sentry-frontend')).not.toBeInTheDocument();
  117. await selectEvent.openMenu(
  118. screen.getByRole('button', {name: 'Filter example/repo-name'})
  119. );
  120. expect(await screen.findByText('getsentry/sentry-frontend')).toBeInTheDocument();
  121. });
  122. it('should render the commits from the selected repo', async () => {
  123. const otherRepo = RepositoryFixture({
  124. id: '5',
  125. name: 'getsentry/sentry-frontend',
  126. integrationId: '1',
  127. });
  128. // Current repo is stored in query parameter activeRepo
  129. const {router: newRouterContext} = initializeOrg({
  130. router: {
  131. params: {release: release.version},
  132. location: {query: {activeRepo: otherRepo.name}},
  133. },
  134. });
  135. MockApiClient.addMockResponse({
  136. url: `/projects/${organization.slug}/${project.slug}/releases/${encodeURIComponent(
  137. release.version
  138. )}/repositories/`,
  139. body: [repos[0]!, otherRepo],
  140. });
  141. MockApiClient.addMockResponse({
  142. url: `/projects/org-slug/project-slug/releases/${encodeURIComponent(
  143. release.version
  144. )}/commits/`,
  145. body: [
  146. CommitFixture(),
  147. CommitFixture({
  148. repository: otherRepo,
  149. }),
  150. ],
  151. });
  152. render(
  153. <ReleaseContext.Provider
  154. value={{
  155. release,
  156. project,
  157. deploys: [],
  158. refetchData: () => {},
  159. hasHealthData: false,
  160. releaseBounds: {} as any,
  161. releaseMeta: {} as any,
  162. }}
  163. >
  164. <Commits />
  165. </ReleaseContext.Provider>,
  166. {router: newRouterContext}
  167. );
  168. expect(await screen.findByRole('button')).toHaveTextContent(otherRepo.name);
  169. expect(screen.queryByText('example/repo-name')).not.toBeInTheDocument();
  170. });
  171. });