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

300 lines
9.2 KiB
JavaScript
Raw Normal View History

2018-12-29 20:35:04 +01:00
import { findAll, currentRouteName, find, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { t } from 'ember-i18n/test-support';
import switchTab from 'croodle/tests/helpers/switch-tab';
2016-03-20 15:30:54 +01:00
import moment from 'moment';
import PollEvaluationPage from 'croodle/tests/pages/poll/evaluation';
import { assign } from '@ember/polyfills';
2015-08-21 12:10:02 +02:00
2018-12-29 20:35:04 +01:00
module('Acceptance | view evaluation', function(hooks) {
hooks.beforeEach(function() {
window.localStorage.setItem('locale', 'en');
2015-08-21 12:10:02 +02:00
});
2018-12-29 20:35:04 +01:00
setupApplicationTest(hooks);
setupMirage(hooks);
2015-08-21 12:10:02 +02:00
2018-12-29 20:35:04 +01:00
test('evaluation summary is not present for poll without participants', async function(assert) {
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
let poll = this.server.create('poll', {
encryptionKey
});
2015-08-21 12:10:02 +02:00
2018-12-29 20:35:04 +01:00
await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`);
assert.equal(currentRouteName(), 'poll.participation');
await switchTab('evaluation');
assert.equal(findAll('.tab-content .tab-pane .evaluation-summary').length, 0, 'evaluation summary is not present');
2016-03-20 15:30:54 +01:00
});
2018-12-29 20:35:04 +01:00
test('evaluation is correct for FindADate', async function(assert) {
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
let user1 = this.server.create('user', {
creationDate: '2015-01-01T00:00:00.000Z',
encryptionKey,
name: 'Maximilian',
selections: [
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
},
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
}
]
});
let user2 = this.server.create('user', {
creationDate: '2015-08-01T00:00:00.000Z',
encryptionKey,
name: 'Peter',
selections: [
{
type: 'no',
labelTranslation: 'answerTypes.no.label',
icon: 'glyphicon glyphicon-thumbs-down',
label: 'No'
},
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
}
]
});
let poll = this.server.create('poll', {
answers: [
{
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'
}
],
encryptionKey,
options: [
{ title: '2015-12-12' },
{ title: '2016-01-01' }
],
users: [user1, user2]
});
2016-03-20 15:30:54 +01:00
2018-12-29 20:35:04 +01:00
await visit(`/poll/${poll.id}/evaluation?encryptionKey=${encryptionKey}`);
assert.equal(currentRouteName(), 'poll.evaluation');
assert.equal(findAll('.tab-content .tab-pane .evaluation-summary').length, 1, 'evaluation summary is present');
2016-03-20 15:30:54 +01:00
assert.equal(
2018-12-29 20:35:04 +01:00
find('.participants').textContent.trim(),
2016-03-20 15:30:54 +01:00
t('poll.evaluation.participants', { count: 2 }).toString(),
'participants are counted correctly'
);
assert.equal(
2018-12-29 20:35:04 +01:00
find('.best-options strong').textContent.trim(),
'Friday, January 1, 2016',
2016-03-20 15:30:54 +01:00
'options are evaluated correctly'
);
assert.equal(
2018-12-29 20:35:04 +01:00
find('.last-participation').textContent.trim(),
2016-03-20 15:30:54 +01:00
t('poll.evaluation.lastParticipation', {
ago: moment('2015-08-01T00:00:00.000Z').from()
}).toString(),
'last participation is evaluated correctly'
);
});
2015-08-21 12:10:02 +02:00
2018-12-29 20:35:04 +01:00
test('evaluation is correct for MakeAPoll', async function(assert) {
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
let usersData = [
{
creationDate: '2015-01-01T00:00:00.000Z',
encryptionKey,
name: 'Maximilian',
selections: [
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
},
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
}
]
},
{
creationDate: '2015-08-01T00:00:00.000Z',
encryptionKey,
name: 'Peter',
selections: [
{
type: 'no',
labelTranslation: 'answerTypes.no.label',
icon: 'glyphicon glyphicon-thumbs-down',
label: 'No'
},
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
}
]
},
];
let pollData = {
2018-12-29 20:35:04 +01:00
answers: [
{
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'
}
],
encryptionKey,
options: [
{ title: 'first option' },
{ title: 'second option' }
],
pollType: 'MakeAPoll',
};
let poll = this.server.create('poll', assign(pollData, { users: usersData.map((_) => this.server.create('user', _)) }));
2015-08-21 12:10:02 +02:00
2018-12-29 20:35:04 +01:00
await visit(`/poll/${poll.id}/evaluation?encryptionKey=${encryptionKey}`);
assert.equal(currentRouteName(), 'poll.evaluation');
assert.equal(findAll('.tab-content .tab-pane .evaluation-summary').length, 1, 'evaluation summary is present');
2016-03-20 15:30:54 +01:00
assert.equal(
2018-12-29 20:35:04 +01:00
find('.participants').textContent.trim(),
2016-03-20 15:30:54 +01:00
t('poll.evaluation.participants', { count: 2 }).toString(),
'participants are counted correctly'
);
assert.equal(
2018-12-29 20:35:04 +01:00
find('.best-options strong').textContent.trim(),
2016-03-20 15:30:54 +01:00
'second option',
'options are evaluated correctly'
);
2016-03-20 15:30:54 +01:00
assert.deepEqual(
PollEvaluationPage.options.map((_) => _.label),
['first option', 'second option'],
2016-03-20 15:30:54 +01:00
'dates are used as table headers'
);
assert.deepEqual(
PollEvaluationPage.participants.map((_) => _.name), usersData.map((_) => _.name),
'users are listed in participants table with their names'
2016-03-20 15:30:54 +01:00
);
usersData.forEach((user) => {
let participant = PollEvaluationPage.participants.filterBy('name', user.name)[0];
assert.deepEqual(
participant.selections.map((_) => _.answer),
user.selections.map((_) => t(_.labelTranslation).toString()),
`answers are shown for user ${user.name} in participants table`
);
});
2016-03-20 15:30:54 +01:00
assert.equal(
2018-12-29 20:35:04 +01:00
find('.last-participation').textContent.trim(),
2016-03-20 15:30:54 +01:00
t('poll.evaluation.lastParticipation', {
ago: moment('2015-08-01T00:00:00.000Z').from()
}).toString(),
'last participation is evaluated correctly'
);
2015-08-21 12:10:02 +02:00
});
2016-03-18 20:26:41 +01:00
2018-12-29 20:35:04 +01:00
test('could open evaluation by tab from poll participation', async function(assert) {
let encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
let poll = this.server.create('poll', {
answers: [
{
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'
}
],
encryptionKey,
options: [
{ title: '2015-12-12' },
{ title: '2016-01-01' }
],
users: [
this.server.create('user', {
creationDate: '2015-01-01T00:00:00.000Z',
encryptionKey,
name: 'Maximilian',
selections: [
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
},
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
}
]
}),
this.server.create('user', {
creationDate: '2015-08-01T00:00:00.000Z',
encryptionKey,
name: 'Peter',
selections: [
{
type: 'yes',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
},
{
id: 'no',
labelTranslation: 'answerTypes.yes.label',
icon: 'glyphicon glyphicon-thumbs-up',
label: 'Yes'
}
]
})
]
});
2016-03-18 20:26:41 +01:00
2018-12-29 20:35:04 +01:00
await visit(`/poll/${poll.id}?encryptionKey=${encryptionKey}`);
assert.equal(currentRouteName(), 'poll.participation');
2016-03-20 15:30:54 +01:00
2018-12-29 20:35:04 +01:00
await switchTab('evaluation');
assert.equal(currentRouteName(), 'poll.evaluation');
assert.equal(
find('.tab-pane h2').textContent.trim(),
t('poll.evaluation.label').toString(),
'headline is there'
);
2016-03-18 20:26:41 +01:00
});
});