decide.nolog.cz/tests/integration/components/create-options-datetime-test.js

144 lines
4.6 KiB
JavaScript
Raw Normal View History

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';
import hbs from 'htmlbars-inline-precompile';
import { setupIntl } from 'ember-intl/test-support';
module('Integration | Component | create options datetime', function (hooks) {
2018-12-29 20:35:04 +01:00
setupRenderingTest(hooks);
setupIntl(hooks);
hooks.beforeEach(function () {
2018-12-29 20:35:04 +01:00
this.store = this.owner.lookup('service:store');
});
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'
*/
test('it generates input field for options iso 8601 date string (without time)', async function (assert) {
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');
});
test('it generates input field for options iso 8601 datetime string (with time)', async function (assert) {
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}} />`);
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');
});
test('it hides repeated labels', async function (assert) {
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}} />`);
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(
findAll('.days .form-group')[0]
.querySelector('label')
.classList.contains('sr-only'),
'the first label is shown',
2018-12-29 20:35:04 +01:00
);
assert.ok(
findAll('.days .form-group')[1]
.querySelector('label')
.classList.contains('sr-only'),
'the repeated label on second form-group is hidden by sr-only class',
2018-12-29 20:35:04 +01:00
);
assert.notOk(
findAll('.days .form-group')[2]
.querySelector('label')
.classList.contains('sr-only'),
'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
});
test('allows to add another option', async function (assert) {
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');
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(
findAll('.days .form-group')[1].querySelector('label').textContent,
findAll('.days .form-group')[0].querySelector('label').textContent,
'new input has correct label',
2018-12-29 20:35:04 +01:00
);
assert.ok(
findAll('.days .form-group')[1]
.querySelector('label')
.classList.contains('sr-only'),
"label ofnew input is hidden cause it's repeated",
2018-12-29 20:35:04 +01:00
);
});
test('allows to delete an option', async function (assert) {
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),
'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');
});
});