decide.nolog.cz/tests/acceptance/view-poll-test.js

254 lines
7.4 KiB
JavaScript
Raw Normal View History

import Ember from 'ember';
2016-12-19 17:04:09 +01:00
import { test } from 'qunit';
import moduleForAcceptance from 'croodle/tests/helpers/module-for-acceptance';
import pageParticipation from 'croodle/tests/pages/poll/participation';
import pageEvaluation from 'croodle/tests/pages/poll/evaluation';
2016-12-19 17:04:09 +01:00
import moment from 'moment';
/* jshint proto: true */
const { run } = Ember;
2016-12-19 17:04:09 +01:00
moduleForAcceptance('Acceptance | view poll', {
beforeEach() {
window.localStorage.setItem('locale', 'en');
2016-12-19 17:04:09 +01:00
moment.locale('en');
}
});
test('poll url', function(assert) {
2016-01-20 03:52:06 +01:00
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz012345789';
2016-12-19 17:04:09 +01:00
let poll = server.create('poll', { encryptionKey });
let pollUrl = `/poll/${poll.id}?encryptionKey=${encryptionKey}`;
visit(pollUrl);
andThen(function() {
assert.equal(
pageParticipation.url,
window.location.href,
'share link is shown'
);
pageParticipation.copyUrl();
/*
* Can't test if link is actually copied to clipboard due to api
* restrictions. Due to security it's not allowed to read from clipboard.
*
* Can't test if flash message is shown due to
* https://github.com/poteto/ember-cli-flash/issues/202
*/
});
});
test('shows a warning if poll is about to be expired', function(assert) {
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
let poll = server.create('poll', {
encryptionKey,
expirationDate: moment().add(1, 'week')
});
visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`).then(function() {
assert.ok(
pageParticipation.showsExpirationWarning
);
});
});
test('view a poll with dates', function(assert) {
2016-01-20 03:52:06 +01:00
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
2016-12-19 17:04:09 +01:00
let poll = server.create('poll', {
encryptionKey,
options: [
{ title: '2015-12-12' },
{ title: '2016-01-01' }
]
});
2016-12-19 17:04:09 +01:00
visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`).then(function() {
assert.deepEqual(
pageParticipation.options().labels,
[
'Saturday, December 12, 2015',
'Friday, January 1, 2016'
]
);
});
});
test('view a poll with dates and times', function(assert) {
2016-12-19 17:04:09 +01:00
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
let timezone = moment.tz.guess();
2016-12-19 17:04:09 +01:00
let poll = server.create('poll', {
encryptionKey,
expirationDate: moment().add(1, 'year'),
2016-12-19 17:04:09 +01:00
isDateTime: true,
options: [
{ title: '2015-12-12T11:11:00.000Z' },
{ title: '2015-12-12T13:13:00.000Z' },
{ title: '2016-01-01T11:11:00.000Z' }
],
timezone
});
2016-12-19 17:04:09 +01:00
visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`).then(function() {
assert.deepEqual(
pageParticipation.options().labels,
[
// full date
moment.tz('2015-12-12T11:11:00.000Z', timezone).locale('en').format('LLLL'),
// only time cause day is repeated
moment.tz('2015-12-12T13:13:00.000Z', timezone).locale('en').format('LT'),
// full date cause day changed
moment.tz('2016-01-01T11:11:00.000Z', timezone).locale('en').format('LLLL')
]
);
assert.notOk(
pageParticipation.showsExpirationWarning,
'does not show an expiration warning if poll will not expire in next weeks'
);
});
});
test('view a poll while timezone differs from the one poll got created in and choose local timezone', function(assert) {
2016-12-19 17:04:09 +01:00
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
let timezoneUser = moment.tz.guess();
2016-12-19 17:04:09 +01:00
let timezonePoll = timezoneUser !== 'America/Caracas' ? 'America/Caracas' : 'Europe/Moscow';
let poll = server.create('poll', {
encryptionKey,
isDateTime: true,
options: [
{ title: '2015-12-12T11:11:00.000Z' },
{ title: '2016-01-01T11:11:00.000Z' }
],
timezone: timezonePoll,
users: [
server.create('user', {
encryptionKey,
selections: [
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
},
{
type: 'no',
labelTranslation: 'answerTypes.no.label',
icon: 'glyphicon glyphicon-thumbs-down',
label: 'No'
}
]
})
]
});
2016-12-19 17:04:09 +01:00
visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`).then(function() {
run.next(() => {
assert.ok(
find('#modal-choose-timezone-modal').is(':visible'),
'user gets asked which timezone should be used'
);
click('#modal-choose-timezone-modal button.use-local-timezone');
2016-12-19 17:04:09 +01:00
andThen(() => {
assert.deepEqual(
pageParticipation.options().labels,
[
2016-12-19 17:04:09 +01:00
moment.tz('2015-12-12T11:11:00.000Z', timezoneUser).locale('en').format('LLLL'),
moment.tz('2016-01-01T11:11:00.000Z', timezoneUser).locale('en').format('LLLL')
]
);
2016-12-19 17:04:09 +01:00
run.next(() => {
assert.notOk(
find('#modal-choose-timezone-modal').is(':visible'),
'modal is closed'
);
});
andThen(() => {
switchTab('evaluation');
andThen(() => {
assert.deepEqual(
pageEvaluation.preferedOptions,
[moment.tz('2015-12-12T11:11:00.000Z', timezoneUser).locale('en').format('LLLL')]
);
});
});
});
});
});
});
test('view a poll while timezone differs from the one poll got created in and choose poll timezone', function(assert) {
2016-12-19 17:04:09 +01:00
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
let timezoneUser = moment.tz.guess();
2016-12-19 17:04:09 +01:00
let timezonePoll = timezoneUser !== 'America/Caracas' ? 'America/Caracas' : 'Europe/Moscow';
let poll = server.create('poll', {
encryptionKey,
isDateTime: true,
options: [
{ title: '2015-12-12T11:11:00.000Z' },
{ title: '2016-01-01T11:11:00.000Z' }
],
timezone: timezonePoll,
users: [
server.create('user', {
encryptionKey,
selections: [
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
},
{
type: 'no',
labelTranslation: 'answerTypes.no.label',
icon: 'glyphicon glyphicon-thumbs-down',
label: 'No'
}
]
})
]
});
2016-12-19 17:04:09 +01:00
visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`).then(function() {
run.next(function() {
assert.ok(
find('#modal-choose-timezone-modal').is(':visible'),
'user gets asked which timezone should be used'
);
click('#modal-choose-timezone-modal button.use-poll-timezone');
2015-10-16 11:21:06 +02:00
andThen(function() {
assert.deepEqual(
pageParticipation.options().labels,
[
moment.tz('2015-12-12T11:11:00.000Z', timezonePoll).locale('en').format('LLLL'),
moment.tz('2016-01-01T11:11:00.000Z', timezonePoll).locale('en').format('LLLL')
]
);
run.next(function() {
assert.notOk(
find('#modal-choose-timezone-modal').is(':visible'),
'modal is closed'
);
});
andThen(() => {
switchTab('evaluation');
andThen(() => {
assert.deepEqual(
pageEvaluation.preferedOptions,
[moment.tz('2015-12-12T11:11:00.000Z', timezonePoll).locale('en').format('LLLL')]
);
});
});
});
});
});
});