Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Fixes broken specs
Browse files Browse the repository at this point in the history
  • Loading branch information
el-mapache committed Aug 8, 2017
1 parent 80ddc1a commit 52b3d07
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 50 deletions.
2 changes: 0 additions & 2 deletions static_src/actions/service_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ const serviceActions = {
serviceGuid,
servicePlanGuid: planGuid
});

return Promise.resolve();
});
},

Expand Down
5 changes: 2 additions & 3 deletions static_src/components/create_service_instance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { validateString } from '../util/validators';
const CREATE_SERVICE_INSTANCE_FORM_GUID = 'create-service-form';

const propTypes = {
error: PropTypes.object,
service: PropTypes.object,
servicePlan: PropTypes.object.isRequired
};
Expand All @@ -28,7 +29,6 @@ const defaultProps = {

function stateSetter() {
return {
createError: ServiceInstanceStore.createError,
createLoading: ServiceInstanceStore.createLoading,
createdTempNotification: ServiceInstanceStore.createdTempNotification,
spaces: SpaceStore.getAll()
Expand All @@ -41,8 +41,7 @@ export default class CreateServiceInstance extends React.Component {

this.state = {
errs: [],
spaces: SpaceStore.getAll(),
createError: ServiceInstanceStore.createError
spaces: SpaceStore.getAll()
};

this.validateString = validateString().bind(this);
Expand Down
2 changes: 1 addition & 1 deletion static_src/stores/service_instance_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class ServiceInstanceStore extends BaseStore {
}

case serviceActionTypes.SERVICE_INSTANCE_CREATE_ERROR: {
this._createInstanceForm = Object.assign({}, this._createInstanceForm, {
this._createInstanceForm = Object.assign({}, this._createInstanceForm || {}, {
error: {
description: getFriendlyError(action.error, SERVICE_INSTANCE_CREATE_ERROR_MAP)
}
Expand Down
39 changes: 26 additions & 13 deletions static_src/test/unit/actions/service_actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,36 @@ describe('serviceActions', function() {
});
});

describe('createInstanceForm()', function() {
it(`should dispatch a view event of type create instance form with the
service guid and service plan guid`, function() {
var expectedServiceGuid = 'wqphjhajkajkhadjhfd',
expectedServicePlanGuid = 'fp2ajkdsfadgh32fasd';
describe('createInstanceForm()', () => {
const expectedServiceGuid = 'wqphjhajkajkhadjhfd';
const expectedServicePlanGuid = 'fp2ajkdsfadgh32fasd';

let expectedParams = {
servicePlanGuid: expectedServicePlanGuid,
serviceGuid: expectedServiceGuid
};
let spy = setupViewSpy(sandbox);
const expectedParams = {
servicePlanGuid: expectedServicePlanGuid,
serviceGuid: expectedServiceGuid
};

it('should dispatch a form cancel action', (done) => {
let uiSpy = setupUISpy(sandbox);

serviceActions.createInstanceForm(expectedServiceGuid,
expectedServicePlanGuid);
expectedServicePlanGuid).then(() => {
assertAction(uiSpy, serviceActionTypes.SERVICE_INSTANCE_CREATE_FORM_CANCEL);
done();
}, done.fail);
});

assertAction(spy, serviceActionTypes.SERVICE_INSTANCE_CREATE_FORM,
expectedParams);
it('should dispatch a form create action', (done) => {
let viewSpy = setupViewSpy(sandbox);

sandbox.stub(serviceActions, 'createInstanceFormCancel').returns(Promise.resolve());

serviceActions.createInstanceForm(expectedServiceGuid,
expectedServicePlanGuid).then(() => {
assertAction(viewSpy, serviceActionTypes.SERVICE_INSTANCE_CREATE_FORM,
expectedParams);
done();
}, done.fail);
});
});

Expand Down
16 changes: 2 additions & 14 deletions static_src/test/unit/components/create_service_instance.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,13 @@ import '../../global_setup';
import React from 'react';
import CreateServiceInstance from '../../../components/create_service_instance.jsx';
import FormError from '../../../components/form/form_error.jsx';
import Immutable from 'immutable';
import SpaceStore from '../../../stores/space_store';
import ServiceInstanceStore from '../../../stores/service_instance_store';
import serviceActions from '../../../actions/service_actions';
import { shallow } from 'enzyme';

describe('<CreateServiceInstance />', () => {
beforeEach(() => {
ServiceInstanceStore._createError = { description: 'Bad stuff everyone' };
});

afterEach(() => {
ServiceInstanceStore._createError = null;
});

it('displays an error message when ServiceInstanceStore has one', () => {
SpaceStore._data = Immutable.fromJS([]);

const wrapper = shallow(<CreateServiceInstance servicePlan={ {} } />);
const error = { description: 'Bad stuff everyone' };
const wrapper = shallow(<CreateServiceInstance servicePlan={ {} } error={ error } />);

expect(wrapper.find(FormError).length).toBe(1);
});
Expand Down
35 changes: 18 additions & 17 deletions static_src/test/unit/stores/service_instance_store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,23 @@ describe('ServiceInstanceStore', function() {
});
});

describe('on service instance create ui', function() {
it('should set createInstanceForm to object with service and plan from stores',
function() {
var expectedService = { guid: 'adsf3232222a' },
expectedServicePlan = { guid: 'zxvczvqe' };
describe('on service instance create ui', () => {
it('should set createInstanceForm to object with service and plan from stores', (done) => {
const expectedService = { guid: 'adsf3232222a' };
const expectedServicePlan = { guid: 'zxvczvqe' };

sandbox.stub(ServiceStore, 'get').returns(expectedService);
sandbox.stub(ServicePlanStore, 'get').returns(expectedServicePlan);
sandbox.stub(serviceActions, 'createInstanceFormCancel').returns(Promise.resolve());

serviceActions.createInstanceForm('adfkjvnzxczv', 'aldsfjalqwe');

let actual = ServiceInstanceStore.createInstanceForm;
serviceActions.createInstanceForm('adfkjvnzxczv', 'aldsfjalqwe').then(() => {
const actual = ServiceInstanceStore.createInstanceForm;

expect(actual).toBeTruthy();
expect(actual.service).toEqual(expectedService);
expect(actual.servicePlan).toEqual(expectedServicePlan);
expect(actual).toBeTruthy();
expect(actual.service).toEqual(expectedService);
expect(actual.servicePlan).toEqual(expectedServicePlan);
done();
}, done);
});

it('should emit a change event', function() {
Expand Down Expand Up @@ -295,7 +296,7 @@ describe('ServiceInstanceStore', function() {
return { response: { data: { error_code: code } } };
};

it('should set `createError` based on error received', () => {
it('should set error props of instance form based on error received', () => {
const serverError = { code: 500 };
const argumentError = serviceInstanceError('CF-MessageParseError');
const spaceError = serviceInstanceError('CF-ServiceInstanceInvalid');
Expand All @@ -307,35 +308,35 @@ describe('ServiceInstanceStore', function() {
let actual;

serviceActions.errorCreateInstance(serverError);
actual = ServiceInstanceStore.createError;
actual = ServiceInstanceStore._createInstanceForm.error;

expect(actual).toEqual({
description: serverErrorMsg
});

serviceActions.errorCreateInstance(argumentError);
actual = ServiceInstanceStore.createError;
actual = ServiceInstanceStore._createInstanceForm.error;

expect(actual).toEqual({
description: SERVICE_INSTANCE_CREATE_ERROR_MAP['CF-MessageParseError']
});

serviceActions.errorCreateInstance(spaceError);
actual = ServiceInstanceStore.createError;
actual = ServiceInstanceStore._createInstanceForm.error;

expect(actual).toEqual({
description: SERVICE_INSTANCE_CREATE_ERROR_MAP['CF-ServiceInstanceInvalid']
});

serviceActions.errorCreateInstance(configError);
actual = ServiceInstanceStore.createError;
actual = ServiceInstanceStore._createInstanceForm.error;

expect(actual).toEqual({
description: SERVICE_INSTANCE_CREATE_ERROR_MAP['CF-ServiceBrokerBadResponse']
});

serviceActions.errorCreateInstance(dupeNameError);
actual = ServiceInstanceStore.createError;
actual = ServiceInstanceStore._createInstanceForm.error;

expect(actual).toEqual({
description: SERVICE_INSTANCE_CREATE_ERROR_MAP['CF-ServiceInstanceNameTaken']
Expand Down

0 comments on commit 52b3d07

Please sign in to comment.