Permalink
Browse files

improved vote reset support

  • Loading branch information...
teropa committed Sep 6, 2015
1 parent a6bc6f4 commit 80b1cd682f39e7eca37dde030a702bf06ac95478
Showing with 19 additions and 1 deletion.
  1. +4 −1 src/core.js
  2. +12 −0 test/core_spec.js
  3. +3 −0 test/reducer_spec.js
View
@@ -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)
});
}
View
@@ -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')
@@ -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,
@@ -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')
@@ -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,
@@ -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')
@@ -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,
@@ -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
@@ -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,
@@ -135,6 +144,7 @@ describe('application logic', () => {
}), 'Trainspotting')
).to.equal(
Map({
round: 1,
pair: List.of('Trainspotting', '28 Days Later'),
tally: Map({
'Trainspotting': 4,
@@ -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')
})
);
View
@@ -24,6 +24,7 @@ describe('reducer', () => {
expect(nextState).to.equal(fromJS({
vote: {
round: 1,
pair: ['Trainspotting', '28 Days Later']
},
entries: []
@@ -33,6 +34,7 @@ describe('reducer', () => {
it('handles VOTE', () => {
const initialState = fromJS({
vote: {
round: 1,
pair: ['Trainspotting', '28 Days Later']
},
entries: []
@@ -42,6 +44,7 @@ describe('reducer', () => {
expect(nextState).to.equal(fromJS({
vote: {
round: 1,
pair: ['Trainspotting', '28 Days Later'],
tally: {Trainspotting: 1}
},

0 comments on commit 80b1cd6

Please sign in to comment.