Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alvaro Muhlethaler
committed
Aug 10, 2016
1 parent
a02681f
commit 691cf43
Showing
13 changed files
with
206 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var React = require('react'); | ||
|
||
var Clock = React.createClass({ | ||
getDefaultProps: function() { | ||
return { | ||
totalSeconds: 0 | ||
}; | ||
}, | ||
propTypes: { | ||
totalSeconds: React.PropTypes.number | ||
}, | ||
formatSeconds: function (totalSeconds) { | ||
var seconds = totalSeconds % 60; | ||
var minutes = Math.floor(totalSeconds / 60); | ||
|
||
if(seconds < 10){ | ||
seconds = '0' + seconds; | ||
} | ||
|
||
if(minutes < 10){ | ||
minutes = '0' + minutes; | ||
} | ||
|
||
return minutes + ':' + seconds; | ||
}, | ||
render: function() { | ||
var {totalSeconds} = this.props; | ||
return ( | ||
<div className="clock"> | ||
<span className="clock-text">{this.formatSeconds(totalSeconds)}</span> | ||
</div> | ||
); | ||
} | ||
|
||
}); | ||
|
||
module.exports = Clock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import "base/variables"; | ||
@import "components/nav"; | ||
@import "components/clock" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.clock { | ||
align-items: center; | ||
background-color: $clock-bg-color; | ||
border: 2px solid $clock-border-color; | ||
border-radius: 50%; | ||
display: flex; | ||
height: 14rem; | ||
justify-content: center; | ||
margin: 4rem auto; | ||
width: 14rem; | ||
} | ||
|
||
.clock-text { | ||
color: $clock-text-color; | ||
font-size: 2.25rem; | ||
font-weight: 300; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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'); | ||
|
||
describe('Clock', () => { | ||
it('should exist', () => { | ||
expect(Clock).toExist(); | ||
}); | ||
|
||
describe('render', () => { | ||
it('should render clock to output', () => { | ||
var clock = TestUtils.renderIntoDocument(<Clock totalSeconds={62}/>); | ||
var $el = $(ReactDOM.findDOMNode(clock)); | ||
var actualText = $el.find('.clock-text').text(); | ||
expect(actualText).toBe('01:02'); | ||
}); | ||
}); | ||
|
||
describe('formatSeconds', () => { | ||
it('should format seconds', () => { | ||
var clock = TestUtils.renderIntoDocument(<Clock/>); | ||
var seconds = 615; | ||
var expected = '10:15'; | ||
var actual = clock.formatSeconds(seconds); | ||
expect(actual).toBe(expected); | ||
}); | ||
|
||
it('should format seconds when min/sec are less than 10', () => { | ||
var clock = TestUtils.renderIntoDocument(<Clock/>); | ||
var seconds = 61; | ||
var expected = '01:01'; | ||
var actual = clock.formatSeconds(seconds); | ||
expect(actual).toBe(expected); | ||
}); | ||
}); | ||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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'; | ||
var form = $el.find('form')[0]; | ||
TestUtils.Simulate.submit(form); | ||
|
||
expect(spy).toHaveBeenCalledWith(109); | ||
}); | ||
|
||
it('should not call onSetCountdown if invalid seconds entered', () => { | ||
var spy = expect.createSpy(); | ||
var countdownForm = TestUtils.renderIntoDocument(<CountdownForm onSetCountdown={spy}/>); | ||
var $el = $(ReactDOM.findDOMNode(countdownForm)); | ||
|
||
countdownForm.refs.seconds.value = '10as'; | ||
var form = $el.find('form')[0]; | ||
TestUtils.Simulate.submit(form); | ||
|
||
expect(spy).toNotHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters