createProject.spec.jsx 5.2 KB

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