createProject.spec.jsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  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. };
  18. it('should block if you have access to no teams', function () {
  19. const props = {
  20. ...baseProps,
  21. };
  22. const wrapper = mountWithTheme(
  23. <CreateProject {...props} />,
  24. TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}])
  25. );
  26. expect(wrapper).toSnapshot();
  27. });
  28. it('can create a new team', function () {
  29. const props = {
  30. ...baseProps,
  31. };
  32. const wrapper = mountWithTheme(
  33. <CreateProject {...props} />,
  34. TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}])
  35. );
  36. wrapper.find('TeamSelectInput Button button').simulate('click');
  37. expect(openCreateTeamModal).toHaveBeenCalled();
  38. });
  39. it('should fill in project name if its empty when platform is chosen', function () {
  40. const props = {
  41. ...baseProps,
  42. };
  43. const wrapper = mountWithTheme(
  44. <CreateProject {...props} teams={[teamWithAccess]} />,
  45. TestStubs.routerContext([
  46. {organization: {id: '1', slug: 'testOrg'}, location: {query: {}}},
  47. ])
  48. );
  49. let node = wrapper.find('PlatformCard').first();
  50. node.simulate('click');
  51. expect(wrapper.find('ProjectNameInput input').props().value).toBe('iOS');
  52. node = wrapper.find('PlatformCard').last();
  53. node.simulate('click');
  54. expect(wrapper.find('ProjectNameInput input').props().value).toBe('Rails');
  55. // but not replace it when project name is something else:
  56. wrapper.setState({projectName: 'another'});
  57. node = wrapper.find('PlatformCard').first();
  58. node.simulate('click');
  59. expect(wrapper.find('ProjectNameInput input').props().value).toBe('another');
  60. expect(wrapper).toSnapshot();
  61. });
  62. it('should fill in platform name if its provided by url', function () {
  63. const props = {
  64. ...baseProps,
  65. location: {query: {platform: 'ruby-rails'}},
  66. };
  67. const wrapper = mountWithTheme(
  68. <CreateProject {...props} teams={[teamWithAccess]} />,
  69. TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}])
  70. );
  71. expect(wrapper.find('ProjectNameInput input').props().value).toBe('Rails');
  72. expect(wrapper).toSnapshot();
  73. });
  74. it('should fill in category name if its provided by url', function () {
  75. const props = {
  76. ...baseProps,
  77. location: {query: {category: 'mobile'}},
  78. };
  79. const wrapper = mountWithTheme(
  80. <CreateProject {...props} teams={[teamWithAccess]} />,
  81. TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}])
  82. );
  83. expect(wrapper.find('PlatformPicker').state('category')).toBe('mobile');
  84. });
  85. it('should deal with incorrect platform name if its provided by url', function () {
  86. const props = {
  87. ...baseProps,
  88. };
  89. const wrapper = mountWithTheme(
  90. <CreateProject {...props} teams={[teamWithAccess]} />,
  91. TestStubs.routerContext([
  92. {
  93. organization: {id: '1', slug: 'testOrg'},
  94. location: {query: {platform: 'XrubyROOLs'}},
  95. },
  96. ])
  97. );
  98. expect(wrapper.find('ProjectNameInput input').props().value).toBe('');
  99. expect(wrapper).toSnapshot();
  100. });
  101. describe('Issue Alerts Options', () => {
  102. let props = {};
  103. beforeEach(() => {
  104. props = {
  105. ...baseProps,
  106. };
  107. props.teams = [teamWithAccess];
  108. MockApiClient.addMockResponse({
  109. url: `/projects/${props.organization.slug}/rule-conditions/`,
  110. body: TestStubs.MOCK_RESP_VERBOSE,
  111. });
  112. });
  113. afterEach(() => {
  114. MockApiClient.clearMockResponses();
  115. });
  116. it('should enabled the submit button if and only if all the required information has been filled', () => {
  117. const wrapper = mountWithTheme(
  118. <CreateProject {...props} />,
  119. TestStubs.routerContext([
  120. {
  121. location: {query: {}},
  122. },
  123. ])
  124. );
  125. const expectSubmitButtonToBeDisabled = isDisabled => {
  126. expect(
  127. wrapper.find('Button[data-test-id="create-project"]').props().disabled
  128. ).toBe(isDisabled);
  129. };
  130. wrapper
  131. .find('SelectControl[data-test-id="metric-select-control"]')
  132. .closest('RadioLineItem')
  133. .find('Radio input')
  134. .simulate('change');
  135. expectSubmitButtonToBeDisabled(true);
  136. wrapper
  137. .find('input[data-test-id="range-input"]')
  138. .first()
  139. .simulate('change', {target: {value: '2'}});
  140. expectSubmitButtonToBeDisabled(true);
  141. wrapper.find('PlatformCard').first().simulate('click');
  142. expectSubmitButtonToBeDisabled(false);
  143. wrapper
  144. .find('input[data-test-id="range-input"]')
  145. .first()
  146. .simulate('change', {target: {value: ''}});
  147. expectSubmitButtonToBeDisabled(true);
  148. wrapper
  149. .find('input[data-test-id="range-input"]')
  150. .first()
  151. .simulate('change', {target: {value: '2712'}});
  152. expectSubmitButtonToBeDisabled(false);
  153. wrapper
  154. .find('input[data-test-id="range-input"]')
  155. .first()
  156. .simulate('change', {target: {value: ''}});
  157. expectSubmitButtonToBeDisabled(true);
  158. wrapper.find('Radio input').first().simulate('change');
  159. expectSubmitButtonToBeDisabled(false);
  160. });
  161. });
  162. });