2018-12-29 20:35:04 +01:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2023-11-04 17:32:09 +01:00
|
|
|
import { render, click, findAll } from '@ember/test-helpers';
|
2016-01-20 02:52:21 +01:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2023-11-03 20:16:25 +01:00
|
|
|
import { setupIntl } from 'ember-intl/test-support';
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2023-10-15 20:37:03 +02:00
|
|
|
module('Integration | Component | create options datetime', function (hooks) {
|
2018-12-29 20:35:04 +01:00
|
|
|
setupRenderingTest(hooks);
|
2023-11-03 20:16:25 +01:00
|
|
|
setupIntl(hooks);
|
2016-01-29 12:54:54 +01:00
|
|
|
|
2023-10-15 20:37:03 +02:00
|
|
|
hooks.beforeEach(function () {
|
2018-12-29 20:35:04 +01:00
|
|
|
this.store = this.owner.lookup('service:store');
|
2016-06-06 00:37:26 +02:00
|
|
|
});
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
/*
|
|
|
|
* watch out:
|
|
|
|
* polyfill adds another input[type="text"] for every input[type="time"]
|
|
|
|
* if browser doesn't support input[type="time"]
|
|
|
|
* that ones could be identifed by class 'ws-inputreplace'
|
|
|
|
*/
|
2016-01-22 00:19:46 +01:00
|
|
|
|
2023-10-15 20:37:03 +02:00
|
|
|
test('it generates input field for options iso 8601 date string (without time)', async function (assert) {
|
2023-12-19 19:28:04 +01:00
|
|
|
this.set('poll', {
|
|
|
|
dateOptions: new Set(['2015-01-01']),
|
|
|
|
timesForDateOptions: new Map(),
|
|
|
|
});
|
|
|
|
await render(hbs`<CreateOptionsDatetime @poll={{this.poll}} />`);
|
2018-12-29 20:35:04 +01:00
|
|
|
|
2023-11-04 17:32:09 +01:00
|
|
|
assert
|
|
|
|
.dom('.days .form-group input')
|
|
|
|
.exists({ count: 1 }, 'there is one input field');
|
|
|
|
assert
|
|
|
|
.dom('.days .form-group input')
|
|
|
|
.hasNoValue('value is an empty string');
|
2016-06-06 00:37:26 +02:00
|
|
|
});
|
2016-01-22 00:19:46 +01:00
|
|
|
|
2023-10-15 20:37:03 +02:00
|
|
|
test('it generates input field for options iso 8601 datetime string (with time)', async function (assert) {
|
2023-12-19 19:28:04 +01:00
|
|
|
this.set('poll', {
|
|
|
|
dateOptions: new Set(['2015-01-01']),
|
|
|
|
timesForDateOptions: new Map([['2015-01-01', new Set(['11:11'])]]),
|
|
|
|
});
|
|
|
|
await render(hbs`<CreateOptionsDatetime @poll={{this.poll}} />`);
|
2016-01-22 00:19:46 +01:00
|
|
|
|
2023-11-04 17:32:09 +01:00
|
|
|
assert
|
|
|
|
.dom('.days .form-group input')
|
|
|
|
.exists({ count: 1 }, 'there is one input field');
|
|
|
|
assert
|
|
|
|
.dom('.days .form-group input')
|
|
|
|
.hasValue('11:11', 'it has time in option as value');
|
2016-06-06 00:37:26 +02:00
|
|
|
});
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2023-10-15 20:37:03 +02:00
|
|
|
test('it hides repeated labels', async function (assert) {
|
2023-12-19 19:28:04 +01:00
|
|
|
this.set('poll', {
|
|
|
|
dateOptions: new Set(['2015-01-01', '2015-02-02']),
|
|
|
|
timesForDateOptions: new Map([
|
|
|
|
['2015-01-01', new Set(['11:11', '22:22'])],
|
|
|
|
]),
|
|
|
|
});
|
|
|
|
await render(hbs`<CreateOptionsDatetime @poll={{this.poll}} />`);
|
2016-01-22 00:19:46 +01:00
|
|
|
|
2023-11-04 17:32:09 +01:00
|
|
|
assert
|
|
|
|
.dom('.days label')
|
|
|
|
.exists({ count: 3 }, 'every form-group has a label');
|
|
|
|
assert
|
|
|
|
.dom('.days label:not(.sr-only)')
|
|
|
|
.exists(
|
|
|
|
{ count: 2 },
|
|
|
|
'there are two not hidden labels for two different dates',
|
|
|
|
);
|
2018-12-29 20:35:04 +01:00
|
|
|
assert.notOk(
|
2023-10-15 20:37:03 +02:00
|
|
|
findAll('.days .form-group')[0]
|
|
|
|
.querySelector('label')
|
|
|
|
.classList.contains('sr-only'),
|
2023-10-17 10:44:45 +02:00
|
|
|
'the first label is shown',
|
2018-12-29 20:35:04 +01:00
|
|
|
);
|
|
|
|
assert.ok(
|
2023-10-15 20:37:03 +02:00
|
|
|
findAll('.days .form-group')[1]
|
|
|
|
.querySelector('label')
|
|
|
|
.classList.contains('sr-only'),
|
2023-10-17 10:44:45 +02:00
|
|
|
'the repeated label on second form-group is hidden by sr-only class',
|
2018-12-29 20:35:04 +01:00
|
|
|
);
|
|
|
|
assert.notOk(
|
2023-10-15 20:37:03 +02:00
|
|
|
findAll('.days .form-group')[2]
|
|
|
|
.querySelector('label')
|
|
|
|
.classList.contains('sr-only'),
|
2023-10-17 10:44:45 +02:00
|
|
|
'the new label on third form-group is shown',
|
2018-12-29 20:35:04 +01:00
|
|
|
);
|
2016-05-20 21:49:29 +02:00
|
|
|
});
|
2016-01-22 00:19:46 +01:00
|
|
|
|
2023-10-15 20:37:03 +02:00
|
|
|
test('allows to add another option', async function (assert) {
|
2023-12-19 19:28:04 +01:00
|
|
|
this.set('poll', {
|
|
|
|
dateOptions: new Set(['2015-01-01', '2015-02-02']),
|
|
|
|
timesForDateOptions: new Map(),
|
|
|
|
});
|
|
|
|
await render(hbs`<CreateOptionsDatetime @poll={{this.poll}} />`);
|
2018-12-29 20:35:04 +01:00
|
|
|
|
2023-11-04 17:32:09 +01:00
|
|
|
assert
|
|
|
|
.dom('.days .form-group input')
|
|
|
|
.exists({ count: 2 }, 'there are two input fields before');
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2018-12-29 20:35:04 +01:00
|
|
|
await click(findAll('.days .form-group')[0].querySelector('.add'));
|
2023-11-04 17:32:09 +01:00
|
|
|
assert
|
|
|
|
.dom('.days .form-group input')
|
|
|
|
.exists({ count: 3 }, 'another input field is added');
|
|
|
|
assert.strictEqual(
|
2019-01-18 19:59:21 +01:00
|
|
|
findAll('.days .form-group')[1].querySelector('label').textContent,
|
|
|
|
findAll('.days .form-group')[0].querySelector('label').textContent,
|
2023-10-17 10:44:45 +02:00
|
|
|
'new input has correct label',
|
2018-12-29 20:35:04 +01:00
|
|
|
);
|
|
|
|
assert.ok(
|
2023-10-15 20:37:03 +02:00
|
|
|
findAll('.days .form-group')[1]
|
|
|
|
.querySelector('label')
|
|
|
|
.classList.contains('sr-only'),
|
2023-10-17 10:44:45 +02:00
|
|
|
"label ofnew input is hidden cause it's repeated",
|
2018-12-29 20:35:04 +01:00
|
|
|
);
|
2016-06-06 00:37:26 +02:00
|
|
|
});
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2023-10-15 20:37:03 +02:00
|
|
|
test('allows to delete an option', async function (assert) {
|
2023-12-19 19:28:04 +01:00
|
|
|
this.set('poll', {
|
|
|
|
dateOptions: new Set(['2015-01-01']),
|
|
|
|
timesForDateOptions: new Map([
|
|
|
|
['2015-01-01', new Set(['11:11', '22:22'])],
|
|
|
|
]),
|
|
|
|
});
|
|
|
|
await render(hbs`<CreateOptionsDatetime @poll={{this.poll}} />`);
|
2018-12-29 20:35:04 +01:00
|
|
|
|
2023-11-04 17:32:09 +01:00
|
|
|
assert
|
|
|
|
.dom('.days input')
|
|
|
|
.exists({ count: 2 }, 'there are two input fields before');
|
2018-12-29 20:35:04 +01:00
|
|
|
assert.ok(
|
|
|
|
findAll('.delete').every((el) => el.disabled === false),
|
2023-10-17 10:44:45 +02:00
|
|
|
'options are deleteable',
|
2018-12-29 20:35:04 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
await click(findAll('.days .form-group')[0].querySelector('.delete'));
|
2023-11-04 17:32:09 +01:00
|
|
|
assert
|
|
|
|
.dom('.days .form-group input')
|
|
|
|
.exists({ count: 1 }, 'one input field is removed after deletion');
|
|
|
|
assert
|
|
|
|
.dom('.days .form-group input')
|
|
|
|
.hasValue('22:22', 'correct input field is deleted');
|
2016-06-06 00:37:26 +02:00
|
|
|
});
|
|
|
|
});
|