createProject.spec.jsx 5.6 KB

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