Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 58 additions & 13 deletions __tests__/reducers/reducers.test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import reducer from '../../src/reducers';
import { SUBMIT, TOGGLE, TOGGLE_JS, TOGGLE_MODE } from '../../src/static/constants/actions';
import {
SUBMIT,
TOGGLE,
TOGGLE_JS,
TOGGLE_MODE,
RESTART
} from '../../src/static/constants/actions';

const answers = [
{
name: 'Template',
type: 'behavioral',
codeES5: 'Code ES5',
codeES6: 'Code ES6',
answered: false,
correct: null,
answerId: null,
answered: true,
correct: true,
answerId: 'ba2ca6b0-0c86-4573-baf0-60f33ce6e947',
uuid: 'ba2ca6b0-0c86-4573-baf0-60f33ce6e947'
},
{
name: 'Visitor',
type: 'behavioral',
codeES5: 'Code ES5',
codeES6: 'Code ES6',
answered: false,
correct: null,
answerId: null,
uuid: 'eb9427c5-0167-4d65-a99b-a5ffadf5fd46'
},
{
name: 'Singleton',
type: 'creational',
answered: false,
correct: null,
answerId: null,
uuid: 'slearknbqarlnbqasOLdnv'
}
];

Expand Down Expand Up @@ -75,22 +85,57 @@ describe('Reducers', () => {
});
});

xit('should handle SUBMIT', () => {
it('should handle SUBMIT', () => {
const action = {
type: SUBMIT,
payload: {
currentIndex: 0,
remainingPatterns: answers[1],
currentIndex: 1,
remainingPatterns: [answers[1], answers[2]],
recentlyAnswered: answers[0]
}
};

expect(reducer(initialState, action)).toMatchObject({
...initialState,
progress: {
remaining: [answers[1]],
remaining: [answers[1], answers[2]],
answers: [answers[0]],
current: answers[1]
current: answers[2]
}
});
});

it('should handle the _last_ SUBMIT', () => {
const action = {
type: SUBMIT,
payload: {
currentIndex: null,
remainingPatterns: [],
recentlyAnswered: answers[2]
}
};

expect(reducer(initialState, action)).toMatchObject({
...initialState,
progress: {
remaining: [],
answers: [answers[2]],
current: null
}
});
});

it('should handle RESTART', () => {
const action = {
type: RESTART,
payload: null
};

expect(reducer(initialState, action)).toMatchObject({
...initialState,
progress: {
remaining: answers,
answers: []
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Game = ({ current, answers, style, onRestart }) => {
<TwitterButton
className="twitter-share-button"
data-dnt="true"
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/`}
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/`}
>
Tweet Your Score
</TwitterButton>
Expand Down
3 changes: 2 additions & 1 deletion stories/Button.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import Provider from './Provider.js';
import { action } from '@storybook/addon-actions';
import { storiesOf } from '@storybook/react';
import { withKnobs, text } from '@storybook/addon-knobs';
import Button from '../src/components/Button';
Expand All @@ -12,5 +13,5 @@ storiesOf('Button', module)
.addDecorator(withKnobs)

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