2018-12-29 20:35:04 +01:00
|
|
|
import {
|
|
|
|
click,
|
|
|
|
find,
|
|
|
|
findAll,
|
|
|
|
currentURL,
|
|
|
|
currentRouteName,
|
|
|
|
visit
|
|
|
|
} from '@ember/test-helpers';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
|
|
import { t } from 'ember-i18n/test-support';
|
2019-05-21 13:53:49 +02:00
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2019-04-20 23:29:59 +02:00
|
|
|
import PollEvaluationPage from 'croodle/tests/pages/poll/evaluation';
|
2018-12-29 20:35:04 +01:00
|
|
|
import pollParticipate from 'croodle/tests/helpers/poll-participate';
|
2015-01-24 14:50:56 +01:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
module('Acceptance | participate in a poll', function(hooks) {
|
2019-04-20 23:29:59 +02:00
|
|
|
let yesLabel;
|
|
|
|
let noLabel;
|
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
hooks.beforeEach(function() {
|
2016-08-21 14:31:39 +02:00
|
|
|
window.localStorage.setItem('locale', 'en');
|
2015-07-27 20:28:00 +02:00
|
|
|
});
|
2016-12-19 17:04:09 +01:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
2019-04-20 23:29:59 +02:00
|
|
|
hooks.beforeEach(function() {
|
|
|
|
yesLabel = t('answerTypes.yes.label').toString();
|
|
|
|
noLabel = t('answerTypes.no.label').toString();
|
|
|
|
});
|
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('participate in a default poll', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
let poll = this.server.create('poll', {
|
|
|
|
encryptionKey
|
2015-01-24 14:50:56 +01:00
|
|
|
});
|
2015-06-20 18:33:51 +02:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`);
|
|
|
|
assert.equal(currentRouteName(), 'poll.participation', 'poll is redirected to poll.participation');
|
|
|
|
|
|
|
|
await pollParticipate('Max Meiner', ['yes', 'no']);
|
|
|
|
assert.equal(currentRouteName(), 'poll.evaluation');
|
|
|
|
assert.equal(
|
|
|
|
currentURL().split('?')[1],
|
|
|
|
`encryptionKey=${encryptionKey}`,
|
|
|
|
'encryption key is part of query params'
|
|
|
|
);
|
2019-04-20 23:29:59 +02:00
|
|
|
assert.equal(PollEvaluationPage.participants.length, 1, 'user is added to participants table');
|
|
|
|
let participant = PollEvaluationPage.participants.filterBy('name', 'Max Meiner')[0];
|
|
|
|
assert.ok(participant, 'user exists in participants table');
|
|
|
|
assert.deepEqual(
|
|
|
|
participant.selections.map((_) => _.answer), [yesLabel, noLabel],
|
|
|
|
'participants table shows correct answers for new participant'
|
|
|
|
);
|
2018-12-29 20:35:04 +01:00
|
|
|
|
|
|
|
await click('.nav .participation');
|
|
|
|
assert.equal(currentRouteName(), 'poll.participation');
|
|
|
|
assert.equal(find('.name input').value, '', 'input for name is cleared');
|
|
|
|
assert.ok(
|
|
|
|
!findAll('input[type="radio"]').toArray().some((el) => el.checked),
|
|
|
|
'radios are cleared'
|
|
|
|
);
|
|
|
|
|
|
|
|
await pollParticipate('Peter Müller', ['yes', 'yes']);
|
|
|
|
assert.equal(currentRouteName(), 'poll.evaluation');
|
2019-04-20 23:29:59 +02:00
|
|
|
assert.equal(PollEvaluationPage.participants.length, 2, 'user is added to participants table');
|
|
|
|
participant = PollEvaluationPage.participants.filterBy('name', 'Peter Müller')[0];
|
|
|
|
assert.ok(participant, 'user exists in participants table');
|
|
|
|
assert.deepEqual(
|
|
|
|
participant.selections.map((_) => _.answer), [yesLabel, yesLabel],
|
|
|
|
'participants table shows correct answers for new participant'
|
|
|
|
);
|
2016-12-19 17:04:09 +01:00
|
|
|
});
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('participate in a poll using freetext', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
let poll = this.server.create('poll', {
|
|
|
|
answerType: 'FreeText',
|
|
|
|
answers: [],
|
|
|
|
encryptionKey
|
2015-06-20 18:33:51 +02:00
|
|
|
});
|
2015-07-01 16:21:18 +02:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`)
|
|
|
|
assert.equal(currentRouteName(), 'poll.participation');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await pollParticipate('Max Manus', ['answer 1', 'answer 2']);
|
|
|
|
assert.equal(currentRouteName(), 'poll.evaluation');
|
2019-04-20 23:29:59 +02:00
|
|
|
assert.equal(PollEvaluationPage.participants.length, 1, 'user is added to participants table');
|
|
|
|
|
|
|
|
let participant = PollEvaluationPage.participants.filterBy('name', 'Max Manus')[0];
|
|
|
|
assert.ok(participant, 'user exists in participants table');
|
|
|
|
assert.deepEqual(
|
|
|
|
participant.selections.map((_) => _.answer), ['answer 1', 'answer 2'],
|
|
|
|
'participants table shows correct answers for new participant'
|
|
|
|
);
|
2018-12-29 20:35:04 +01:00
|
|
|
});
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('participate in a poll which does not force an answer to all options', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
let poll = this.server.create('poll', {
|
|
|
|
encryptionKey,
|
|
|
|
forceAnswer: false
|
2015-07-01 16:21:18 +02:00
|
|
|
});
|
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await visit(`/poll/${poll.id}/participation?encryptionKey=${encryptionKey}`);
|
|
|
|
assert.equal(currentRouteName(), 'poll.participation');
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await pollParticipate('Karl Käfer', ['yes', null]);
|
|
|
|
assert.equal(currentRouteName(), 'poll.evaluation');
|
2019-04-20 23:29:59 +02:00
|
|
|
assert.equal(PollEvaluationPage.participants.length, 1, 'user is added to participants table');
|
|
|
|
|
|
|
|
let participant = PollEvaluationPage.participants.filterBy('name', 'Karl Käfer')[0];
|
|
|
|
assert.ok(participant, 'user exists in participants table');
|
|
|
|
assert.deepEqual(
|
|
|
|
participant.selections.map((_) => _.answer), [yesLabel, ''],
|
|
|
|
'participants table shows correct answers for new participant'
|
|
|
|
);
|
2018-12-29 20:35:04 +01:00
|
|
|
});
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('participate in a poll which allows anonymous participation', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
let poll = this.server.create('poll', {
|
|
|
|
anonymousUser: true,
|
|
|
|
encryptionKey
|
2015-07-01 16:21:18 +02:00
|
|
|
});
|
2016-08-12 13:00:18 +02:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await visit(`/poll/${poll.id}/participation?encryptionKey=${encryptionKey}`);
|
|
|
|
assert.equal(currentRouteName(), 'poll.participation');
|
|
|
|
|
|
|
|
await pollParticipate(null, ['yes', 'no']);
|
|
|
|
assert.equal(currentRouteName(), 'poll.evaluation');
|
2019-04-20 23:29:59 +02:00
|
|
|
assert.equal(PollEvaluationPage.participants.length, 1, 'user is added to participants table');
|
|
|
|
|
|
|
|
let participant = PollEvaluationPage.participants.filterBy('name', '')[0];
|
|
|
|
assert.ok(participant, 'user exists in participants table');
|
|
|
|
assert.deepEqual(
|
|
|
|
participant.selections.map((_) => _.answer), [yesLabel, noLabel],
|
|
|
|
'participants table shows correct answers for new participant'
|
|
|
|
);
|
2016-12-19 17:04:09 +01:00
|
|
|
});
|
2016-08-12 13:00:18 +02:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
test('network connectivity errors', async function(assert) {
|
|
|
|
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
let poll = this.server.create('poll', {
|
|
|
|
encryptionKey
|
2016-08-12 13:00:18 +02:00
|
|
|
});
|
2018-12-29 20:35:04 +01:00
|
|
|
|
|
|
|
this.server.post('/users', undefined, 503);
|
|
|
|
|
|
|
|
await visit(`/poll/${poll.id}/participation?encryptionKey=${encryptionKey}`);
|
|
|
|
assert.equal(currentRouteName(), 'poll.participation');
|
2019-01-18 19:59:21 +01:00
|
|
|
assert.dom('modal-saving-failed-modal')
|
|
|
|
.doesNotExist('failed saving notification is not shown before attempt to save');
|
2018-12-29 20:35:04 +01:00
|
|
|
|
2019-04-20 23:29:59 +02:00
|
|
|
await pollParticipate('John Doe', ['yes', 'no']);
|
2019-01-18 19:59:21 +01:00
|
|
|
assert.dom('#modal-saving-failed-modal')
|
|
|
|
.exists('user gets notified that saving failed');
|
2018-12-29 20:35:04 +01:00
|
|
|
|
|
|
|
this.server.post('/users');
|
|
|
|
|
|
|
|
await click('#modal-saving-failed-modal button');
|
2019-01-18 19:59:21 +01:00
|
|
|
assert.dom('#modal-saving-failed-modal')
|
|
|
|
.doesNotExist('Notification is hidden after another save attempt was successful');
|
2018-12-29 20:35:04 +01:00
|
|
|
assert.equal(currentRouteName(), 'poll.evaluation');
|
2019-04-20 23:29:59 +02:00
|
|
|
assert.equal(PollEvaluationPage.participants.length, 1, 'user is added to participants table');
|
|
|
|
|
|
|
|
let participant = PollEvaluationPage.participants.filterBy('name', 'John Doe')[0];
|
|
|
|
assert.ok(participant, 'user exists in participants table');
|
|
|
|
assert.deepEqual(
|
|
|
|
participant.selections.map((_) => _.answer), [yesLabel, noLabel],
|
|
|
|
'participants table shows correct answers for new participant'
|
|
|
|
);
|
2016-08-12 13:00:18 +02:00
|
|
|
});
|
|
|
|
});
|