FIX: Incorrect sort for poll results.

This commit is contained in:
Guo Xiang Tan 2016-07-29 14:42:55 +08:00
parent f9ef1e1997
commit e336e56153
2 changed files with 9 additions and 2 deletions

View File

@ -8,7 +8,7 @@ export default Em.Component.extend({
@computed("poll.voters", "poll.type", "poll.options.[]") @computed("poll.voters", "poll.type", "poll.options.[]")
options(voters, type) { options(voters, type) {
const options = this.get("poll.options").slice(0).sort((a, b) => { const options = this.get("poll.options").slice(0).sort((a, b) => {
return a.get("votes") < b.get("votes") ? 1 : 0; return b.get("votes") - a.get("votes");
}); });
let percentages = voters === 0 ? let percentages = voters === 0 ?

View File

@ -39,7 +39,12 @@ componentTest('multiple options in descending order', {
setup(store) { setup(store) {
this.set('poll', { this.set('poll', {
type: 'multiple', type: 'multiple',
options: [Em.Object.create({ votes: 5 }), Em.Object.create({ votes: 4 })], options: [
Em.Object.create({ votes: 5}),
Em.Object.create({ votes: 2}),
Em.Object.create({ votes: 4}),
Em.Object.create({ votes: 1})
],
voters: 9 voters: 9
}); });
}, },
@ -47,5 +52,7 @@ componentTest('multiple options in descending order', {
test(assert) { test(assert) {
assert.equal(this.$('.option .percentage:eq(0)').text(), '55%'); assert.equal(this.$('.option .percentage:eq(0)').text(), '55%');
assert.equal(this.$('.option .percentage:eq(1)').text(), '44%'); assert.equal(this.$('.option .percentage:eq(1)').text(), '44%');
assert.equal(this.$('.option .percentage:eq(2)').text(), '22%');
assert.equal(this.$('.option .percentage:eq(3)').text(), '11%');
} }
}); });