2016-01-19 05:46:52 +01:00
|
|
|
import Ember from 'ember';
|
2015-06-11 10:53:22 +02:00
|
|
|
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-11-24 01:37:37 +01:00
|
|
|
import moment from 'moment';
|
2015-08-01 11:03:00 +02:00
|
|
|
/* jshint proto: true */
|
2015-06-11 10:53:22 +02:00
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
let application, server;
|
2015-08-01 11:03:00 +02:00
|
|
|
|
2016-03-21 13:05:23 +01:00
|
|
|
const randomString = function(length) {
|
|
|
|
return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1);
|
|
|
|
};
|
|
|
|
|
2015-08-01 11:03:00 +02:00
|
|
|
module('Acceptance | create a poll', {
|
2016-01-19 05:46:52 +01:00
|
|
|
beforeEach() {
|
|
|
|
let lastCreatedPoll = {};
|
2016-03-21 13:05:23 +01:00
|
|
|
const pollId = randomString(10);
|
2015-11-24 01:37:37 +01:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
server.post('/polls',
|
2016-01-19 05:46:52 +01:00
|
|
|
function(request) {
|
2016-01-31 15:30:31 +01:00
|
|
|
let ret = serverPostPolls(request.requestBody, pollId);
|
2015-08-01 11:03:00 +02:00
|
|
|
lastCreatedPoll = ret[2];
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-01-31 15:30:31 +01:00
|
|
|
server.get(`/polls/${pollId}`,
|
2016-01-19 05:46:52 +01:00
|
|
|
function() {
|
2015-08-01 11:03:00 +02:00
|
|
|
return [
|
|
|
|
200,
|
2016-01-19 05:46:52 +01:00
|
|
|
{ 'Content-Type': 'application/json' },
|
2015-08-01 11:03:00 +02:00
|
|
|
lastCreatedPoll
|
|
|
|
];
|
|
|
|
}
|
|
|
|
);
|
2015-11-24 01:37:37 +01:00
|
|
|
|
|
|
|
moment.locale(
|
|
|
|
application.__container__.lookup('service:i18n').get('locale')
|
|
|
|
);
|
2015-06-11 10:53:22 +02:00
|
|
|
},
|
2016-01-19 05:46:52 +01:00
|
|
|
afterEach() {
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
test('create a default poll', function(assert) {
|
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
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2015-06-11 10:53:22 +02:00
|
|
|
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
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2015-06-11 10:53:22 +02:00
|
|
|
assert.equal(currentPath(), 'create.options');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
let dates =
|
2015-11-20 23:33:20 +01:00
|
|
|
[
|
|
|
|
moment().add(1, 'day'),
|
|
|
|
moment().add(1, 'week')
|
|
|
|
];
|
|
|
|
|
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
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2016-02-16 02:26:27 +01:00
|
|
|
assert.equal(currentPath(), 'create.options-datetime');
|
2015-11-19 21:51:49 +01:00
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2016-02-16 02:26:27 +01:00
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentPath(), 'create.settings');
|
|
|
|
|
|
|
|
click('button[type="submit"]');
|
|
|
|
|
|
|
|
andThen(function() {
|
|
|
|
assert.equal(currentPath(), 'poll.participation');
|
|
|
|
pollHasValidURL(assert);
|
|
|
|
|
|
|
|
pollTitleEqual(assert, 'default poll');
|
|
|
|
pollDescriptionEqual(assert, '');
|
|
|
|
pollHasOptions(
|
|
|
|
assert,
|
|
|
|
dates.map((date) => {
|
|
|
|
return date.format(
|
|
|
|
moment.localeData().longDateFormat('LLLL')
|
|
|
|
.replace(
|
|
|
|
moment.localeData().longDateFormat('LT'), '')
|
|
|
|
.trim()
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
pollHasAnswers(assert, [
|
|
|
|
t('answerTypes.yes.label'),
|
|
|
|
t('answerTypes.no.label')
|
|
|
|
]);
|
|
|
|
pollHasUsersCount(assert, 0);
|
|
|
|
});
|
2015-06-11 10:53:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
test('create a poll for answering a question', function(assert) {
|
2015-06-11 10:53:22 +02:00
|
|
|
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
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2015-06-11 10:53:22 +02:00
|
|
|
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
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2015-06-11 10:53:22 +02:00
|
|
|
assert.equal(currentPath(), 'create.options');
|
2016-01-19 04:56:51 +01:00
|
|
|
expectComponent('create-options-text');
|
|
|
|
|
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]);
|
2016-01-19 05:46:52 +01: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"]');
|
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2015-11-16 13:09:13 +01:00
|
|
|
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
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2015-11-16 13:09:13 +01:00
|
|
|
assert.equal(currentPath(), 'poll.participation');
|
2016-01-31 15:30:31 +01:00
|
|
|
pollHasValidURL(assert);
|
2015-11-16 13:09:13 +01:00
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
test('create a poll with description', function(assert) {
|
|
|
|
let dates =
|
2015-11-12 15:52:14 +01:00
|
|
|
[
|
|
|
|
moment().add(1, 'day'),
|
|
|
|
moment().add(1, 'week')
|
|
|
|
];
|
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
let formattedDates =
|
2015-11-12 15:52:14 +01:00
|
|
|
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
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2015-06-11 10:53:22 +02:00
|
|
|
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
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2015-06-11 10:53:22 +02:00
|
|
|
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
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2016-02-16 02:26:27 +01:00
|
|
|
assert.equal(currentPath(), 'create.options-datetime');
|
2015-11-19 21:51:49 +01:00
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
andThen(function() {
|
2016-02-16 02:26:27 +01:00
|
|
|
assert.equal(currentPath(), 'create.settings');
|
|
|
|
|
|
|
|
click('button[type="submit"]');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2016-02-16 02:26:27 +01:00
|
|
|
andThen(function() {
|
|
|
|
assert.equal(currentPath(), 'poll.participation');
|
|
|
|
pollHasValidURL(assert);
|
|
|
|
|
|
|
|
pollTitleEqual(assert, 'default poll');
|
|
|
|
pollDescriptionEqual(assert, 'a sample description');
|
|
|
|
pollHasOptions(assert, formattedDates);
|
|
|
|
pollHasUsersCount(assert, 0);
|
|
|
|
});
|
2015-06-11 10:53:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-07-01 16:21:18 +02:00
|
|
|
});
|