2019-04-23 17:37:42 +02:00
|
|
|
import { click, currentURL, currentRouteName, visit } from '@ember/test-helpers';
|
2018-12-29 20:35:04 +01:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2019-05-21 13:53:49 +02:00
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2018-12-29 20:35:04 +01:00
|
|
|
import switchTab from 'croodle/tests/helpers/switch-tab';
|
2016-04-08 21:48:22 +02:00
|
|
|
import pageParticipation from 'croodle/tests/pages/poll/participation';
|
2017-08-11 16:39:36 +02:00
|
|
|
import pageEvaluation from 'croodle/tests/pages/poll/evaluation';
|
2023-09-21 12:30:14 +02:00
|
|
|
import { DateTime } from 'luxon';
|
2019-03-16 11:26:39 +01:00
|
|
|
import { triggerCopySuccess } from 'ember-cli-clipboard/test-support';
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
module('Acceptance | view poll', function(hooks) {
|
|
|
|
hooks.beforeEach(function() {
|
2016-08-21 14:31:39 +02:00
|
|
|
window.localStorage.setItem('locale', 'en');
|
2018-12-29 20:35:04 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
setupApplicationTest(hooks);
|
|
|
|
setupMirage(hooks);
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('poll url', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz012345789';
|
|
|
|
let poll = this.server.create('poll', { encryptionKey });
|
|
|
|
let pollUrl = `/poll/${poll.id}?encryptionKey=${encryptionKey}`;
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await visit(pollUrl);
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(
|
2017-08-26 02:14:09 +02:00
|
|
|
pageParticipation.url,
|
2015-11-02 23:02:59 +01:00
|
|
|
window.location.href,
|
|
|
|
'share link is shown'
|
|
|
|
);
|
2016-08-20 22:02:53 +02:00
|
|
|
|
2019-03-16 11:26:39 +01:00
|
|
|
await triggerCopySuccess();
|
2016-08-20 22:02:53 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2015-11-02 23:02:59 +01:00
|
|
|
});
|
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('shows a warning if poll is about to be expired', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
let poll = this.server.create('poll', {
|
|
|
|
encryptionKey,
|
2023-09-21 12:30:14 +02:00
|
|
|
expirationDate: DateTime.local().plus({ weeks: 1 }).toISO(),
|
2018-12-29 20:35:04 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`);
|
2017-08-26 02:14:09 +02:00
|
|
|
assert.ok(
|
|
|
|
pageParticipation.showsExpirationWarning
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('view a poll with dates', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
let poll = this.server.create('poll', {
|
|
|
|
encryptionKey,
|
|
|
|
options: [
|
|
|
|
{ title: '2015-12-12' },
|
|
|
|
{ title: '2016-01-01' }
|
|
|
|
]
|
|
|
|
});
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`);
|
2016-04-08 21:48:22 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
pageParticipation.options().labels,
|
|
|
|
[
|
2017-07-25 16:10:55 +02:00
|
|
|
'Saturday, December 12, 2015',
|
|
|
|
'Friday, January 1, 2016'
|
2016-04-08 21:48:22 +02:00
|
|
|
]
|
|
|
|
);
|
2015-08-01 23:54:07 +02:00
|
|
|
});
|
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('view a poll with dates and times', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
2023-09-21 12:30:14 +02:00
|
|
|
let timezone = Intl.DateTimeFormat().resolvedOptions().timeZone ;
|
2018-12-29 20:35:04 +01:00
|
|
|
let poll = this.server.create('poll', {
|
|
|
|
encryptionKey,
|
2023-09-21 12:30:14 +02:00
|
|
|
expirationDate: DateTime.local().plus({ years: 1 }).toISO(),
|
2018-12-29 20:35:04 +01:00
|
|
|
isDateTime: true,
|
|
|
|
options: [
|
2023-09-21 12:30:14 +02:00
|
|
|
// need to parse the date with luxon cause Safari's Date.parse()
|
2020-01-31 21:45:58 +01:00
|
|
|
// implementation treats a data-time string without explicit
|
|
|
|
// time zone as UTC rather than local time
|
2023-09-21 12:30:14 +02:00
|
|
|
{ title: DateTime.fromISO('2015-12-12T11:11:00').toISO() },
|
|
|
|
{ title: DateTime.fromISO('2015-12-12T13:13:00').toISO() },
|
|
|
|
{ title: DateTime.fromISO('2016-01-01T11:11:00').toISO() }
|
2018-12-29 20:35:04 +01:00
|
|
|
],
|
|
|
|
timezone
|
|
|
|
});
|
|
|
|
|
|
|
|
await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`);
|
2016-04-08 21:48:22 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
pageParticipation.options().labels,
|
|
|
|
[
|
|
|
|
// full date
|
2023-09-21 12:30:14 +02:00
|
|
|
'Saturday, December 12, 2015 at 11:11 AM',
|
2016-04-08 21:48:22 +02:00
|
|
|
// only time cause day is repeated
|
2020-01-03 14:25:37 +01:00
|
|
|
'1:13 PM',
|
2016-04-08 21:48:22 +02:00
|
|
|
// full date cause day changed
|
2023-09-21 12:30:14 +02:00
|
|
|
'Friday, January 1, 2016 at 11:11 AM',
|
2016-04-08 21:48:22 +02:00
|
|
|
]
|
|
|
|
);
|
2017-08-26 02:14:09 +02:00
|
|
|
assert.notOk(
|
|
|
|
pageParticipation.showsExpirationWarning,
|
|
|
|
'does not show an expiration warning if poll will not expire in next weeks'
|
|
|
|
);
|
2015-08-01 23:54:07 +02:00
|
|
|
});
|
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('view a poll while timezone differs from the one poll got created in and choose local timezone', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
2023-09-21 12:30:14 +02:00
|
|
|
let timezoneUser = Intl.DateTimeFormat().resolvedOptions().timeZone ;
|
2018-12-29 20:35:04 +01:00
|
|
|
let timezonePoll = timezoneUser !== 'America/Caracas' ? 'America/Caracas' : 'Europe/Moscow';
|
|
|
|
let poll = this.server.create('poll', {
|
|
|
|
encryptionKey,
|
|
|
|
isDateTime: true,
|
|
|
|
options: [
|
|
|
|
{ title: '2015-12-12T11:11:00.000Z' },
|
|
|
|
{ title: '2016-01-01T11:11:00.000Z' }
|
|
|
|
],
|
|
|
|
timezone: timezonePoll,
|
|
|
|
users: [
|
|
|
|
this.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'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`);
|
2019-11-14 21:18:52 +01:00
|
|
|
assert.dom('[data-test-modal="choose-timezone"]')
|
2019-01-18 19:59:21 +01:00
|
|
|
.exists('user is asked which timezone should be used');
|
2018-12-29 20:35:04 +01:00
|
|
|
|
2019-11-14 21:18:52 +01:00
|
|
|
await click('[data-test-modal="choose-timezone"] [data-test-button="use-local-timezone"]');
|
2018-12-29 20:35:04 +01:00
|
|
|
assert.deepEqual(
|
|
|
|
pageParticipation.options().labels,
|
|
|
|
[
|
2023-09-21 12:30:14 +02:00
|
|
|
Intl.DateTimeFormat('en-US', { dateStyle: "full", timeStyle: "short" }).format(new Date('2015-12-12T11:11:00.000Z')),
|
|
|
|
Intl.DateTimeFormat('en-US', { dateStyle: "full", timeStyle: "short" }).format(new Date('2016-01-01T11:11:00.000Z')),
|
2018-12-29 20:35:04 +01:00
|
|
|
]
|
|
|
|
);
|
2019-11-14 21:18:52 +01:00
|
|
|
assert.dom('[data-test-modal="choose-timezone"]').doesNotExist('modal is closed');
|
2015-08-01 23:54:07 +02:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await switchTab('evaluation');
|
|
|
|
assert.deepEqual(
|
|
|
|
pageEvaluation.preferedOptions,
|
2023-09-21 12:30:14 +02:00
|
|
|
[Intl.DateTimeFormat('en-US', { dateStyle: "full", timeStyle: "short" }).format(new Date('2015-12-12T11:11:00.000Z'))]
|
2018-12-29 20:35:04 +01:00
|
|
|
);
|
2015-08-01 23:54:07 +02:00
|
|
|
});
|
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('view a poll while timezone differs from the one poll got created in and choose poll timezone', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
2023-09-21 12:30:14 +02:00
|
|
|
let timezoneUser = Intl.DateTimeFormat().resolvedOptions().timeZone ;
|
2018-12-29 20:35:04 +01:00
|
|
|
let timezonePoll = timezoneUser !== 'America/Caracas' ? 'America/Caracas' : 'Europe/Moscow';
|
|
|
|
let poll = this.server.create('poll', {
|
|
|
|
encryptionKey,
|
|
|
|
isDateTime: true,
|
|
|
|
options: [
|
|
|
|
{ title: '2015-12-12T11:11:00.000Z' },
|
|
|
|
{ title: '2016-01-01T11:11:00.000Z' }
|
|
|
|
],
|
|
|
|
timezone: timezonePoll,
|
|
|
|
users: [
|
|
|
|
this.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'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`);
|
2019-11-14 21:18:52 +01:00
|
|
|
assert.dom('[data-test-modal="choose-timezone"]')
|
2019-01-18 19:59:21 +01:00
|
|
|
.exists('user is asked which timezone should be used');
|
2018-12-29 20:35:04 +01:00
|
|
|
|
2019-11-14 21:18:52 +01:00
|
|
|
await click('[data-test-modal="choose-timezone"] [data-test-button="use-poll-timezone"]');
|
2018-12-29 20:35:04 +01:00
|
|
|
assert.deepEqual(
|
|
|
|
pageParticipation.options().labels,
|
|
|
|
[
|
2023-09-21 12:30:14 +02:00
|
|
|
Intl.DateTimeFormat('en-US', { timeZone: timezonePoll, dateStyle: "full", timeStyle: "short" }).format(new Date('2015-12-12T11:11:00.000Z')),
|
|
|
|
Intl.DateTimeFormat('en-US', { timeZone: timezonePoll, dateStyle: "full", timeStyle: "short" }).format(new Date('2016-01-01T11:11:00.000Z')),
|
2018-12-29 20:35:04 +01:00
|
|
|
]
|
|
|
|
);
|
2019-11-14 21:18:52 +01:00
|
|
|
assert.dom('[data-test-modal="choose-timezone"]').doesNotExist('modal is closed');
|
2018-12-29 20:35:04 +01:00
|
|
|
|
|
|
|
await switchTab('evaluation');
|
|
|
|
assert.deepEqual(
|
|
|
|
pageEvaluation.preferedOptions,
|
2023-09-21 12:30:14 +02:00
|
|
|
[Intl.DateTimeFormat('en-US', { timeZone: timezonePoll, dateStyle: "full", timeStyle: "short" }).format(new Date('2015-12-12T11:11:00.000Z')),]
|
2018-12-29 20:35:04 +01:00
|
|
|
);
|
|
|
|
});
|
2019-04-23 17:37:42 +02:00
|
|
|
|
|
|
|
test('shows error page if poll does not exist', async function(assert) {
|
|
|
|
let pollId = 'not-existing';
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
|
|
|
|
await visit(`/poll/${pollId}?encryptionKey=${encryptionKey}`);
|
|
|
|
assert.equal(currentURL(), `/poll/${pollId}?encryptionKey=${encryptionKey}`, 'shows URL entered by user');
|
|
|
|
assert.equal(currentRouteName(), 'poll_error', 'shows error substate of poll route');
|
|
|
|
assert.dom('[data-test-error-type]').hasAttribute('data-test-error-type', 'not-found');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('shows error page if encryption key is wrong', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
let poll = this.server.create('poll', { encryptionKey: 'anotherkey' });
|
|
|
|
|
|
|
|
await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`);
|
|
|
|
assert.equal(currentURL(), `/poll/${poll.id}?encryptionKey=${encryptionKey}`, 'shows URL entered by user');
|
|
|
|
assert.equal(currentRouteName(), 'poll_error', 'shows error substate of poll route');
|
|
|
|
assert.dom('[data-test-error-type]').hasAttribute('data-test-error-type', 'decryption-failed');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('shows error page if server returns a 500', async function(assert) {
|
|
|
|
let pollId = 'not-existing';
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
|
|
|
|
// mock server returning 500 error
|
|
|
|
this.server.get('polls/:id', () => {}, 500);
|
|
|
|
|
|
|
|
await visit(`/poll/${pollId}?encryptionKey=${encryptionKey}`);
|
|
|
|
assert.equal(currentURL(), `/poll/${pollId}?encryptionKey=${encryptionKey}`, 'shows URL entered by user');
|
|
|
|
assert.equal(currentRouteName(), 'poll_error', 'shows error substate of poll route');
|
|
|
|
assert.dom('[data-test-error-type]').hasAttribute('data-test-error-type', 'unexpected');
|
|
|
|
})
|
2015-08-01 23:54:07 +02:00
|
|
|
});
|