commits.spec.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import selectEvent from 'react-select-event';
  2. import {CommitFixture} from 'sentry-fixture/commit';
  3. import {ReleaseFixture} from 'sentry-fixture/release';
  4. import {ReleaseProjectFixture} from 'sentry-fixture/releaseProject';
  5. import {RepositoryFixture} from 'sentry-fixture/repository';
  6. import {initializeOrg} from 'sentry-test/initializeOrg';
  7. import {render, screen} from 'sentry-test/reactTestingLibrary';
  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, routerContext, 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. {context: routerContext}
  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: `/organizations/org-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: `/organizations/org-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: `/organizations/org-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. selectEvent.openMenu(screen.getByRole('button'));
  114. expect(screen.getByText('getsentry/sentry-frontend')).toBeInTheDocument();
  115. });
  116. it('should render the commits from the selected repo', async () => {
  117. const otherRepo = RepositoryFixture({
  118. id: '5',
  119. name: 'getsentry/sentry-frontend',
  120. integrationId: '1',
  121. });
  122. // Current repo is stored in query parameter activeRepo
  123. const {routerContext: newRouterContext, routerProps: newRouterProps} = initializeOrg({
  124. router: {
  125. params: {release: release.version},
  126. location: {query: {activeRepo: otherRepo.name}},
  127. },
  128. });
  129. MockApiClient.addMockResponse({
  130. url: `/projects/${organization.slug}/${project.slug}/releases/${encodeURIComponent(
  131. release.version
  132. )}/repositories/`,
  133. body: [repos[0]!, otherRepo],
  134. });
  135. MockApiClient.addMockResponse({
  136. url: `/organizations/org-slug/releases/${encodeURIComponent(
  137. release.version
  138. )}/commits/`,
  139. body: [
  140. CommitFixture(),
  141. CommitFixture({
  142. repository: otherRepo,
  143. }),
  144. ],
  145. });
  146. render(
  147. <ReleaseContext.Provider
  148. value={{
  149. release,
  150. project,
  151. deploys: [],
  152. refetchData: () => {},
  153. hasHealthData: false,
  154. releaseBounds: {} as any,
  155. releaseMeta: {} as any,
  156. }}
  157. >
  158. <Commits releaseRepos={[]} projectSlug={project.slug} {...newRouterProps} />
  159. </ReleaseContext.Provider>,
  160. {context: newRouterContext}
  161. );
  162. expect(await screen.findByRole('button')).toHaveTextContent(otherRepo.name);
  163. expect(screen.queryByText('example/repo-name')).not.toBeInTheDocument();
  164. });
  165. });