createProject.spec.jsx 3.8 KB

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