Skip to content

Commit

Permalink
add custom step tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Bassetti authored and Lucas Bassetti committed Apr 15, 2017
1 parent 51a24a0 commit a8df1d3
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/ChatBot.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import Random from 'random-id';
import { CustomStep, OptionsStep, TextStep } from './steps/steps';
Expand Down Expand Up @@ -268,6 +269,7 @@ class ChatBot extends Component {

renderStep(step, index) {
const { renderedSteps, previousSteps } = this.state;
const { customStyle } = this.props;
const { options, component } = step;
const steps = {};
const stepIndex = renderedSteps.map(s => s.id).indexOf(step.id);
Expand All @@ -289,6 +291,7 @@ class ChatBot extends Component {
key={index}
step={step}
steps={steps}
style={customStyle}
previousStep={previousStep}
triggerNextStep={this.triggerNextStep}
/>
Expand Down Expand Up @@ -371,6 +374,7 @@ ChatBot.propTypes = {
contentStyle: PropTypes.object,
footerStyle: PropTypes.object,
inputStyle: PropTypes.object,
customStyle: PropTypes.object,
botAvatar: PropTypes.string,
botBubbleColor: PropTypes.string,
botFontColor: PropTypes.string,
Expand All @@ -388,6 +392,7 @@ ChatBot.defaultProps = {
contentStyle: {},
footerStyle: {},
inputStyle: {},
customStyle: {},
botBubbleColor: '#eee',
botFontColor: '#000',
userBubbleColor: '#baf5fd',
Expand Down
12 changes: 10 additions & 2 deletions lib/steps/CustomStep.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styles from './CustomStep.styles';

class CustomStep extends Component {
Expand Down Expand Up @@ -36,10 +37,16 @@ class CustomStep extends Component {

render() {
const { loading } = this.state;
const { style } = this.props;
const customStyle = Object.assign(
{},
styles.customStep,
style,
);
return (
<div
className="custom-step"
style={styles.customStep}
style={customStyle}
>
{ loading ? (
<span style={styles.loading}>Loading ...</span>
Expand All @@ -52,6 +59,7 @@ class CustomStep extends Component {
CustomStep.propTypes = {
step: PropTypes.object.isRequired,
steps: PropTypes.object.isRequired,
style: PropTypes.object.isRequired,
previousStep: PropTypes.object.isRequired,
triggerNextStep: PropTypes.func.isRequired,
};
Expand Down
3 changes: 2 additions & 1 deletion lib/steps/OptionsStep.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import styles from './OptionsStep.styles';

Expand Down
3 changes: 2 additions & 1 deletion lib/steps/TextStep.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styles from './TextStep.styles';

class TextStep extends Component {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
},
"dependencies": {
"lodash": "^4.17.4",
"prop-types": "^15.5.8",
"random-id": "0.0.2",
"react": "^15.0.1",
"react-dom": "^15.0.1"
Expand Down
45 changes: 45 additions & 0 deletions tests/lib/steps/CustomStep.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { describe, it } from 'mocha';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import { CustomStep } from '../../../lib/steps/steps';

const Example = () => (
<div className="example">
Example
</div>
);

describe('CustomStep', () => {
const steps = {
step1: {
id: '1',
component: <Example />,
},
};
const step = steps.step1;
const settings = {
step,
steps,
style: {
border: 0,
},
previousStep: step,
triggerNextStep: () => {},
};

const wrapper = shallow(<CustomStep {...settings} />);
wrapper.setState({ loading: false });

it('should render', () => {
expect(wrapper.hasClass('custom-step')).to.be.equal(true);
});

it('should render without border', () => {
expect(wrapper.find('.custom-step').prop('style').border).to.be.equal(0);
});

it('should render with Example component', () => {
expect(wrapper.find(Example)).to.have.length(1);
});
});

0 comments on commit a8df1d3

Please sign in to comment.