index.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {Fragment} from 'react';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import {textWithMarkupMatcher} from 'sentry-test/utils';
  5. import GlobalModal from 'sentry/components/globalModal';
  6. import {DEBUG_SOURCE_TYPES} from 'sentry/data/debugFileSources';
  7. import ModalStore from 'sentry/stores/modalStore';
  8. import type {CustomRepo, CustomRepoHttp} from 'sentry/types/debugFiles';
  9. import {CustomRepoType} from 'sentry/types/debugFiles';
  10. import CustomRepositories from 'sentry/views/settings/projectDebugFiles/sources/customRepositories';
  11. function TestComponent({
  12. organization,
  13. customRepositories,
  14. ...props
  15. }: Omit<React.ComponentProps<typeof CustomRepositories>, 'customRepositories'> & {
  16. customRepositories?: [CustomRepoHttp];
  17. }) {
  18. return (
  19. <Fragment>
  20. <GlobalModal />
  21. <CustomRepositories
  22. {...props}
  23. organization={organization}
  24. customRepositories={customRepositories ?? []}
  25. />
  26. </Fragment>
  27. );
  28. }
  29. function getProps(props?: Parameters<typeof initializeOrg>[0]) {
  30. const {organization, router, project} = initializeOrg({
  31. router: props?.router,
  32. });
  33. return {
  34. api: new MockApiClient(),
  35. organization,
  36. project,
  37. router,
  38. isLoading: false,
  39. location: router.location,
  40. };
  41. }
  42. describe('Custom Repositories', function () {
  43. const httpRepository: CustomRepo = {
  44. id: '7ebdb871-eb65-0183-8001-ea7df90613a7',
  45. layout: {type: 'native', casing: 'default'},
  46. name: 'New Repo',
  47. password: {'hidden-secret': true},
  48. type: CustomRepoType.HTTP,
  49. url: 'https://msdl.microsoft.com/download/symbols/',
  50. username: 'admin',
  51. };
  52. beforeEach(() => {
  53. ModalStore.reset();
  54. });
  55. beforeAll(async function () {
  56. // TODO: figure out why this transpile is so slow
  57. // transpile the modal upfront so the test runs fast
  58. await import('sentry/components/modals/debugFileCustomRepository');
  59. });
  60. it('renders with custom-symbol-sources feature enabled', async function () {
  61. const props = getProps();
  62. const newOrganization = {...props.organization, features: ['custom-symbol-sources']};
  63. const {rerender} = render(
  64. <TestComponent {...props} organization={newOrganization} />,
  65. {router: props.router}
  66. );
  67. // Section title
  68. expect(screen.getByText('Custom Repositories')).toBeInTheDocument();
  69. // Enabled button
  70. expect(screen.getByText('Add Repository').closest('button')).toBeEnabled();
  71. // Content
  72. expect(screen.getByText('No custom repositories configured')).toBeInTheDocument();
  73. // Choose a source
  74. await userEvent.click(screen.getByText('Add Repository'));
  75. await userEvent.click(screen.getByText('Amazon S3'));
  76. // Display modal content
  77. expect(
  78. await screen.findByText(textWithMarkupMatcher('Add Amazon S3 Repository'))
  79. ).toBeInTheDocument();
  80. // Close Modal
  81. await userEvent.click(screen.getByLabelText('Close Modal'));
  82. // Renders enabled repository list
  83. rerender(
  84. <TestComponent
  85. {...props}
  86. organization={newOrganization}
  87. customRepositories={[httpRepository]}
  88. />
  89. );
  90. // Content
  91. const actions = screen.queryAllByLabelText('Actions');
  92. expect(actions).toHaveLength(1);
  93. // HTTP Repository
  94. expect(screen.getByText(httpRepository.name)).toBeInTheDocument();
  95. expect(screen.getByText(DEBUG_SOURCE_TYPES.http)).toBeInTheDocument();
  96. expect(actions[0]).toBeEnabled();
  97. });
  98. });