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

Commit

Permalink
Merge pull request #1197 from 18F/lkb-alt-service-prompt
Browse files Browse the repository at this point in the history
Create default text for specified services with multiple required params
  • Loading branch information
jcscottiii authored Aug 18, 2017
2 parents b6557b0 + cc2d781 commit 7ffd028
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 40 deletions.
117 changes: 77 additions & 40 deletions static_src/components/create_service_instance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ import { validateString } from '../util/validators';

const CREATE_SERVICE_INSTANCE_FORM_GUID = 'create-service-form';

// Note:
// This is a temporary hardcoded solution to resolve the need
// for multiple parameters when setting up service instances.
const CF_CLI_SERVICE_DETAILS = {
'cdn-route': 'https://cloud.gov/docs/services/cdn-route/',
'cloud-gov-identity-provider': 'https://cloud.gov/docs/services/cloud-gov-identity-provider/',
'cloud-gov-service-account': 'https://cloud.gov/docs/services/cloud-gov-service-account/'
};

const propTypes = {
error: PropTypes.object,
service: PropTypes.object,
Expand Down Expand Up @@ -90,6 +99,73 @@ export default class CreateServiceInstance extends React.Component {
serviceActions.createInstanceFormCancel();
}

get formContent() {
const serviceName = this.serviceName;
if (CF_CLI_SERVICE_DETAILS.hasOwnProperty(serviceName)) {
return (
<Form
guid={ CREATE_SERVICE_INSTANCE_FORM_GUID }
classes={ ['test-create_service_instance_form'] }
ref="form"
onSubmit={ this._onValidForm }
>
<legend>
The
<strong className="actions-callout-inline-block">
{ serviceName }
</strong> service instance must be created using the CF CLI.
Please refer to <a href={ CF_CLI_SERVICE_DETAILS[serviceName] }
target="_blank">{ CF_CLI_SERVICE_DETAILS[serviceName] }</a> for more
information.
</legend>
</Form>
);
} else {
return (
<Form
guid={ CREATE_SERVICE_INSTANCE_FORM_GUID }
classes={ ['test-create_service_instance_form'] }
ref="form"
onSubmit={ this._onValidForm }
>
<legend>
Create a service instance for
<strong className="actions-callout-inline-block">
{ this.serviceName }
</strong> using
<strong className="actions-callout-inline-block">
{ this.servicePlanName }
</strong> plan.
</legend>
<FormText
formGuid={ CREATE_SERVICE_INSTANCE_FORM_GUID }
classes={ ['test-create_service_instance_name'] }
label="Choose a name for the service instance"
name="name"
validator={ this.validateString }
/>
<FormSelect
formGuid={ CREATE_SERVICE_INSTANCE_FORM_GUID }
classes={ ['test-create_service_instance_space'] }
label="Select the space for the service instance"
name="space"
options={ this.validSpaceTargets }
validator={ this.validateString }
/>
{ this.contextualAction }
<Action
label="cancel"
style="base"
type="outline"
clickHandler={ this._onCancelForm }
>
Cancel
</Action>
</Form>
);
}
}

get serviceName() {
return this.props.service.label || 'Unknown Service Name';
}
Expand Down Expand Up @@ -139,46 +215,7 @@ export default class CreateServiceInstance extends React.Component {
return (
<div className="actions-large">
{ createError }
<Form
guid={ CREATE_SERVICE_INSTANCE_FORM_GUID }
classes={ ['test-create_service_instance_form'] }
ref="form"
onSubmit={ this._onValidForm }
>
<legend>
Create a service instance for
<strong className="actions-callout-inline-block">
{ this.serviceName }
</strong> using
<strong className="actions-callout-inline-block">
{ this.servicePlanName }
</strong> plan.
</legend>
<FormText
formGuid={ CREATE_SERVICE_INSTANCE_FORM_GUID }
classes={ ['test-create_service_instance_name'] }
label="Choose a name for the service instance"
name="name"
validator={ this.validateString }
/>
<FormSelect
formGuid={ CREATE_SERVICE_INSTANCE_FORM_GUID }
classes={ ['test-create_service_instance_space'] }
label="Select the space for the service instance"
name="space"
options={ this.validSpaceTargets }
validator={ this.validateString }
/>
{ this.contextualAction }
<Action
label="cancel"
style="base"
type="outline"
clickHandler={ this._onCancelForm }
>
Cancel
</Action>
</Form>
{ this.formContent }
</div>
);
}
Expand Down
56 changes: 56 additions & 0 deletions static_src/test/unit/components/create_service_instance.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import serviceActions from '../../../actions/service_actions';
import { shallow } from 'enzyme';

describe('<CreateServiceInstance />', () => {
const serviceBaseProps = {
service: {},
servicePlan: {
guid: 'some-plan-guid'
}
};

it('displays an error message when ServiceInstanceStore has one', () => {
const error = { description: 'Bad stuff everyone' };
const wrapper = shallow(<CreateServiceInstance servicePlan={ {} } error={ error } />);
Expand All @@ -32,4 +39,53 @@ describe('<CreateServiceInstance />', () => {
expect(typeof spy.getCall(0).args[0]).toBe('string');
});
});

describe('when serviceAction.createInstance has pre-designated responses', () => {
it('called for cdn-route', () => {
const serviceInstanceHTML = '<div class="actions-large"><form id="create-service-form"' +
' action="/" method="post" class="test-create_service_instance_form"><fieldset><legend>' +
'The<strong class="actions-callout-inline-block">cdn-route</strong> service instance ' +
'must be created using the CF CLI. Please refer to <a href="https://cloud.gov/docs/' +
'services/cdn-route/" target="_blank">https://cloud.gov/docs/services/cdn-route/</a> ' +
'for more information.</legend></fieldset></form></div>';
const serviceProps = Object.assign({}, serviceBaseProps, {
service: { label: 'cdn-route' }
});
const wrapper = shallow(<CreateServiceInstance { ...serviceProps } />);

expect(wrapper.html()).toEqual(serviceInstanceHTML);
});

it('called for cloud-gov-identity-provider', () => {
const serviceInstanceHTML = '<div class="actions-large"><form id="create-service-form"' +
' action="/" method="post" class="test-create_service_instance_form"><fieldset><legend>' +
'The<strong class="actions-callout-inline-block">cloud-gov-identity-provider</strong> ' +
'service instance must be created using the CF CLI. Please refer to <a href="https:' +
'//cloud.gov/docs/services/cloud-gov-identity-provider/" target="_blank">https://clo' +
'ud.gov/docs/services/cloud-gov-identity-provider/</a> for more information.</legend>' +
'</fieldset></form></div>';
const serviceProps = Object.assign({}, serviceBaseProps, {
service: { label: 'cloud-gov-identity-provider' }
});
const wrapper = shallow(<CreateServiceInstance { ...serviceProps } />);

expect(wrapper.html()).toEqual(serviceInstanceHTML);
});

it('called for cloud-gov-service-account', () => {
const serviceInstanceHTML = '<div class="actions-large"><form id="create-service-form"' +
' action="/" method="post" class="test-create_service_instance_form"><fieldset><legend>' +
'The<strong class="actions-callout-inline-block">cloud-gov-service-account</strong> ' +
'service instance must be created using the CF CLI. Please refer to <a href="' +
'https://cloud.gov/docs/services/cloud-gov-service-account/" target="_blank">https://' +
'cloud.gov/docs/services/cloud-gov-service-account/</a> for more information.</legend>' +
'</fieldset></form></div>';
const serviceProps = Object.assign({}, serviceBaseProps, {
service: { label: 'cloud-gov-service-account' }
});
const wrapper = shallow(<CreateServiceInstance { ...serviceProps } />);

expect(wrapper.html()).toEqual(serviceInstanceHTML);
});
});
});

0 comments on commit 7ffd028

Please sign in to comment.