123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import PropTypes from 'prop-types';
- import React from 'react';
- import {shallow, mount} from 'enzyme';
- import {Client} from 'app/api';
- import CreateProject from 'app/views/onboarding/createProject';
- describe('CreateProject', function() {
- let sandbox;
- beforeEach(function() {
- sandbox = sinon.sandbox.create();
- this.stubbedApiRequest = sandbox.stub(Client.prototype, 'request');
- });
- afterEach(function() {
- sandbox.restore();
- });
- describe('render()', function() {
- const baseProps = {
- location: {query: {}},
- params: {
- projectId: '',
- orgId: 'testOrg',
- },
- };
- it('should block if you have access to no teams', function() {
- let props = {
- ...baseProps,
- };
- let wrapper = shallow(<CreateProject {...props} />, {
- context: {
- organization: {
- id: '1',
- slug: 'testOrg',
- teams: [{slug: 'test', id: '1', name: 'test', hasAccess: false}],
- },
- location: {query: {}},
- },
- childContextTypes: {
- organization: PropTypes.object,
- location: PropTypes.object,
- },
- });
- expect(wrapper).toMatchSnapshot();
- });
- it('should fill in project name if its empty when platform is chosen', function() {
- let props = {
- ...baseProps,
- };
- let wrapper = mount(<CreateProject {...props} />, {
- context: {
- organization: {
- id: '1',
- slug: 'testOrg',
- teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
- },
- router: TestStubs.router(),
- location: {query: {}},
- },
- childContextTypes: {
- router: PropTypes.object,
- organization: PropTypes.object,
- location: PropTypes.object,
- },
- });
- let node = wrapper.find('PlatformCard').first();
- node.props().onClick();
- expect(wrapper.state().projectName).toBe('C#');
- node = wrapper.find('PlatformCard').last();
- node.props().onClick();
- expect(wrapper.state().projectName).toBe('Ruby');
- //but not replace it when project name is something else:
- wrapper.setState({projectName: 'another'});
- node = wrapper.find('PlatformCard').first();
- node.props().onClick();
- expect(wrapper.state().projectName).toBe('another');
- expect(wrapper).toMatchSnapshot();
- });
- it('should fill in platform name if its provided by url', function() {
- let props = {
- ...baseProps,
- };
- let wrapper = mount(<CreateProject {...props} />, {
- context: {
- organization: {
- id: '1',
- slug: 'testOrg',
- teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
- },
- router: TestStubs.router(),
- location: {query: {platform: 'ruby'}},
- },
- childContextTypes: {
- router: PropTypes.object,
- organization: PropTypes.object,
- location: PropTypes.object,
- },
- });
- expect(wrapper.state().projectName).toBe('Ruby');
- expect(wrapper).toMatchSnapshot();
- });
- it('should deal with incorrect platform name if its provided by url', function() {
- let props = {
- ...baseProps,
- };
- let wrapper = mount(<CreateProject {...props} />, {
- context: {
- organization: {
- id: '1',
- slug: 'testOrg',
- teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
- },
- router: TestStubs.router(),
- location: {query: {platform: 'XrubyROOLs'}},
- },
- childContextTypes: {
- router: PropTypes.object,
- organization: PropTypes.object,
- location: PropTypes.object,
- },
- });
- expect(wrapper.state().projectName).toBe('');
- expect(wrapper).toMatchSnapshot();
- });
- });
- });
|