commits.spec.tsx 5.6 KB

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