decide.nolog.cz/tests/acceptance/create-a-poll-test.js

231 lines
5.8 KiB
JavaScript
Raw Normal View History

2015-06-11 10:53:22 +02:00
import Ember from "ember";
import { module, test } from 'qunit';
import startApp from '../helpers/start-app';
import Pretender from 'pretender';
import serverPostPolls from '../helpers/server-post-polls';
2015-06-11 10:53:22 +02:00
/* global moment */
/* jshint proto: true */
2015-06-11 10:53:22 +02:00
var application, server;
module('Acceptance | create a poll', {
2015-06-11 10:53:22 +02:00
beforeEach: function() {
application = startApp();
application.__container__.lookup('adapter:application').__proto__.namespace = '';
server = new Pretender();
var lastCreatedPoll = {};
server.post('/polls',
function (request) {
var ret = serverPostPolls(request.requestBody, 'test');
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() {
server.shutdown();
Ember.run(application, 'destroy');
2015-06-11 10:53:22 +02:00
}
});
test("create a default poll", function(assert) {
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() {
click('button[type="submit"]');
2015-06-11 10:53:22 +02:00
andThen(function(){
assert.equal(currentPath(), 'create.meta');
fillIn('.title input', 'default poll');
click('button[type="submit"]');
2015-06-11 10:53:22 +02:00
andThen(function(){
assert.equal(currentPath(), 'create.options');
selectDates(
'#datepicker .ember-view',
dates
);
click('button[type="submit"]');
2015-06-11 10:53:22 +02:00
andThen(function(){
assert.equal(currentPath(), 'create.settings');
click('button[type="submit"]');
2015-06-11 10:53:22 +02:00
andThen(function(){
assert.equal(currentPath(), 'poll.participation');
pollTitleEqual(assert, 'default poll');
pollDescriptionEqual(assert, '');
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
fillIn('.poll-type select', 'MakeAPoll');
click('button[type="submit"]');
2015-06-11 10:53:22 +02:00
andThen(function(){
assert.equal(currentPath(), 'create.meta');
fillIn('.title input', 'default poll');
click('button[type="submit"]');
2015-06-11 10:53:22 +02:00
andThen(function(){
assert.equal(currentPath(), 'create.options');
assert.equal(
find('input').length,
2,
'there are two input fields as default'
);
2015-06-11 10:53:22 +02:00
// fill in default two option input fields
fillIn(find('input')[0], 'option a');
fillIn(find('input')[1], 'option c');
2015-06-11 10:53:22 +02:00
// add another option input field
click('button.add', find('.form-group')[0]);
2015-06-11 10:53:22 +02:00
andThen(function(){
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');
click('button[type="submit"]');
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) {
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() {
click('button[type="submit"]');
2015-06-11 10:53:22 +02:00
andThen(function(){
assert.equal(currentPath(), 'create.meta');
fillIn('.title input', 'default poll');
fillIn('.description textarea', 'a sample description');
click('button[type="submit"]');
2015-06-11 10:53:22 +02:00
andThen(function(){
assert.equal(currentPath(), 'create.options');
selectDates('#datepicker .ember-view', dates);
click('button[type="submit"]');
2015-06-11 10:53:22 +02:00
andThen(function(){
assert.equal(currentPath(), 'create.settings');
click('button[type="submit"]');
2015-06-11 10:53:22 +02:00
andThen(function(){
assert.equal(currentPath(), 'poll.participation');
pollTitleEqual(assert, 'default poll');
pollDescriptionEqual(assert, 'a sample description');
pollHasOptions(assert, formattedDates);
2015-10-16 11:21:06 +02:00
pollHasUsersCount(assert, 0);
2015-06-11 10:53:22 +02:00
});
});
});
});
});
});