createProject.spec.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import React from 'react';
  2. import {shallow, mountWithTheme} from 'sentry-test/enzyme';
  3. import {CreateProject} from 'app/components/createProject';
  4. import {openCreateTeamModal} from 'app/actionCreators/modal';
  5. jest.mock('app/actionCreators/modal');
  6. describe('CreateProject', function() {
  7. const baseProps = {
  8. api: new MockApiClient(),
  9. location: {query: {}},
  10. organization: TestStubs.Organization(),
  11. teams: [],
  12. params: {
  13. projectId: '',
  14. orgId: 'testOrg',
  15. },
  16. };
  17. it('should block if you have access to no teams', function() {
  18. const props = {
  19. ...baseProps,
  20. };
  21. const wrapper = shallow(
  22. <CreateProject {...props} />,
  23. TestStubs.routerContext([
  24. {
  25. organization: {
  26. id: '1',
  27. slug: 'testOrg',
  28. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: false}],
  29. },
  30. location: {query: {}},
  31. },
  32. ])
  33. );
  34. expect(wrapper).toMatchSnapshot();
  35. });
  36. it('can create a new team', function() {
  37. const props = {
  38. ...baseProps,
  39. };
  40. const wrapper = mountWithTheme(
  41. <CreateProject {...props} />,
  42. TestStubs.routerContext([
  43. {
  44. organization: {
  45. id: '1',
  46. slug: 'testOrg',
  47. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: false}],
  48. },
  49. },
  50. ])
  51. );
  52. wrapper.find('TeamSelectInput Button').simulate('click');
  53. expect(openCreateTeamModal).toHaveBeenCalled();
  54. });
  55. it('should fill in project name if its empty when platform is chosen', function() {
  56. const props = {
  57. ...baseProps,
  58. };
  59. const wrapper = mountWithTheme(
  60. <CreateProject {...props} />,
  61. TestStubs.routerContext([
  62. {
  63. organization: {
  64. id: '1',
  65. slug: 'testOrg',
  66. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
  67. },
  68. location: {query: {}},
  69. },
  70. ])
  71. );
  72. let node = wrapper.find('PlatformCard').first();
  73. node.simulate('click');
  74. expect(wrapper.find('ProjectNameInput input').props().value).toBe('C#');
  75. node = wrapper.find('PlatformCard').last();
  76. node.simulate('click');
  77. expect(wrapper.find('ProjectNameInput input').props().value).toBe('Ruby');
  78. //but not replace it when project name is something else:
  79. wrapper.setState({projectName: 'another'});
  80. node = wrapper.find('PlatformCard').first();
  81. node.simulate('click');
  82. expect(wrapper.find('ProjectNameInput input').props().value).toBe('another');
  83. expect(wrapper).toMatchSnapshot();
  84. });
  85. it('should fill in platform name if its provided by url', function() {
  86. const props = {
  87. ...baseProps,
  88. };
  89. const wrapper = mountWithTheme(
  90. <CreateProject {...props} />,
  91. TestStubs.routerContext([
  92. {
  93. organization: {
  94. id: '1',
  95. slug: 'testOrg',
  96. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
  97. },
  98. location: {query: {platform: 'ruby'}},
  99. },
  100. ])
  101. );
  102. expect(wrapper.find('ProjectNameInput input').props().value).toBe('Ruby');
  103. expect(wrapper).toMatchSnapshot();
  104. });
  105. it('should deal with incorrect platform name if its provided by url', function() {
  106. const props = {
  107. ...baseProps,
  108. };
  109. const wrapper = mountWithTheme(
  110. <CreateProject {...props} />,
  111. TestStubs.routerContext([
  112. {
  113. organization: {
  114. id: '1',
  115. slug: 'testOrg',
  116. teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
  117. },
  118. location: {query: {platform: 'XrubyROOLs'}},
  119. },
  120. ])
  121. );
  122. expect(wrapper.find('ProjectNameInput input').props().value).toBe('');
  123. expect(wrapper).toMatchSnapshot();
  124. });
  125. });