Skip to content

Commit 80b1cd6

Browse files
committed
improved vote reset support
1 parent a6bc6f4 commit 80b1cd6

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/core.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export function next(state) {
2525
.set('winner', entries.first());
2626
} else {
2727
return state.merge({
28-
vote: Map({pair: entries.take(2)}),
28+
vote: Map({
29+
round: state.getIn(['vote', 'round'], 0) + 1,
30+
pair: entries.take(2)
31+
}),
2932
entries: entries.skip(2)
3033
});
3134
}

test/core_spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('application logic', () => {
3636
const nextState = next(state);
3737
expect(nextState).to.equal(Map({
3838
vote: Map({
39+
round: 1,
3940
pair: List.of('Trainspotting', '28 Days Later')
4041
}),
4142
entries: List.of('Sunshine')
@@ -46,6 +47,7 @@ describe('application logic', () => {
4647
expect(
4748
next(Map({
4849
vote: Map({
50+
round: 1,
4951
pair: List.of('Trainspotting', '28 Days Later'),
5052
tally: Map({
5153
'Trainspotting': 4,
@@ -57,6 +59,7 @@ describe('application logic', () => {
5759
).to.equal(
5860
Map({
5961
vote: Map({
62+
round: 2,
6063
pair: List.of('Sunshine', 'Millions')
6164
}),
6265
entries: List.of('127 Hours', 'Trainspotting')
@@ -68,6 +71,7 @@ describe('application logic', () => {
6871
expect(
6972
next(Map({
7073
vote: Map({
74+
round: 1,
7175
pair: List.of('Trainspotting', '28 Days Later'),
7276
tally: Map({
7377
'Trainspotting': 3,
@@ -79,6 +83,7 @@ describe('application logic', () => {
7983
).to.equal(
8084
Map({
8185
vote: Map({
86+
round: 2,
8287
pair: List.of('Sunshine', 'Millions')
8388
}),
8489
entries: List.of('127 Hours', 'Trainspotting', '28 Days Later')
@@ -90,6 +95,7 @@ describe('application logic', () => {
9095
expect(
9196
next(Map({
9297
vote: Map({
98+
round: 1,
9399
pair: List.of('Trainspotting', '28 Days Later'),
94100
tally: Map({
95101
'Trainspotting': 4,
@@ -112,10 +118,12 @@ describe('application logic', () => {
112118
it('creates a tally for the voted entry', () => {
113119
expect(
114120
vote(Map({
121+
round: 1,
115122
pair: List.of('Trainspotting', '28 Days Later')
116123
}), 'Trainspotting')
117124
).to.equal(
118125
Map({
126+
round: 1,
119127
pair: List.of('Trainspotting', '28 Days Later'),
120128
tally: Map({
121129
'Trainspotting': 1
@@ -127,6 +135,7 @@ describe('application logic', () => {
127135
it('adds to existing tally for the voted entry', () => {
128136
expect(
129137
vote(Map({
138+
round: 1,
130139
pair: List.of('Trainspotting', '28 Days Later'),
131140
tally: Map({
132141
'Trainspotting': 3,
@@ -135,6 +144,7 @@ describe('application logic', () => {
135144
}), 'Trainspotting')
136145
).to.equal(
137146
Map({
147+
round: 1,
138148
pair: List.of('Trainspotting', '28 Days Later'),
139149
tally: Map({
140150
'Trainspotting': 4,
@@ -147,10 +157,12 @@ describe('application logic', () => {
147157
it('ignores the vote if for an invalid entry', () => {
148158
expect(
149159
vote(Map({
160+
round: 1,
150161
pair: List.of('Trainspotting', '28 Days Later')
151162
}), 'Sunshine')
152163
).to.equal(
153164
Map({
165+
round: 1,
154166
pair: List.of('Trainspotting', '28 Days Later')
155167
})
156168
);

test/reducer_spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('reducer', () => {
2424

2525
expect(nextState).to.equal(fromJS({
2626
vote: {
27+
round: 1,
2728
pair: ['Trainspotting', '28 Days Later']
2829
},
2930
entries: []
@@ -33,6 +34,7 @@ describe('reducer', () => {
3334
it('handles VOTE', () => {
3435
const initialState = fromJS({
3536
vote: {
37+
round: 1,
3638
pair: ['Trainspotting', '28 Days Later']
3739
},
3840
entries: []
@@ -42,6 +44,7 @@ describe('reducer', () => {
4244

4345
expect(nextState).to.equal(fromJS({
4446
vote: {
47+
round: 1,
4548
pair: ['Trainspotting', '28 Days Later'],
4649
tally: {Trainspotting: 1}
4750
},

0 commit comments

Comments
 (0)