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

153 lines
4.2 KiB
JavaScript
Raw Normal View History

import Ember from 'ember';
2015-08-19 11:29:30 +02:00
import { module, test } from 'qunit';
import startApp from '../helpers/start-app';
import moment from 'moment';
import pageCreateIndex from 'croodle/tests/pages/create/index';
import pageCreateMeta from 'croodle/tests/pages/create/meta';
import pageCreateOptions from 'croodle/tests/pages/create/options';
import pageCreateOptionsDatetime from 'croodle/tests/pages/create/options-datetime';
import pageCreateSettings from 'croodle/tests/pages/create/settings';
import pagePollParticipation from 'croodle/tests/pages/poll/participation';
2015-08-19 11:29:30 +02:00
/* jshint proto: true */
let application;
2015-08-19 11:29:30 +02:00
module('Integration', {
beforeEach() {
window.localStorage.setItem('locale', 'en');
2015-08-19 11:29:30 +02:00
application = startApp();
moment.locale(
application.__container__.lookup('service:i18n').get('locale')
);
2015-08-19 11:29:30 +02:00
},
afterEach() {
2015-08-19 11:29:30 +02:00
Ember.run(application, 'destroy');
}
});
test('create a default poll and participate', function(assert) {
const dates =
[
moment().add(1, 'day'),
moment().add(1, 'week'),
moment().add(1, 'month')
];
const formattedDates =
dates.map((date) => {
return date.format(
moment.localeData().longDateFormat('LLLL')
.replace(
moment.localeData().longDateFormat('LT'), '')
.trim()
);
});
pageCreateIndex
.visit();
andThen(function() {
pageCreateIndex
.next();
andThen(function() {
2015-08-19 11:29:30 +02:00
assert.equal(currentPath(), 'create.meta');
pageCreateMeta
.title('default poll')
.next();
andThen(function() {
2015-08-19 11:29:30 +02:00
assert.equal(currentPath(), 'create.options');
2016-05-21 17:17:08 +02:00
assert.notOk(
pageCreateOptions.dateHasError,
'no validation error shown before user interaction'
);
pageCreateOptions
.next();
andThen(function() {
2016-05-21 17:17:08 +02:00
assert.equal(
currentPath(),
'create.options',
'transition is aborted due to validation error (no day selected)'
);
assert.ok(
pageCreateOptions.dateHasError,
'validation error is shown if no day is selected (after user interaction)'
);
pageCreateOptions
.dateOptions(dates);
pageCreateOptions
.next();
andThen(function() {
2016-05-21 17:17:08 +02:00
assert.equal(currentPath(), 'create.options-datetime');
2016-05-21 17:17:08 +02:00
pageCreateOptionsDatetime
.next();
andThen(function() {
2016-05-21 17:17:08 +02:00
assert.equal(currentPath(), 'create.settings');
pageCreateSettings
.next();
andThen(function() {
2016-05-21 17:17:08 +02:00
assert.equal(currentPath(), 'poll.participation');
assert.ok(
pagePollParticipation.urlIsValid() === true,
'poll url is valid'
);
assert.equal(
pagePollParticipation.title,
'default poll',
'title is correct'
);
assert.equal(
pagePollParticipation.description,
'',
'description is correct'
);
assert.deepEqual(
pagePollParticipation.options().labels,
formattedDates,
'option labels are correct'
);
assert.deepEqual(
pagePollParticipation.options().answers,
[
2016-05-21 17:17:08 +02:00
t('answerTypes.yes.label').toString(),
t('answerTypes.no.label').toString()
],
'option labels are correct'
);
2016-05-21 17:17:08 +02:00
pollParticipate('Max Hoelz', ['no', 'no', 'yes']);
andThen(function() {
assert.equal(currentPath(), 'poll.evaluation');
pollHasUsersCount(assert, 1);
pollHasUser(
assert,
'Max Hoelz',
[
t('answerTypes.no.label'),
t('answerTypes.no.label'),
t('answerTypes.yes.label')
]
);
});
});
});
2015-08-19 11:29:30 +02:00
});
});
});
});
});
});