Skip to content

Commit

Permalink
CountdownForm Testing Done Succesfully
Browse files Browse the repository at this point in the history
  • Loading branch information
viruhemanth committed Dec 23, 2016
1 parent bf6c3f2 commit d3f14ec
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"jshint.enable": false
}
2 changes: 1 addition & 1 deletion app/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Countdown = require('Countdown');
require('style!css!foundation-sites/dist/css/foundation.min.css')

$(document).foundation();

// Loading Css
require('style!css!sass!applicationStyles')

ReactDOM.render(
Expand Down
2 changes: 2 additions & 0 deletions app/components/Clock.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var React = require('react');


var Clock = React.createClass({
getInitialProps : function () {
totalSeconds : 0
Expand All @@ -25,6 +26,7 @@ var Clock = React.createClass({
<span className="clock-text">
{this.formatSeconds(totalSeconds)}
</span>

</div>
);
}
Expand Down
27 changes: 27 additions & 0 deletions app/components/CountDownForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var React = require('react');

var CountdownForm = React.createClass({
onSubmit : function (e) {
e.preventDefault();
var strSeconds = this.refs.seconds.value;

if(strSeconds.match(/^[0-9,]*$/)) {
this.refs.seconds.value = '';
this.props.onSetCountDown(parseInt(strSeconds,10));
}
},
render : function () {
return(
<div>
<form ref="form" onSubmit={this.onSubmit} className="countdown-form">
<input type="text" ref="seconds" placeholder="Enter time in seconds"/>
<button className="button expanded">Start</button>
</form>
</div>
);
}
});



module.exports = CountdownForm;
17 changes: 16 additions & 1 deletion app/components/Countdown.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
var React = require('react');
var Clock = require('Clock');
var CountdownForm = require('CountdownForm');
var Countdown = React.createClass({

getInitialState : function () {
return {
count : 0
};
},
handleSetCountDown : function (seconds) {
this.setState({
count : seconds
});
},
render : function () {
var {count} = this.state;

return (
<div>
<Clock totalSeconds={1190}/>
<Clock totalSeconds={count}/>
<CountdownForm onSetCountDown = {this.handleSetCountDown}/>
</div>
);
}
Expand Down
13 changes: 6 additions & 7 deletions app/components/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ var Main = React.createClass({
render: function() {
return (
<div>
<div>

<NavBar/>
<h2> Main.jsx</h2>

{this.props.children}
</div>
<NavBar/>
<div className="row">
<div className="column small-centered medium-6 large-4">
{this.props.children}
</div>
</div>
</div>

);
}
Expand Down
3 changes: 1 addition & 2 deletions app/tests/components/Clock.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var React = require('react');
var ReactDOM = require('react-dom');
var expect = require('expect');
var $ = require('jQuery');

var TestUtils = require('react-addons-test-utils');

var Clock = require('Clock');
Expand All @@ -16,7 +15,7 @@ describe('Clock', ()=> {
it('should render clock component',()=>{
var clock = TestUtils.renderIntoDocument(<Clock totalSeconds = {90}/>);
var $el = $(ReactDOM.findDOMNode(clock));
var actualText = $el.find('.clock-test').text();
var actualText = $el.find('.clock-text').text();
expect(actualText).toBe('01:30');
});
});
Expand Down
34 changes: 34 additions & 0 deletions app/tests/components/CountDownForm.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var expect = require('expect');
var React = require('react');
var ReactDOM = require('react-dom');
var TestUtils = require('react-addons-test-utils');
var $ = require('jQuery');

var CountdownForm = require('CountdownForm');

describe('CountdownForm', () => {
it('should exist', () => {
expect(CountdownForm).toExist();
});
it('should call onSetCountDown if valid seconds entered', ()=>{
var spy = expect.createSpy();
var countdownForm = TestUtils.renderIntoDocument(<CountdownForm onSetCountDown={spy} />);
var $el = $(ReactDOM.findDOMNode(countdownForm));
countdownForm.refs.seconds.value = '109';

TestUtils.Simulate.submit($el.find('form')[0]);

expect(spy).toHaveBeenCalledWith(109);
});

it('should call onSetCountDown if valid seconds not entered', ()=>{
var spy = expect.createSpy();
var countdownForm = TestUtils.renderIntoDocument(<CountdownForm onSetCountDown={spy} />);
var $el = $(ReactDOM.findDOMNode(countdownForm));
countdownForm.refs.seconds.value = '109j';

TestUtils.Simulate.submit($el.find('form')[0]);

expect(spy).toNotHaveBeenCalled();
});
});
37 changes: 22 additions & 15 deletions public/bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports = {
NavBar : 'app/components/NavBar.jsx',
Timer : 'app/components/Timer.jsx',
Countdown : 'app/components/Countdown.jsx',
Clock : 'app/components/Clock.jsx'
Clock : 'app/components/Clock.jsx',
CountdownForm : 'app/components/CountdownForm.jsx'
},
extensions: ['', '.js', '.jsx']
},
Expand Down

0 comments on commit d3f14ec

Please sign in to comment.