filesChanged.spec.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import {CommitAuthorFixture} from 'sentry-fixture/commitAuthor';
  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 {CommitFile} from 'sentry/types/integrations';
  10. import type {ReleaseProject} from 'sentry/types/release';
  11. import {ReleaseContext} from 'sentry/views/releases/detail';
  12. import FilesChanged from './filesChanged';
  13. function CommitFileFixture(params: Partial<CommitFile> = {}): CommitFile {
  14. return {
  15. id: '111222',
  16. orgId: 1,
  17. author: CommitAuthorFixture(),
  18. commitMessage: 'feat(issues): Add alert (#1337)',
  19. filename: 'static/app/components/alert.tsx',
  20. type: 'M',
  21. repoName: 'getsentry/sentry',
  22. ...params,
  23. };
  24. }
  25. describe('FilesChanged', () => {
  26. const release = ReleaseFixture();
  27. const project = ReleaseProjectFixture() as Required<ReleaseProject>;
  28. const {routerProps, router, organization} = initializeOrg({
  29. router: {params: {release: release.version}},
  30. });
  31. const repos = [RepositoryFixture({integrationId: '1'})];
  32. function renderComponent() {
  33. return render(
  34. <ReleaseContext.Provider
  35. value={{
  36. release,
  37. project,
  38. deploys: [],
  39. refetchData: () => {},
  40. hasHealthData: false,
  41. releaseBounds: {} as any,
  42. releaseMeta: {} as any,
  43. }}
  44. >
  45. <FilesChanged
  46. releaseRepos={[]}
  47. orgSlug={organization.slug}
  48. projectSlug={project.slug}
  49. {...routerProps}
  50. />
  51. </ReleaseContext.Provider>,
  52. {router}
  53. );
  54. }
  55. beforeEach(() => {
  56. MockApiClient.clearMockResponses();
  57. MockApiClient.addMockResponse({
  58. url: `/organizations/${organization.slug}/repos/`,
  59. body: repos,
  60. });
  61. RepositoryStore.init();
  62. });
  63. it('should render no repositories message', async () => {
  64. MockApiClient.addMockResponse({
  65. url: `/organizations/${organization.slug}/repos/`,
  66. body: [],
  67. });
  68. renderComponent();
  69. expect(
  70. await screen.findByText('Releases are better with commit data!')
  71. ).toBeInTheDocument();
  72. });
  73. it('should render no files changed', async () => {
  74. MockApiClient.addMockResponse({
  75. url: `/projects/${organization.slug}/${project.slug}/releases/${encodeURIComponent(
  76. release.version
  77. )}/repositories/`,
  78. body: repos,
  79. });
  80. MockApiClient.addMockResponse({
  81. url: `/organizations/org-slug/releases/${encodeURIComponent(
  82. release.version
  83. )}/commitfiles/`,
  84. body: [],
  85. });
  86. renderComponent();
  87. expect(await screen.findByText(/There are no changed files/)).toBeInTheDocument();
  88. });
  89. it('should render list of files changed', async () => {
  90. MockApiClient.addMockResponse({
  91. url: `/projects/${organization.slug}/${project.slug}/releases/${encodeURIComponent(
  92. release.version
  93. )}/repositories/`,
  94. body: repos,
  95. });
  96. MockApiClient.addMockResponse({
  97. url: `/organizations/org-slug/releases/${encodeURIComponent(
  98. release.version
  99. )}/commitfiles/`,
  100. body: [CommitFileFixture()],
  101. });
  102. renderComponent();
  103. expect(await screen.findByText('1 file changed')).toBeInTheDocument();
  104. expect(screen.getByText('static/app/components/alert.tsx')).toBeInTheDocument();
  105. });
  106. it('should render repo picker', async () => {
  107. MockApiClient.addMockResponse({
  108. url: `/projects/${organization.slug}/${project.slug}/releases/${encodeURIComponent(
  109. release.version
  110. )}/repositories/`,
  111. body: [
  112. repos[0]!,
  113. RepositoryFixture({
  114. id: '5',
  115. name: 'getsentry/sentry-frontend',
  116. integrationId: '1',
  117. }),
  118. ],
  119. });
  120. MockApiClient.addMockResponse({
  121. url: `/organizations/org-slug/releases/${encodeURIComponent(
  122. release.version
  123. )}/commitfiles/`,
  124. body: [CommitFileFixture()],
  125. });
  126. renderComponent();
  127. expect(await screen.findByRole('button')).toHaveTextContent('example/repo-name');
  128. expect(screen.queryByText('getsentry/sentry-frontend')).not.toBeInTheDocument();
  129. await selectEvent.openMenu(screen.getByRole('button'));
  130. expect(screen.getByText('getsentry/sentry-frontend')).toBeInTheDocument();
  131. });
  132. });