mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 11:11:13 +08:00
Migrate Discourse Polls to use vdom instead of embedded ember
This commit is contained in:
@ -0,0 +1,64 @@
|
||||
import { moduleForWidget, widgetTest } from 'helpers/widget-test';
|
||||
moduleForWidget('discourse-poll-option');
|
||||
|
||||
const template = `{{mount-widget
|
||||
widget="discourse-poll-option"
|
||||
args=(hash option=option isMultiple=isMultiple vote=vote)}}`;
|
||||
|
||||
widgetTest('single, not selected', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
this.set('option', { id: 'opt-id' });
|
||||
this.set('vote', []);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(find('li .fa-circle-o:eq(0)').length === 1);
|
||||
}
|
||||
});
|
||||
|
||||
widgetTest('single, selected', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
this.set('option', { id: 'opt-id' });
|
||||
this.set('vote', ['opt-id']);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(find('li .fa-dot-circle-o:eq(0)').length === 1);
|
||||
}
|
||||
});
|
||||
|
||||
widgetTest('multi, not selected', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
this.setProperties({
|
||||
option: { id: 'opt-id' },
|
||||
isMultiple: true,
|
||||
vote: []
|
||||
});
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(find('li .fa-square-o:eq(0)').length === 1);
|
||||
}
|
||||
});
|
||||
|
||||
widgetTest('multi, selected', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
this.setProperties({
|
||||
option: { id: 'opt-id' },
|
||||
isMultiple: true,
|
||||
vote: ['opt-id']
|
||||
});
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(find('li .fa-check-square-o:eq(0)').length === 1);
|
||||
}
|
||||
});
|
@ -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%');
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user