filesChanged.spec.tsx 4.4 KB

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