Created
April 6, 2016 19:54
-
-
Save t3h2mas/9f82a92aa87fed7c4907fc1461da7bc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {List, Map} from 'immutable'; | |
import {expect} from 'chai'; | |
import {setEntries, next, vote} from '../src/core'; | |
describe('Application logic', () => { | |
describe('setEntries', () => { | |
it('adds the entries to the state', () => { | |
const state = Map(); | |
const entries = List.of('Trainspotting', '28 Days Later'); | |
const nextState = setEntries(state, entries); | |
expect(nextState).to.equal(Map({ | |
entries: List.of('Trainspotting', '28 Days Later') | |
})); | |
}); | |
it('converts to immutable', () => { | |
const state = Map(); | |
const entries = ['Trainspotting', '28 Days Later']; | |
const nextState = setEntries(state, entries); | |
expect(nextState).to.equal(Map({ | |
entries: List.of('Trainspotting', '28 Days Later') | |
})); | |
}); | |
}); | |
describe('next', () => { | |
it('takes the next two entries under vote', () => { | |
const state = Map({ | |
entries: List.of('Trainspotting', '28 Days Later', 'Sunshine') | |
}); | |
const nextState = next(state); | |
expect(nextState).to.equal(Map({ | |
vote: Map({ | |
pair: List.of('Trainspotting', '28 Days Later') | |
}), | |
entries: List.of('Sunshine') | |
})); | |
}); | |
it('puts winner of current vote back to entries', () => { | |
const state = Map({ | |
vote: Map({ | |
pair: List.of('Trainspotting', '28 Days Later'), | |
tally: Map({ | |
'Trainspotting': 4, | |
'28 Days Later': 2 | |
}) | |
}), | |
entries: List.of('Sunshine', 'Millions', '127 Hours') | |
}); | |
const nextState = next(state); | |
expect(nextState).to.equal(Map({ | |
vote: Map({ | |
pair: List.of('Sunshine', 'Millions') | |
}), | |
entries: List.of('127 Hours', 'Trainspotting') | |
})); | |
}); | |
it('puts both from tied vote back to entries', () => { | |
const state = Map({ | |
vote: Map({ | |
pair: List.of('Trainspotting', '28 Days Later'), | |
tally: Map({ | |
'Trainspotting': 3, | |
'28 Days Later': 3 | |
}) | |
}), | |
entries: List.of('127 Hours', 'Trainspotting', '28 Days Later') | |
}); | |
}); | |
it('marks the winner when just one entry left', () => { | |
const state = Map({ | |
vote: Map({ | |
pair: List.of('Trainspotting', '28 Days Later'), | |
tally: Map({ | |
'Trainspotting': 4, | |
'28 Days Later': 2 | |
}) | |
}), | |
entries: List() | |
}); | |
const nextState = next(state); | |
expect(nextState).to.equal(Map({ | |
winner: 'Trainspotting' | |
})); | |
}); | |
}); | |
describe('vote', () => { | |
it('creates a tally for the voted entry', () => { | |
const state = Map({ | |
pair: List.of('Trainspotting', '28 Days Later') | |
}); | |
const nextState = vote(state, 'Trainspotting'); | |
expect(nextState).to.equal(Map({ | |
pair: List.of('Trainspotting', '28 Days Later'), | |
tally: Map({ | |
'Trainspotting': 1 | |
}) | |
})); | |
}); | |
it('adds to existing tally of the voted entry', () => { | |
const state = Map({ | |
pair: List.of('Trainspotting', '28 Days Later'), | |
tally: Map({ | |
'Trainspotting': 3, | |
'28 Days Later': 2 | |
}) | |
}); | |
const nextState = vote(state, 'Trainspotting'); | |
expect(nextState).to.equal(Map({ | |
pair: List.of('Trainspotting', '28 Days Later'), | |
tally: Map({ | |
'Trainspotting': 4, | |
'28 Days Later': 2 | |
}) | |
})); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment