Skip to content

Commit

Permalink
improved vote reset support
Browse files Browse the repository at this point in the history
  • Loading branch information
teropa committed Sep 10, 2015
1 parent a6bc6f4 commit 80b1cd6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export function next(state) {
.set('winner', entries.first());
} else {
return state.merge({
vote: Map({pair: entries.take(2)}),
vote: Map({
round: state.getIn(['vote', 'round'], 0) + 1,
pair: entries.take(2)
}),
entries: entries.skip(2)
});
}
Expand Down
12 changes: 12 additions & 0 deletions test/core_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('application logic', () => {
const nextState = next(state);
expect(nextState).to.equal(Map({
vote: Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later')
}),
entries: List.of('Sunshine')
Expand All @@ -46,6 +47,7 @@ describe('application logic', () => {
expect(
next(Map({
vote: Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later'),
tally: Map({
'Trainspotting': 4,
Expand All @@ -57,6 +59,7 @@ describe('application logic', () => {
).to.equal(
Map({
vote: Map({
round: 2,
pair: List.of('Sunshine', 'Millions')
}),
entries: List.of('127 Hours', 'Trainspotting')
Expand All @@ -68,6 +71,7 @@ describe('application logic', () => {
expect(
next(Map({
vote: Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later'),
tally: Map({
'Trainspotting': 3,
Expand All @@ -79,6 +83,7 @@ describe('application logic', () => {
).to.equal(
Map({
vote: Map({
round: 2,
pair: List.of('Sunshine', 'Millions')
}),
entries: List.of('127 Hours', 'Trainspotting', '28 Days Later')
Expand All @@ -90,6 +95,7 @@ describe('application logic', () => {
expect(
next(Map({
vote: Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later'),
tally: Map({
'Trainspotting': 4,
Expand All @@ -112,10 +118,12 @@ describe('application logic', () => {
it('creates a tally for the voted entry', () => {
expect(
vote(Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later')
}), 'Trainspotting')
).to.equal(
Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later'),
tally: Map({
'Trainspotting': 1
Expand All @@ -127,6 +135,7 @@ describe('application logic', () => {
it('adds to existing tally for the voted entry', () => {
expect(
vote(Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later'),
tally: Map({
'Trainspotting': 3,
Expand All @@ -135,6 +144,7 @@ describe('application logic', () => {
}), 'Trainspotting')
).to.equal(
Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later'),
tally: Map({
'Trainspotting': 4,
Expand All @@ -147,10 +157,12 @@ describe('application logic', () => {
it('ignores the vote if for an invalid entry', () => {
expect(
vote(Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later')
}), 'Sunshine')
).to.equal(
Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later')
})
);
Expand Down
3 changes: 3 additions & 0 deletions test/reducer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('reducer', () => {

expect(nextState).to.equal(fromJS({
vote: {
round: 1,
pair: ['Trainspotting', '28 Days Later']
},
entries: []
Expand All @@ -33,6 +34,7 @@ describe('reducer', () => {
it('handles VOTE', () => {
const initialState = fromJS({
vote: {
round: 1,
pair: ['Trainspotting', '28 Days Later']
},
entries: []
Expand All @@ -42,6 +44,7 @@ describe('reducer', () => {

expect(nextState).to.equal(fromJS({
vote: {
round: 1,
pair: ['Trainspotting', '28 Days Later'],
tally: {Trainspotting: 1}
},
Expand Down

0 comments on commit 80b1cd6

Please sign in to comment.