Skip to content

Commit

Permalink
Added WelcomePage
Browse files Browse the repository at this point in the history
  • Loading branch information
tomazy committed Aug 27, 2018
1 parent 136c546 commit e1245ae
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ export class App extends React.Component {
public render() {
debug('render', this.state)
return (
<WelcomePage numQuestions={10} />
<WelcomePage
numQuestions={10}
onBegin={this.handleOnBegin}
/>
)
}

private handleOnBegin = () => {
debug('handleOnBegin')
}
}
3 changes: 2 additions & 1 deletion src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import 'jest-enzyme'
import * as React from 'react'

import { App } from '../App'
import { WelcomePage } from '../pages/WelcomePage'

describe('<App />', () => {
it('has the happy path', () => {
const app = shallow(<App />)
expect(app).toIncludeText('Welcome to the Trivia Challenge!')
expect(app.find(WelcomePage)).toExist()
})
})
5 changes: 3 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Trivia Game</title>
</head>
<body class="near-black bg-pink sans-serif">
<div id="app"></div>
<body class="near-black sans-serif">
<div id="app" class="mw6 center tc">
</div>
</body>
</html>
26 changes: 26 additions & 0 deletions src/pages/WelcomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react'

export type OnBegin = () => void

interface Props {
numQuestions: number
onBegin: OnBegin
}

export const WelcomePage = ({ numQuestions, onBegin }: Props) => (
<div>
<h1>Welcome to the Trivia Challenge!</h1>

<p>
You will be presented with {numQuestions} <strong>True</strong> or <strong>False</strong> questions.
</p>

<p>
Can you score 100%?
</p>

<div>
<button onClick={() => onBegin()}>Begin</button>
</div>
</div>
)
35 changes: 35 additions & 0 deletions src/pages/__tests__/WelcomePage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { mount, shallow } from 'enzyme'
import 'jest-enzyme'
import * as React from 'react'

import { OnBegin, WelcomePage } from '../../pages/WelcomePage'

describe('<WelcomePage />', () => {
let onBeginMock: OnBegin

beforeEach(() => {
onBeginMock = jest.fn()
})

it('renders the number of questions', () => {
const numQuestions = 1234567
const page = shallow(
<WelcomePage
numQuestions={numQuestions}
onBegin={onBeginMock}
/>
)
expect(page).toIncludeText(String(numQuestions))
})

it('handles the button click', () => {
const page = mount(
<WelcomePage
numQuestions={5}
onBegin={onBeginMock}
/>
)
page.find('button').simulate('click')
expect(onBeginMock).toHaveBeenCalled()
})
})
10 changes: 8 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
Expand Down Expand Up @@ -55,5 +55,11 @@
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
],
"exclude": [
]
}

0 comments on commit e1245ae

Please sign in to comment.