Skip to content

Commit 073940e

Browse files
Merge pull request zoltantothcom#28 from zoltantothcom/dev
Test coverage improved
2 parents 8e74ddf + 0fd3c15 commit 073940e

File tree

3 files changed

+61
-15
lines changed

3 files changed

+61
-15
lines changed

__tests__/reducers/reducers.test.js

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
import reducer from '../../src/reducers';
2-
import { SUBMIT, TOGGLE, TOGGLE_JS, TOGGLE_MODE } from '../../src/static/constants/actions';
2+
import {
3+
SUBMIT,
4+
TOGGLE,
5+
TOGGLE_JS,
6+
TOGGLE_MODE,
7+
RESTART
8+
} from '../../src/static/constants/actions';
39

410
const answers = [
511
{
612
name: 'Template',
713
type: 'behavioral',
8-
codeES5: 'Code ES5',
9-
codeES6: 'Code ES6',
10-
answered: false,
11-
correct: null,
12-
answerId: null,
14+
answered: true,
15+
correct: true,
16+
answerId: 'ba2ca6b0-0c86-4573-baf0-60f33ce6e947',
1317
uuid: 'ba2ca6b0-0c86-4573-baf0-60f33ce6e947'
1418
},
1519
{
1620
name: 'Visitor',
1721
type: 'behavioral',
18-
codeES5: 'Code ES5',
19-
codeES6: 'Code ES6',
2022
answered: false,
2123
correct: null,
2224
answerId: null,
2325
uuid: 'eb9427c5-0167-4d65-a99b-a5ffadf5fd46'
26+
},
27+
{
28+
name: 'Singleton',
29+
type: 'creational',
30+
answered: false,
31+
correct: null,
32+
answerId: null,
33+
uuid: 'slearknbqarlnbqasOLdnv'
2434
}
2535
];
2636

@@ -75,22 +85,57 @@ describe('Reducers', () => {
7585
});
7686
});
7787

78-
xit('should handle SUBMIT', () => {
88+
it('should handle SUBMIT', () => {
7989
const action = {
8090
type: SUBMIT,
8191
payload: {
82-
currentIndex: 0,
83-
remainingPatterns: answers[1],
92+
currentIndex: 1,
93+
remainingPatterns: [answers[1], answers[2]],
8494
recentlyAnswered: answers[0]
8595
}
8696
};
8797

8898
expect(reducer(initialState, action)).toMatchObject({
8999
...initialState,
90100
progress: {
91-
remaining: [answers[1]],
101+
remaining: [answers[1], answers[2]],
92102
answers: [answers[0]],
93-
current: answers[1]
103+
current: answers[2]
104+
}
105+
});
106+
});
107+
108+
it('should handle the _last_ SUBMIT', () => {
109+
const action = {
110+
type: SUBMIT,
111+
payload: {
112+
currentIndex: null,
113+
remainingPatterns: [],
114+
recentlyAnswered: answers[2]
115+
}
116+
};
117+
118+
expect(reducer(initialState, action)).toMatchObject({
119+
...initialState,
120+
progress: {
121+
remaining: [],
122+
answers: [answers[2]],
123+
current: null
124+
}
125+
});
126+
});
127+
128+
it('should handle RESTART', () => {
129+
const action = {
130+
type: RESTART,
131+
payload: null
132+
};
133+
134+
expect(reducer(initialState, action)).toMatchObject({
135+
...initialState,
136+
progress: {
137+
remaining: answers,
138+
answers: []
94139
}
95140
});
96141
});

src/pages/Game.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const Game = ({ current, answers, style, onRestart }) => {
6161
<TwitterButton
6262
className="twitter-share-button"
6363
data-dnt="true"
64-
href={`https://twitter.com/intent/tweet?text=I%20scored%20${correct}%20out%20of%2023%20in%20JavaScript%20Design%20Patterns%20game!%20Try%20it!&url=http://javascript-design-patterns.surge.sh/`}
64+
href={`https://twitter.com/intent/tweet?text=I%20scored%20${correct}%20out%20of%2023%20in%20JavaScript%20Design%20Patterns%20game!%20Try%20it!&url=http://design-patterns-javascript.surge.sh/`}
6565
>
6666
Tweet Your Score
6767
</TwitterButton>

stories/Button.stories.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import Provider from './Provider.js';
3+
import { action } from '@storybook/addon-actions';
34
import { storiesOf } from '@storybook/react';
45
import { withKnobs, text } from '@storybook/addon-knobs';
56
import Button from '../src/components/Button';
@@ -12,5 +13,5 @@ storiesOf('Button', module)
1213
.addDecorator(withKnobs)
1314

1415
.add('default', () => (
15-
<Button label={text('label', 'Hello Button')} id="abc" onClick={() => console.log('click')} />
16+
<Button label={text('label', 'Hello Button')} id="abc" onClick={action('button-click')} />
1617
));

0 commit comments

Comments
 (0)