diff --git a/__tests__/Layout.test.js b/__tests__/Layout.test.js index a6d826b..b7a44fe 100644 --- a/__tests__/Layout.test.js +++ b/__tests__/Layout.test.js @@ -44,6 +44,7 @@ describe('Layout', () => { remaining: [patterns[1]], current: patterns[0] }, + intro: false, mode: 'light', js: 'es5' }); @@ -86,6 +87,7 @@ describe('Layout', () => { remaining: [patterns[1]], current: patterns[0] }, + intro: false, mode: 'dark', js: 'es5' }); diff --git a/__tests__/actions/actions.test.js b/__tests__/actions/actions.test.js index bd9ff0c..4b4a187 100644 --- a/__tests__/actions/actions.test.js +++ b/__tests__/actions/actions.test.js @@ -1,3 +1,4 @@ +import { start } from '../../src/actions/start'; import { restart } from '../../src/actions/restart'; import { submitAnswer } from '../../src/actions/submitAnswer'; import { toggle, toggleJS, toggleMode } from '../../src/actions/toggle'; @@ -6,10 +7,17 @@ import { TOGGLE, TOGGLE_JS, TOGGLE_MODE, + START, RESTART } from '../../src/static/constants/actions'; describe('Action Creators', () => { + it('should dispatch START action', () => { + expect(start('start')).toEqual({ + type: START, + payload: 'start' + }); + }); it('should dispatch RESTART action', () => { expect(restart('restart')).toEqual({ type: RESTART, diff --git a/__tests__/pages/Game.test.js b/__tests__/pages/Game.test.js index fd70fa6..9ae91c6 100644 --- a/__tests__/pages/Game.test.js +++ b/__tests__/pages/Game.test.js @@ -9,7 +9,7 @@ import { themeDark } from '../../src/styles/themes/theme.dark'; import styleLight from '../../src/styles/hljs/hljs.light'; import styleDark from '../../src/styles/hljs/hljs.dark'; import Game from '../../src/pages/Game'; -import { RESTART } from '../../src/static/constants/actions'; +import { START, RESTART } from '../../src/static/constants/actions'; const patterns = [ { @@ -43,6 +43,7 @@ const store = mockStore({ remaining: [patterns[1]], current: patterns[0] }, + intro: false, mode: 'light', js: 'es5' }); @@ -115,6 +116,41 @@ describe('Game page - GAME - DARK style', () => { }); }); +describe('Game page - INTRO', () => { + let tree; + const store = mockStore({ + patterns: patterns, + progress: { + answers: patterns, + remaining: [], + current: null + }, + intro: true, + mode: 'light', + js: 'es5' + }); + + beforeEach(() => { + tree = mount( + + + + + + ); + }); + + it('renders a + + + +`; + exports[`Game page - RESULTS renders a component 1`] = ` .c0 { border: 4px solid red; @@ -958,7 +1071,7 @@ exports[`Game page - RESULTS renders a component 1`] = `null`; exports[`Game page - RESULTS renders a component 1`] = ` .c0 { - color: #0A000A; + color: #6F256F; margin: 3rem 0; text-align: center; } diff --git a/__tests__/reducers/reducers.test.js b/__tests__/reducers/reducers.test.js index a2ef218..7e9a6f1 100644 --- a/__tests__/reducers/reducers.test.js +++ b/__tests__/reducers/reducers.test.js @@ -4,6 +4,7 @@ import { TOGGLE, TOGGLE_JS, TOGGLE_MODE, + START, RESTART } from '../../src/static/constants/actions'; @@ -38,6 +39,7 @@ const initialState = { js: 'es5', mode: 'dark', patterns: answers, + intro: true, progress: { answers: [], remaining: answers, @@ -85,6 +87,17 @@ describe('Reducers', () => { }); }); + it('should toggle INTRO', () => { + const action = { + type: START + }; + + expect(reducer(initialState, action)).toEqual({ + ...initialState, + intro: false + }); + }); + it('should handle SUBMIT', () => { const action = { type: SUBMIT, diff --git a/__tests__/selectors/selectors.test.js b/__tests__/selectors/selectors.test.js index c28bf7b..2202ae4 100644 --- a/__tests__/selectors/selectors.test.js +++ b/__tests__/selectors/selectors.test.js @@ -4,7 +4,8 @@ import { getMode, getJS, getCurrent, - getAnswers + getAnswers, + getIntro } from '../../src/selectors'; describe('Selectors', () => { @@ -14,6 +15,7 @@ describe('Selectors', () => { state = { mode: 'dark', js: 'es6', + intro: true, patterns: [0, 1, 2, 3, 4, 5, 6], progress: { answers: [0, 1, 2], @@ -46,4 +48,8 @@ describe('Selectors', () => { it('should get the JS version', () => { expect(getJS(state)).toBe('es6'); }); + + it('should get the intro value', () => { + expect(getIntro(state)).toBe(true); + }); }); diff --git a/src/actions/start.js b/src/actions/start.js new file mode 100644 index 0000000..c50278f --- /dev/null +++ b/src/actions/start.js @@ -0,0 +1,6 @@ +import { START } from '../static/constants/actions'; + +export const start = payload => ({ + type: START, + payload +}); diff --git a/src/hoc/withThemeProvider.jsx b/src/hoc/withThemeProvider.jsx deleted file mode 100644 index b305ebd..0000000 --- a/src/hoc/withThemeProvider.jsx +++ /dev/null @@ -1,33 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import { compose } from 'redux'; -import { connect } from 'react-redux'; -import { ThemeProvider } from 'styled-components'; -import { themeLight } from '../styles/themes/theme.light'; -import { themeDark } from '../styles/themes/theme.dark'; - -const withThemeProvider = Component => { - const Sub = ({ mode, ...rest }) => ( - - - - ); - - Sub.propTypes = { - mode: PropTypes.string.isRequired - }; - - return Sub; -}; - -const mapStateToProps = ({ mode }) => ({ mode }); - -const composedWrapper = compose( - connect( - mapStateToProps, - null - ), - withThemeProvider -); - -export default composedWrapper; diff --git a/src/pages/Game.jsx b/src/pages/Game.jsx index b69f6c9..35b9939 100644 --- a/src/pages/Game.jsx +++ b/src/pages/Game.jsx @@ -2,8 +2,9 @@ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import styled from 'styled-components'; import { connect } from 'react-redux'; +import { start } from '../actions/start'; import { restart } from '../actions/restart'; -import { getCurrent, getAnswers } from '../selectors'; +import { getIntro, getCurrent, getAnswers } from '../selectors'; import ButtonContainer from '../components/ButtonContainer'; import ProgressBar from '../components/ProgressBar'; import Code from '../components/Code'; @@ -11,6 +12,19 @@ import Result from '../components/Result'; import Percentage from '../components/Percentage'; import Button from '../components/Button'; +const Intro = styled.div` + border: 1px solid ${props => props.theme.border}; + border-radius: 4px; + color: ${props => props.theme.text}; + margin: 2rem 0; + padding: 2rem 3rem; +`; + +const StartButtonContainer = styled.div` + margin: 3rem auto 1rem; + /* text-align: center; */ +`; + const Restart = styled.div` margin: 3rem 0; text-align: center; @@ -35,7 +49,7 @@ const ShareContainer = styled.p` text-align: center; `; -const Game = ({ current, answers, style, onRestart }) => { +const Game = ({ intro, current, answers, style, onStart, onRestart }) => { let correct; if (!current) { @@ -44,13 +58,29 @@ const Game = ({ current, answers, style, onRestart }) => { return ( - {current ? ( + {intro && ( + +

+ Each question contains a code snippet and four answer choices. +
+ Look carefully at the code and choose the one correct answer. +

+

After answering all 23 questions you'll be shown your results.

+ +