2015-06-11 10:53:22 +02:00
|
|
|
import Ember from "ember";
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import startApp from '../helpers/start-app';
|
2015-08-01 11:03:00 +02:00
|
|
|
import Pretender from 'pretender';
|
2015-10-14 20:36:47 +02:00
|
|
|
import serverPostPolls from '../helpers/server-post-polls';
|
2015-06-11 10:53:22 +02:00
|
|
|
/* global moment */
|
2015-08-01 11:03:00 +02:00
|
|
|
/* jshint proto: true */
|
2015-06-11 10:53:22 +02:00
|
|
|
|
2015-08-01 11:03:00 +02:00
|
|
|
var application, server;
|
|
|
|
|
|
|
|
module('Acceptance | create a poll', {
|
2015-06-11 10:53:22 +02:00
|
|
|
beforeEach: function() {
|
2015-08-01 11:03:00 +02:00
|
|
|
application = startApp();
|
|
|
|
application.__container__.lookup('adapter:application').__proto__.namespace = '';
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-08-01 11:03:00 +02:00
|
|
|
server = new Pretender();
|
|
|
|
|
|
|
|
var lastCreatedPoll = {};
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-08-01 11:03:00 +02:00
|
|
|
server.post('/polls',
|
|
|
|
function (request) {
|
2015-10-14 20:36:47 +02:00
|
|
|
var ret = serverPostPolls(request.requestBody, 'test');
|
2015-08-01 11:03:00 +02:00
|
|
|
lastCreatedPoll = ret[2];
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
server.get('/polls/test',
|
|
|
|
function () {
|
|
|
|
return [
|
|
|
|
200,
|
|
|
|
{"Content-Type": "application/json"},
|
|
|
|
lastCreatedPoll
|
|
|
|
];
|
|
|
|
}
|
|
|
|
);
|
2015-06-11 10:53:22 +02:00
|
|
|
},
|
|
|
|
afterEach: function() {
|
2015-08-01 11:03:00 +02:00
|
|
|
server.shutdown();
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-08-01 11:03:00 +02:00
|
|
|
Ember.run(application, 'destroy');
|
2015-06-11 10:53:22 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-11-02 23:02:59 +01:00
|
|
|
test("create a default poll", function(assert) {
|
2015-11-12 15:52:14 +01:00
|
|
|
var dates =
|
|
|
|
[
|
|
|
|
moment().add(1, 'day'),
|
|
|
|
moment().add(1, 'week')
|
|
|
|
];
|
|
|
|
|
|
|
|
var formattedDates =
|
|
|
|
dates.map((date) => {
|
|
|
|
return date.format(
|
|
|
|
moment.localeData().longDateFormat('LLLL')
|
|
|
|
.replace(
|
|
|
|
moment.localeData().longDateFormat('LT'), '')
|
|
|
|
.trim()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
visit('/create').then(function() {
|
2015-11-16 14:28:00 +01:00
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
|
|
|
assert.equal(currentPath(), 'create.meta');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-11-16 14:28:00 +01:00
|
|
|
fillIn('.title input', 'default poll');
|
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
|
|
|
assert.equal(currentPath(), 'create.options');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-11-12 15:52:14 +01:00
|
|
|
selectDates(
|
|
|
|
'#datepicker .ember-view',
|
|
|
|
dates
|
|
|
|
);
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-11-19 21:51:49 +01:00
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
|
|
|
assert.equal(currentPath(), 'create.settings');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-11-19 21:51:49 +01:00
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(currentPath(), 'poll.participation');
|
|
|
|
|
2015-10-14 20:36:47 +02:00
|
|
|
pollTitleEqual(assert, 'default poll');
|
|
|
|
pollDescriptionEqual(assert, '');
|
2015-11-12 15:52:14 +01:00
|
|
|
pollHasOptions(assert, formattedDates);
|
2015-10-16 11:21:06 +02:00
|
|
|
pollHasAnswers(assert, [
|
2015-11-20 02:18:19 +01:00
|
|
|
t('answerTypes.yes.label'),
|
|
|
|
t('answerTypes.no.label')
|
2015-10-16 11:21:06 +02:00
|
|
|
]);
|
|
|
|
pollHasUsersCount(assert, 0);
|
2015-06-11 10:53:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("create a poll for answering a question", function(assert) {
|
|
|
|
visit('/create').then(function() {
|
|
|
|
// select poll type answer a question
|
2015-11-16 14:28:00 +01:00
|
|
|
fillIn('.poll-type select', 'MakeAPoll');
|
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
|
|
|
assert.equal(currentPath(), 'create.meta');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-11-16 14:28:00 +01:00
|
|
|
fillIn('.title input', 'default poll');
|
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
|
|
|
assert.equal(currentPath(), 'create.options');
|
2015-11-16 13:09:13 +01:00
|
|
|
assert.equal(
|
|
|
|
find('input').length,
|
|
|
|
2,
|
|
|
|
'there are two input fields as default'
|
|
|
|
);
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
// fill in default two option input fields
|
|
|
|
fillIn(find('input')[0], 'option a');
|
2015-11-16 13:09:13 +01:00
|
|
|
fillIn(find('input')[1], 'option c');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
// add another option input field
|
2015-11-16 13:09:13 +01:00
|
|
|
click('button.add', find('.form-group')[0]);
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
2015-11-16 13:09:13 +01:00
|
|
|
assert.equal(
|
|
|
|
find('input').length,
|
|
|
|
3,
|
|
|
|
'option was added'
|
|
|
|
);
|
|
|
|
fillIn(find('input')[1], 'option b');
|
|
|
|
|
|
|
|
click('button.add', find('.form-group')[2]);
|
|
|
|
andThen(function() {
|
|
|
|
assert.equal(
|
|
|
|
find('input').length,
|
|
|
|
4,
|
|
|
|
'option was added'
|
|
|
|
);
|
|
|
|
fillIn(find('input')[3], 'to be deleted');
|
|
|
|
click('button.delete', find('.form-group')[3]);
|
|
|
|
|
|
|
|
andThen(function() {
|
|
|
|
assert.equal(
|
|
|
|
find('input').length,
|
|
|
|
3,
|
|
|
|
'option got deleted'
|
|
|
|
);
|
|
|
|
|
|
|
|
click('button[type="submit"]');
|
|
|
|
|
|
|
|
andThen(function(){
|
|
|
|
assert.equal(currentPath(), 'create.settings');
|
|
|
|
|
2015-11-19 21:51:49 +01:00
|
|
|
click('button[type="submit"]');
|
2015-11-16 13:09:13 +01:00
|
|
|
|
|
|
|
andThen(function(){
|
|
|
|
assert.equal(currentPath(), 'poll.participation');
|
|
|
|
|
|
|
|
pollTitleEqual(assert, 'default poll');
|
|
|
|
pollDescriptionEqual(assert, '');
|
|
|
|
pollHasOptions(assert, ['option a', 'option b', 'option c']);
|
|
|
|
pollHasUsersCount(assert, 0);
|
|
|
|
});
|
|
|
|
});
|
2015-06-11 10:53:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("create a poll with description", function(assert) {
|
2015-11-12 15:52:14 +01:00
|
|
|
var dates =
|
|
|
|
[
|
|
|
|
moment().add(1, 'day'),
|
|
|
|
moment().add(1, 'week')
|
|
|
|
];
|
|
|
|
|
|
|
|
var formattedDates =
|
|
|
|
dates.map((date) => {
|
|
|
|
return date.format(
|
|
|
|
moment.localeData().longDateFormat('LLLL')
|
|
|
|
.replace(
|
|
|
|
moment.localeData().longDateFormat('LT'), '')
|
|
|
|
.trim()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
visit('/create').then(function() {
|
2015-11-16 14:28:00 +01:00
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
|
|
|
assert.equal(currentPath(), 'create.meta');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-11-16 14:28:00 +01:00
|
|
|
fillIn('.title input', 'default poll');
|
|
|
|
fillIn('.description textarea', 'a sample description');
|
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
|
|
|
assert.equal(currentPath(), 'create.options');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-11-12 15:52:14 +01:00
|
|
|
selectDates('#datepicker .ember-view', dates);
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-11-19 21:51:49 +01:00
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
|
|
|
assert.equal(currentPath(), 'create.settings');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-11-19 21:51:49 +01:00
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-11 10:53:22 +02:00
|
|
|
andThen(function(){
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(currentPath(), 'poll.participation');
|
|
|
|
|
2015-10-14 20:36:47 +02:00
|
|
|
pollTitleEqual(assert, 'default poll');
|
|
|
|
pollDescriptionEqual(assert, 'a sample description');
|
2015-11-12 15:52:14 +01:00
|
|
|
pollHasOptions(assert, formattedDates);
|
2015-10-16 11:21:06 +02:00
|
|
|
pollHasUsersCount(assert, 0);
|
2015-06-11 10:53:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-07-01 16:21:18 +02:00
|
|
|
});
|