Migrate Discourse Polls to use vdom instead of embedded ember

This commit is contained in:
Robin Ward
2016-12-07 15:48:47 -05:00
parent 846597f563
commit f07443b488
23 changed files with 702 additions and 620 deletions

View File

@ -0,0 +1,63 @@
import { moduleForWidget, widgetTest } from 'helpers/widget-test';
moduleForWidget('discourse-poll-standard-results');
const template = `{{mount-widget
widget="discourse-poll-standard-results"
args=(hash poll=poll isMultiple=isMultiple)}}`;
widgetTest('options in descending order', {
template,
setup() {
this.set('poll', Ember.Object.create({
options: [{ votes: 5 }, { votes: 4 }],
voters: 9
}));
},
test(assert) {
assert.equal(this.$('.option .percentage:eq(0)').text(), '56%');
assert.equal(this.$('.option .percentage:eq(1)').text(), '44%');
}
});
widgetTest('options in ascending order', {
template,
setup() {
this.set('poll', Ember.Object.create({
options: [{ votes: 4 }, { votes: 5 }],
voters: 9
}));
},
test(assert) {
assert.equal(this.$('.option .percentage:eq(0)').text(), '56%');
assert.equal(this.$('.option .percentage:eq(1)').text(), '44%');
}
});
widgetTest('multiple options in descending order', {
template,
setup() {
this.set('isMultiple', true);
this.set('poll', Ember.Object.create({
type: 'multiple',
options: [
{ votes: 5 },
{ votes: 2 },
{ votes: 4 },
{ votes: 1 }
],
voters: 12
}));
},
test(assert) {
assert.equal(this.$('.option .percentage:eq(0)').text(), '41%');
assert.equal(this.$('.option .percentage:eq(1)').text(), '33%');
assert.equal(this.$('.option .percentage:eq(2)').text(), '16%');
assert.equal(this.$('.option .percentage:eq(3)').text(), '8%');
}
});