createProject.spec.jsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import {fireEvent, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {openCreateTeamModal} from 'sentry/actionCreators/modal';
  3. import {CreateProject} from 'sentry/views/projectInstall/createProject';
  4. jest.mock('sentry/actionCreators/modal');
  5. describe('CreateProject', function () {
  6. const teamNoAccess = {slug: 'test', id: '1', name: 'test', hasAccess: false};
  7. const teamWithAccess = {...teamNoAccess, hasAccess: true};
  8. const baseProps = {
  9. api: new MockApiClient(),
  10. location: {query: {}},
  11. organization: TestStubs.Organization(),
  12. teams: [teamNoAccess],
  13. params: {
  14. projectId: '',
  15. orgId: 'testOrg',
  16. },
  17. setEventNames: jest.fn(),
  18. };
  19. beforeEach(() => {
  20. MockApiClient.addMockResponse({
  21. url: `/projects/testOrg/rule-conditions/`,
  22. body: {},
  23. // Not required for these tests
  24. statusCode: 500,
  25. });
  26. });
  27. afterEach(() => {
  28. MockApiClient.clearMockResponses();
  29. });
  30. it('should block if you have access to no teams', function () {
  31. const wrapper = render(<CreateProject {...baseProps} />, {
  32. context: TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}]),
  33. });
  34. expect(wrapper.container).toSnapshot();
  35. });
  36. it('can create a new team', function () {
  37. render(<CreateProject {...baseProps} />, {
  38. context: TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}]),
  39. });
  40. userEvent.click(screen.getByRole('button', {name: 'Create a team'}));
  41. expect(openCreateTeamModal).toHaveBeenCalled();
  42. });
  43. it('should fill in project name if its empty when platform is chosen', function () {
  44. const wrapper = render(<CreateProject {...baseProps} teams={[teamWithAccess]} />, {
  45. context: TestStubs.routerContext([
  46. {organization: {id: '1', slug: 'testOrg'}, location: {query: {}}},
  47. ]),
  48. });
  49. userEvent.click(screen.getByTestId('platform-apple-ios'));
  50. expect(screen.getByPlaceholderText('project-name')).toHaveValue('apple-ios');
  51. userEvent.click(screen.getByTestId('platform-ruby-rails'));
  52. expect(screen.getByPlaceholderText('project-name')).toHaveValue('ruby-rails');
  53. // but not replace it when project name is something else:
  54. userEvent.clear(screen.getByPlaceholderText('project-name'));
  55. userEvent.type(screen.getByPlaceholderText('project-name'), 'another');
  56. userEvent.click(screen.getByTestId('platform-apple-ios'));
  57. expect(screen.getByPlaceholderText('project-name')).toHaveValue('another');
  58. expect(wrapper.container).toSnapshot();
  59. });
  60. it('should fill in platform name if its provided by url', function () {
  61. const props = {
  62. ...baseProps,
  63. location: {query: {platform: 'ruby-rails'}},
  64. };
  65. const wrapper = render(<CreateProject {...props} teams={[teamWithAccess]} />, {
  66. context: TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}]),
  67. });
  68. expect(screen.getByPlaceholderText('project-name')).toHaveValue('Rails');
  69. expect(wrapper.container).toSnapshot();
  70. });
  71. it('should fill in category name if its provided by url', function () {
  72. const props = {
  73. ...baseProps,
  74. location: {query: {category: 'mobile'}},
  75. };
  76. render(<CreateProject {...props} teams={[teamWithAccess]} />, {
  77. context: TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}]),
  78. });
  79. expect(screen.getByTestId('platform-apple-ios')).toBeInTheDocument();
  80. expect(screen.queryByTestId('platform-ruby-rails')).not.toBeInTheDocument();
  81. });
  82. it('should deal with incorrect platform name if its provided by url', function () {
  83. const wrapper = render(<CreateProject {...baseProps} teams={[teamWithAccess]} />, {
  84. context: TestStubs.routerContext([
  85. {
  86. organization: {id: '1', slug: 'testOrg'},
  87. location: {query: {platform: 'XrubyROOLs'}},
  88. },
  89. ]),
  90. });
  91. expect(screen.getByPlaceholderText('project-name')).toHaveValue('');
  92. expect(wrapper.container).toSnapshot();
  93. });
  94. describe('Issue Alerts Options', () => {
  95. const props = {
  96. ...baseProps,
  97. teams: [teamWithAccess],
  98. };
  99. beforeEach(() => {
  100. MockApiClient.addMockResponse({
  101. url: `/projects/${props.organization.slug}/rule-conditions/`,
  102. body: TestStubs.MOCK_RESP_VERBOSE,
  103. });
  104. });
  105. afterEach(() => {
  106. MockApiClient.clearMockResponses();
  107. });
  108. it('should enabled the submit button if and only if all the required information has been filled', () => {
  109. render(<CreateProject {...props} />, {
  110. context: TestStubs.routerContext([
  111. {
  112. location: {query: {}},
  113. },
  114. ]),
  115. });
  116. const createProjectButton = screen.getByTestId('create-project');
  117. userEvent.click(screen.getByText(/When there are more than/));
  118. expect(createProjectButton).toBeDisabled();
  119. userEvent.paste(screen.getByTestId('range-input'), '2', {skipClick: true});
  120. expect(screen.getByTestId('range-input')).toHaveValue(2);
  121. expect(createProjectButton).toBeDisabled();
  122. userEvent.click(screen.getByTestId('platform-apple-ios'));
  123. expect(createProjectButton).toBeEnabled();
  124. userEvent.clear(screen.getByTestId('range-input'));
  125. expect(createProjectButton).toBeEnabled();
  126. userEvent.paste(screen.getByTestId('range-input'), '2712', {skipClick: true});
  127. expect(createProjectButton).toBeEnabled();
  128. fireEvent.change(screen.getByTestId('range-input'), {target: {value: ''}});
  129. expect(createProjectButton).toBeDisabled();
  130. userEvent.click(screen.getByText("I'll create my own alerts later"));
  131. expect(createProjectButton).toBeEnabled();
  132. });
  133. });
  134. });