From c3a30cee46c41a4dbbdb026d9a0143afa9a5e1af Mon Sep 17 00:00:00 2001 From: Jeason Centaure Date: Fri, 26 Jan 2018 15:34:26 +0100 Subject: [PATCH] feat: ScoreResult component --- components/Question.test.js | 2 +- components/ScoreResult.js | 13 +++++++++++++ components/ScoreResult.test.js | 10 ++++++++++ stories/index.js | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 components/ScoreResult.js create mode 100644 components/ScoreResult.test.js diff --git a/components/Question.test.js b/components/Question.test.js index 4ac9f13..599044e 100644 --- a/components/Question.test.js +++ b/components/Question.test.js @@ -5,6 +5,6 @@ import Question from './Question' describe('#Question', () => { it('should render a question component using ReactMarkdown', () => { const wrapper = shallow() - expect(wrapper.find('Markdown').prop('source')).toEqual('2 + 2 ?') + expect(wrapper.find('Markdown').prop('source')).toBe('2 + 2 ?') }) }) diff --git a/components/ScoreResult.js b/components/ScoreResult.js new file mode 100644 index 0000000..f179d19 --- /dev/null +++ b/components/ScoreResult.js @@ -0,0 +1,13 @@ +import React from 'react' +import PropTypes from 'prop-types' + +const ScoreResult = ({ totalScore, userScore }) => ( +

{`Vous avez obtenu ${userScore}/${totalScore} au quiz React.`}

+) + +ScoreResult.propTypes = { + totalScore: PropTypes.number, + userScore: PropTypes.number, +} + +export default ScoreResult diff --git a/components/ScoreResult.test.js b/components/ScoreResult.test.js new file mode 100644 index 0000000..69510ff --- /dev/null +++ b/components/ScoreResult.test.js @@ -0,0 +1,10 @@ +import React from 'react' +import { shallow } from 'enzyme' +import ScoreResult from './ScoreResult' + +describe('ScoreResult', () => { + it('should render the ScoreResult component', () => { + const wrapper = shallow() + expect(wrapper.text()).toEqual('Vous avez obtenu 12/20 au quiz React.') + }) +}) diff --git a/stories/index.js b/stories/index.js index 1ce04fa..2cef83b 100644 --- a/stories/index.js +++ b/stories/index.js @@ -3,6 +3,7 @@ import { storiesOf } from '@storybook/react' import ProgressBar from '../components/ProgressBar' import Timer from '../components/Timer' import NextButton from '../components/NextButton' +import ScoreResult from '../components/ScoreResult' storiesOf('ProgressBar', module) .add('0/20', () => ) @@ -18,3 +19,8 @@ storiesOf('Timer', module).add('Basic', () => ) storiesOf('NextButton', module) .add('disabled', () => ) .add('not disabled', () => ) +storiesOf('Timer', module).add('Basic Timer', () => ) + +storiesOf('ScoreResult', module).add('12/20 Final Score', () => ( + +))