2015-08-01 23:54:07 +02:00
|
|
|
import Ember from 'ember';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import startApp from 'croodle/tests/helpers/start-app';
|
|
|
|
import Pretender from 'pretender';
|
2015-10-14 20:36:47 +02:00
|
|
|
import serverGetPolls from '../helpers/server-get-polls';
|
2016-04-08 21:48:22 +02:00
|
|
|
import pageParticipation from 'croodle/tests/pages/poll/participation';
|
2015-08-01 23:54:07 +02:00
|
|
|
/* jshint proto: true */
|
2016-08-04 22:24:53 +02:00
|
|
|
/* global jstz, moment */
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2016-08-02 01:55:48 +02:00
|
|
|
const { run } = Ember;
|
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
let application, server;
|
2015-08-01 23:54:07 +02:00
|
|
|
|
|
|
|
module('Acceptance | view poll', {
|
2016-01-20 03:52:06 +01:00
|
|
|
beforeEach() {
|
2015-08-01 23:54:07 +02:00
|
|
|
application = startApp();
|
|
|
|
application.__container__.lookup('adapter:application').__proto__.namespace = '';
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-08-01 23:54:07 +02:00
|
|
|
server = new Pretender();
|
|
|
|
},
|
2016-01-20 03:52:06 +01:00
|
|
|
afterEach() {
|
2015-08-01 23:54:07 +02:00
|
|
|
server.shutdown();
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2016-08-02 01:55:48 +02:00
|
|
|
run(application, 'destroy');
|
2015-08-01 23:54:07 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-11-02 23:02:59 +01:00
|
|
|
test('view poll url', function(assert) {
|
2016-01-20 03:52:06 +01:00
|
|
|
let id = 'test';
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz012345789';
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
server.get(`/polls/${id}`, function() {
|
|
|
|
return serverGetPolls({ id }, encryptionKey);
|
2015-11-02 23:02:59 +01:00
|
|
|
});
|
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
visit(`/poll/${id}?encryptionKey=${encryptionKey}`);
|
2015-11-02 23:02:59 +01:00
|
|
|
andThen(function() {
|
|
|
|
assert.equal(
|
2016-07-27 23:12:35 +02:00
|
|
|
find('.poll-link .link a').text(),
|
2015-11-02 23:02:59 +01:00
|
|
|
window.location.href,
|
|
|
|
'share link is shown'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-08-01 23:54:07 +02:00
|
|
|
test('view a poll with dates', function(assert) {
|
2016-01-20 03:52:06 +01:00
|
|
|
let id = 'test';
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
server.get(`/polls/${id}`, function() {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverGetPolls(
|
2015-08-01 23:54:07 +02:00
|
|
|
{
|
2016-01-20 03:19:10 +01:00
|
|
|
id,
|
2015-08-01 23:54:07 +02:00
|
|
|
options: [
|
2016-01-20 03:52:06 +01:00
|
|
|
{ title: '2015-12-12' },
|
|
|
|
{ title: '2016-01-01' }
|
2015-08-01 23:54:07 +02:00
|
|
|
]
|
|
|
|
}, encryptionKey
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
visit(`/poll/${id}?encryptionKey=${encryptionKey}`).then(function() {
|
2016-04-08 21:48:22 +02:00
|
|
|
const dayFormat = moment.localeData().longDateFormat('LLLL')
|
|
|
|
.replace(
|
|
|
|
moment.localeData().longDateFormat('LT'), '')
|
|
|
|
.trim();
|
|
|
|
assert.deepEqual(
|
|
|
|
pageParticipation.options().labels,
|
|
|
|
[
|
|
|
|
moment('2015-12-12').format(dayFormat),
|
|
|
|
moment('2016-01-01').format(dayFormat)
|
|
|
|
]
|
|
|
|
);
|
2015-08-01 23:54:07 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('view a poll with dates and times', function(assert) {
|
2016-01-28 11:27:00 +01:00
|
|
|
const id = 'test';
|
|
|
|
const encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
const timezone = jstz.determine().name();
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
server.get(`/polls/${id}`, function() {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverGetPolls(
|
2015-08-01 23:54:07 +02:00
|
|
|
{
|
2016-01-20 03:19:10 +01:00
|
|
|
id,
|
2015-08-01 23:54:07 +02:00
|
|
|
isDateTime: true,
|
|
|
|
options: [
|
2016-01-20 03:52:06 +01:00
|
|
|
{ title: '2015-12-12T11:11:00.000Z' },
|
|
|
|
{ title: '2015-12-12T13:13:00.000Z' },
|
|
|
|
{ title: '2016-01-01T11:11:00.000Z' }
|
2015-08-01 23:54:07 +02:00
|
|
|
],
|
2016-01-28 12:34:56 +01:00
|
|
|
timezone
|
2015-08-01 23:54:07 +02:00
|
|
|
}, encryptionKey
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
visit(`/poll/${id}?encryptionKey=${encryptionKey}`).then(function() {
|
2016-04-08 21:48:22 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
pageParticipation.options().labels,
|
|
|
|
[
|
|
|
|
// full date
|
|
|
|
moment.tz('2015-12-12T11:11:00.000Z', timezone).format('LLLL'),
|
|
|
|
// only time cause day is repeated
|
|
|
|
moment.tz('2015-12-12T13:13:00.000Z', timezone).format('LT'),
|
|
|
|
// full date cause day changed
|
|
|
|
moment.tz('2016-01-01T11:11:00.000Z', timezone).format('LLLL')
|
|
|
|
]
|
|
|
|
);
|
2015-08-01 23:54:07 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('view a poll while timezone differs from the one poll got created in and choose local timezone', function(assert) {
|
2016-01-28 12:34:56 +01:00
|
|
|
const id = 'test';
|
|
|
|
const encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
const timezoneLocal = jstz.determine().name();
|
|
|
|
let timezonePoll;
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2016-01-28 12:34:56 +01:00
|
|
|
if (timezoneLocal !== 'America/Caracas') {
|
2015-08-01 23:54:07 +02:00
|
|
|
timezonePoll = 'America/Caracas';
|
2016-01-28 12:34:56 +01:00
|
|
|
} else {
|
2015-08-01 23:54:07 +02:00
|
|
|
timezonePoll = 'Europe/Moscow';
|
|
|
|
}
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
server.get(`/polls/${id}`, function() {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverGetPolls(
|
2015-08-01 23:54:07 +02:00
|
|
|
{
|
2016-01-20 03:19:10 +01:00
|
|
|
id,
|
2015-08-01 23:54:07 +02:00
|
|
|
isDateTime: true,
|
|
|
|
options: [
|
2016-01-20 03:52:06 +01:00
|
|
|
{ title: '2015-12-12T11:11:00.000Z' },
|
|
|
|
{ title: '2016-01-01T11:11:00.000Z' }
|
2015-08-01 23:54:07 +02:00
|
|
|
],
|
|
|
|
timezone: timezonePoll
|
|
|
|
}, encryptionKey
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
visit(`/poll/${id}?encryptionKey=${encryptionKey}`).then(function() {
|
2016-08-02 01:55:48 +02:00
|
|
|
run.next(function() {
|
2016-08-04 22:24:53 +02:00
|
|
|
assert.ok(
|
2016-08-12 13:00:18 +02:00
|
|
|
find('#modal-choose-timezone-modal').is(':visible'),
|
2015-08-01 23:54:07 +02:00
|
|
|
'user gets asked which timezone should be used'
|
|
|
|
);
|
|
|
|
|
2016-08-12 13:00:18 +02:00
|
|
|
click('#modal-choose-timezone-modal button.use-local-timezone');
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2015-11-02 23:02:59 +01:00
|
|
|
andThen(function() {
|
2016-04-08 21:48:22 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
pageParticipation.options().labels,
|
|
|
|
[
|
|
|
|
moment.tz('2015-12-12T11:11:00.000Z', timezoneLocal).format('LLLL'),
|
|
|
|
moment.tz('2016-01-01T11:11:00.000Z', timezoneLocal).format('LLLL')
|
|
|
|
]
|
|
|
|
);
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2016-08-02 01:55:48 +02:00
|
|
|
run.next(function() {
|
2016-08-04 22:24:53 +02:00
|
|
|
assert.notOk(
|
2016-08-12 13:00:18 +02:00
|
|
|
find('#modal-choose-timezone-modal').is(':visible'),
|
2015-08-01 23:54:07 +02:00
|
|
|
'modal is closed'
|
|
|
|
);
|
2016-08-04 22:24:53 +02:00
|
|
|
});
|
2015-08-01 23:54:07 +02:00
|
|
|
});
|
2016-08-04 22:24:53 +02:00
|
|
|
});
|
2015-08-01 23:54:07 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('view a poll while timezone differs from the one poll got created in and choose poll timezone', function(assert) {
|
2016-01-28 12:34:56 +01:00
|
|
|
const id = 'test';
|
|
|
|
const encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
const timezoneLocal = jstz.determine().name();
|
|
|
|
let timezonePoll;
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2016-01-28 12:34:56 +01:00
|
|
|
if (timezoneLocal !== 'America/Caracas') {
|
2015-08-01 23:54:07 +02:00
|
|
|
timezonePoll = 'America/Caracas';
|
2016-01-28 12:34:56 +01:00
|
|
|
} else {
|
2015-08-01 23:54:07 +02:00
|
|
|
timezonePoll = 'Europe/Moscow';
|
|
|
|
}
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
server.get(`/polls/${id}`, function() {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverGetPolls(
|
2015-08-01 23:54:07 +02:00
|
|
|
{
|
2016-01-20 03:19:10 +01:00
|
|
|
id,
|
2015-08-01 23:54:07 +02:00
|
|
|
isDateTime: true,
|
|
|
|
options: [
|
2016-01-20 03:52:06 +01:00
|
|
|
{ title: '2015-12-12T11:11:00.000Z' },
|
|
|
|
{ title: '2016-01-01T11:11:00.000Z' }
|
2015-08-01 23:54:07 +02:00
|
|
|
],
|
|
|
|
timezone: timezonePoll
|
|
|
|
}, encryptionKey
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-01-20 03:19:10 +01:00
|
|
|
visit(`/poll/${id}?encryptionKey=${encryptionKey}`).then(function() {
|
2016-08-02 01:55:48 +02:00
|
|
|
|
|
|
|
run.next(function() {
|
2016-08-04 22:24:53 +02:00
|
|
|
assert.ok(
|
2016-08-12 13:00:18 +02:00
|
|
|
find('#modal-choose-timezone-modal').is(':visible'),
|
2015-08-01 23:54:07 +02:00
|
|
|
'user gets asked which timezone should be used'
|
|
|
|
);
|
|
|
|
|
2016-08-12 13:00:18 +02:00
|
|
|
click('#modal-choose-timezone-modal button.use-poll-timezone');
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2015-10-16 11:21:06 +02:00
|
|
|
andThen(function() {
|
2016-04-08 21:48:22 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
pageParticipation.options().labels,
|
|
|
|
[
|
|
|
|
moment.tz('2015-12-12T11:11:00.000Z', timezonePoll).format('LLLL'),
|
|
|
|
moment.tz('2016-01-01T11:11:00.000Z', timezonePoll).format('LLLL')
|
|
|
|
]
|
|
|
|
);
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2016-08-02 01:55:48 +02:00
|
|
|
run.next(function() {
|
2016-08-04 22:24:53 +02:00
|
|
|
assert.notOk(
|
2016-08-12 13:00:18 +02:00
|
|
|
find('#modal-choose-timezone-modal').is(':visible'),
|
2015-08-01 23:54:07 +02:00
|
|
|
'modal is closed'
|
|
|
|
);
|
2016-08-04 22:24:53 +02:00
|
|
|
});
|
2015-08-01 23:54:07 +02:00
|
|
|
});
|
2016-08-04 22:24:53 +02:00
|
|
|
});
|
2015-08-01 23:54:07 +02:00
|
|
|
});
|
|
|
|
});
|