createProject.spec.jsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {openCreateTeamModal} from 'app/actionCreators/modal';
  3. import {CreateProject} from 'app/views/projectInstall/createProject';
  4. jest.mock('app/actionCreators/modal');
  5. describe('CreateProject', function () {
  6. const baseProps = {
  7. api: new MockApiClient(),
  8. location: {query: {}},
  9. organization: TestStubs.Organization(),
  10. teams: [],
  11. params: {
  12. projectId: '',
  13. orgId: 'testOrg',
  14. },
  15. };
  16. it('should block if you have access to no teams', function () {
  17. const props = {
  18. ...baseProps,
  19. };
  20. const wrapper = mountWithTheme(
  21. <CreateProject {...props} />,
  22. TestStubs.routerContext([
  23. {
  24. organization: {
  25. id: '1',
  26. slug: 'testOrg',
  27. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: false}],
  28. },
  29. },
  30. ])
  31. );
  32. expect(wrapper).toSnapshot();
  33. });
  34. it('can create a new team', function () {
  35. const props = {
  36. ...baseProps,
  37. };
  38. const wrapper = mountWithTheme(
  39. <CreateProject {...props} />,
  40. TestStubs.routerContext([
  41. {
  42. organization: {
  43. id: '1',
  44. slug: 'testOrg',
  45. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: false}],
  46. },
  47. },
  48. ])
  49. );
  50. wrapper.find('TeamSelectInput Button').simulate('click');
  51. expect(openCreateTeamModal).toHaveBeenCalled();
  52. });
  53. it('should fill in project name if its empty when platform is chosen', function () {
  54. const props = {
  55. ...baseProps,
  56. };
  57. const wrapper = mountWithTheme(
  58. <CreateProject {...props} />,
  59. TestStubs.routerContext([
  60. {
  61. organization: {
  62. id: '1',
  63. slug: 'testOrg',
  64. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
  65. },
  66. location: {query: {}},
  67. },
  68. ])
  69. );
  70. let node = wrapper.find('PlatformCard').first();
  71. node.simulate('click');
  72. expect(wrapper.find('ProjectNameInput input').props().value).toBe('iOS');
  73. node = wrapper.find('PlatformCard').last();
  74. node.simulate('click');
  75. expect(wrapper.find('ProjectNameInput input').props().value).toBe('Rails');
  76. // but not replace it when project name is something else:
  77. wrapper.setState({projectName: 'another'});
  78. node = wrapper.find('PlatformCard').first();
  79. node.simulate('click');
  80. expect(wrapper.find('ProjectNameInput input').props().value).toBe('another');
  81. expect(wrapper).toSnapshot();
  82. });
  83. it('should fill in platform name if its provided by url', function () {
  84. const props = {
  85. ...baseProps,
  86. location: {query: {platform: 'ruby-rails'}},
  87. };
  88. const wrapper = mountWithTheme(
  89. <CreateProject {...props} />,
  90. TestStubs.routerContext([
  91. {
  92. organization: {
  93. id: '1',
  94. slug: 'testOrg',
  95. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
  96. },
  97. },
  98. ])
  99. );
  100. expect(wrapper.find('ProjectNameInput input').props().value).toBe('Rails');
  101. expect(wrapper).toSnapshot();
  102. });
  103. it('should fill in category name if its provided by url', function () {
  104. const props = {
  105. ...baseProps,
  106. location: {query: {category: 'mobile'}},
  107. };
  108. const wrapper = mountWithTheme(
  109. <CreateProject {...props} />,
  110. TestStubs.routerContext([
  111. {
  112. organization: {
  113. id: '1',
  114. slug: 'testOrg',
  115. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
  116. },
  117. },
  118. ])
  119. );
  120. expect(wrapper.find('PlatformPicker').state('category')).toBe('mobile');
  121. });
  122. it('should deal with incorrect platform name if its provided by url', function () {
  123. const props = {
  124. ...baseProps,
  125. };
  126. const wrapper = mountWithTheme(
  127. <CreateProject {...props} />,
  128. TestStubs.routerContext([
  129. {
  130. organization: {
  131. id: '1',
  132. slug: 'testOrg',
  133. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
  134. },
  135. location: {query: {platform: 'XrubyROOLs'}},
  136. },
  137. ])
  138. );
  139. expect(wrapper.find('ProjectNameInput input').props().value).toBe('');
  140. expect(wrapper).toSnapshot();
  141. });
  142. describe('Issue Alerts Options', () => {
  143. let props = {};
  144. beforeEach(() => {
  145. props = {
  146. ...baseProps,
  147. };
  148. props.organization.teams = [{slug: 'test', id: '1', name: 'test', hasAccess: true}];
  149. MockApiClient.addMockResponse({
  150. url: `/projects/${props.organization.slug}/rule-conditions/`,
  151. body: TestStubs.MOCK_RESP_VERBOSE,
  152. });
  153. });
  154. afterEach(() => {
  155. MockApiClient.clearMockResponses();
  156. });
  157. it('should enabled the submit button if and only if all the required information has been filled', () => {
  158. const wrapper = mountWithTheme(
  159. <CreateProject {...props} />,
  160. TestStubs.routerContext([
  161. {
  162. location: {query: {}},
  163. },
  164. ])
  165. );
  166. const expectSubmitButtonToBeDisabled = isDisabled => {
  167. expect(
  168. wrapper.find('Button[data-test-id="create-project"]').props().disabled
  169. ).toBe(isDisabled);
  170. };
  171. wrapper
  172. .find('SelectControl[data-test-id="metric-select-control"]')
  173. .closest('RadioLineItem')
  174. .find('Radio')
  175. .simulate('change');
  176. expectSubmitButtonToBeDisabled(true);
  177. wrapper
  178. .find('input[data-test-id="range-input"]')
  179. .first()
  180. .simulate('change', {target: {value: '2'}});
  181. expectSubmitButtonToBeDisabled(true);
  182. wrapper.find('PlatformCard').first().simulate('click');
  183. expectSubmitButtonToBeDisabled(false);
  184. wrapper
  185. .find('input[data-test-id="range-input"]')
  186. .first()
  187. .simulate('change', {target: {value: ''}});
  188. expectSubmitButtonToBeDisabled(true);
  189. wrapper
  190. .find('input[data-test-id="range-input"]')
  191. .first()
  192. .simulate('change', {target: {value: '2712'}});
  193. expectSubmitButtonToBeDisabled(false);
  194. wrapper
  195. .find('input[data-test-id="range-input"]')
  196. .first()
  197. .simulate('change', {target: {value: ''}});
  198. expectSubmitButtonToBeDisabled(true);
  199. wrapper.find('Radio').first().simulate('change');
  200. expectSubmitButtonToBeDisabled(false);
  201. });
  202. });
  203. });