2016-01-20 02:52:21 +01:00
|
|
|
import { moduleForComponent, test } from 'ember-qunit';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2017-07-29 15:00:11 +02:00
|
|
|
import jQuery from 'jquery';
|
2016-01-22 00:19:46 +01:00
|
|
|
import Ember from 'ember';
|
|
|
|
import moment from 'moment';
|
2016-01-20 02:52:21 +01:00
|
|
|
|
|
|
|
moduleForComponent('create-options-datetime', 'Integration | Component | create options datetime', {
|
2016-05-20 21:49:29 +02:00
|
|
|
integration: true,
|
|
|
|
beforeEach() {
|
|
|
|
this.inject.service('store');
|
|
|
|
}
|
2016-01-20 02:52:21 +01:00
|
|
|
});
|
|
|
|
|
2016-01-29 12:54:54 +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
|
|
|
test('it generates inpute field for options iso 8601 date string (without time)', function(assert) {
|
2016-06-06 00:37:26 +02:00
|
|
|
// validation is based on validation of every option fragment
|
|
|
|
// which validates according to poll model it belongs to
|
|
|
|
// therefore each option needs to be pushed to poll model to have it as
|
|
|
|
// it's owner
|
|
|
|
Ember.run(() => {
|
|
|
|
this.set('poll', this.store.createRecord('poll', {
|
|
|
|
isFindADate: true,
|
2016-06-08 13:55:00 +02:00
|
|
|
isMakeAPoll: false,
|
|
|
|
options: [
|
|
|
|
{ title: '2015-01-01' }
|
|
|
|
]
|
2016-06-06 00:37:26 +02:00
|
|
|
}));
|
|
|
|
});
|
2016-06-08 13:55:00 +02:00
|
|
|
this.render(hbs`{{create-options-datetime dates=poll.options}}`);
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2016-01-22 00:19:46 +01:00
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group input').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
1,
|
|
|
|
'there is one input field'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group input').val(),
|
2016-01-22 00:19:46 +01:00
|
|
|
'',
|
|
|
|
'value is an empty string'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-01-29 11:47:19 +01:00
|
|
|
test('it generates inpute field for options iso 8601 datetime string (with time)', function(assert) {
|
2016-06-06 00:37:26 +02:00
|
|
|
// validation is based on validation of every option fragment
|
|
|
|
// which validates according to poll model it belongs to
|
|
|
|
// therefore each option needs to be pushed to poll model to have it as
|
|
|
|
// it's owner
|
|
|
|
Ember.run(() => {
|
|
|
|
this.set('poll', this.store.createRecord('poll', {
|
|
|
|
isFindADate: true,
|
2016-06-08 13:55:00 +02:00
|
|
|
isMakeAPoll: false,
|
|
|
|
options: [
|
|
|
|
{ title: '2015-01-01T11:11:00.000Z' }
|
|
|
|
]
|
2016-06-06 00:37:26 +02:00
|
|
|
}));
|
|
|
|
});
|
2016-06-08 13:55:00 +02:00
|
|
|
this.render(hbs`{{create-options-datetime dates=poll.options}}`);
|
2016-01-22 00:19:46 +01:00
|
|
|
|
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group input').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
1,
|
|
|
|
'there is one input field'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group input').val(),
|
2016-01-22 00:19:46 +01:00
|
|
|
moment('2015-01-01T11:11:00.000Z').format('HH:mm'),
|
|
|
|
'it has time in option as value'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-06-08 13:55:00 +02:00
|
|
|
test('it hides repeated labels', function(assert) {
|
2016-06-06 00:37:26 +02:00
|
|
|
// validation is based on validation of every option fragment
|
|
|
|
// which validates according to poll model it belongs to
|
|
|
|
// therefore each option needs to be pushed to poll model to have it as
|
|
|
|
// it's owner
|
|
|
|
Ember.run(() => {
|
|
|
|
this.set('poll', this.store.createRecord('poll', {
|
|
|
|
isFindADate: true,
|
2016-06-08 13:55:00 +02:00
|
|
|
isMakeAPoll: false,
|
|
|
|
options: [
|
|
|
|
{ title: moment('2015-01-01T10:11').toISOString() },
|
|
|
|
{ title: moment('2015-01-01T22:22').toISOString() },
|
|
|
|
{ title: '2015-02-02' }
|
|
|
|
]
|
2016-06-06 00:37:26 +02:00
|
|
|
}));
|
|
|
|
});
|
2016-06-08 13:55:00 +02:00
|
|
|
this.render(hbs`{{create-options-datetime dates=poll.options}}`);
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2016-01-22 00:19:46 +01:00
|
|
|
assert.equal(
|
2016-06-08 13:55:00 +02:00
|
|
|
this.$('.days label').length,
|
|
|
|
3,
|
|
|
|
'every form-group has a label'
|
2016-01-22 00:19:46 +01:00
|
|
|
);
|
|
|
|
assert.equal(
|
2016-06-08 13:55:00 +02:00
|
|
|
this.$('.days label:not(.sr-only)').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
2,
|
2016-06-08 13:55:00 +02:00
|
|
|
'there are two not hidden labels for two different dates'
|
2016-01-22 00:19:46 +01:00
|
|
|
);
|
2016-06-08 13:55:00 +02:00
|
|
|
assert.notOk(
|
|
|
|
this.$('.days .form-group').eq(0).find('label').hasClass('sr-only'),
|
|
|
|
'the first label is shown'
|
2016-01-22 00:19:46 +01:00
|
|
|
);
|
2016-06-08 13:55:00 +02:00
|
|
|
assert.ok(
|
|
|
|
this.$('.days .form-group').eq(1).find('label').hasClass('sr-only'),
|
|
|
|
'the repeated label on second form-group is hidden by sr-only class'
|
|
|
|
);
|
|
|
|
assert.notOk(
|
|
|
|
this.$('.days .form-group').eq(2).find('label').hasClass('sr-only'),
|
|
|
|
'the new label on third form-group is shown'
|
2016-01-22 00:19:46 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('allows to add another option', function(assert) {
|
2016-05-20 21:49:29 +02:00
|
|
|
// validation is based on validation of every option fragment
|
|
|
|
// which validates according to poll model it belongs to
|
|
|
|
// therefore each option needs to be pushed to poll model to have it as
|
|
|
|
// it's owner
|
|
|
|
Ember.run(() => {
|
2016-06-08 13:55:00 +02:00
|
|
|
this.set('poll', this.store.createRecord('poll', {
|
2016-05-20 21:49:29 +02:00
|
|
|
options: [
|
|
|
|
{ title: '2015-01-01' },
|
|
|
|
{ title: '2015-02-02' }
|
|
|
|
]
|
2016-06-08 13:55:00 +02:00
|
|
|
}));
|
2016-05-20 21:49:29 +02:00
|
|
|
});
|
2016-06-08 13:55:00 +02:00
|
|
|
this.render(hbs`{{create-options-datetime dates=poll.options}}`);
|
2016-01-22 00:19:46 +01:00
|
|
|
|
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group input').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
2,
|
|
|
|
'there are two input fields before'
|
|
|
|
);
|
2016-06-08 13:55:00 +02:00
|
|
|
this.$('.days .form-group').eq(0).find('.add').click();
|
2016-01-22 00:19:46 +01:00
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group input').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
3,
|
|
|
|
'another input field is added'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-06-08 13:55:00 +02:00
|
|
|
this.$('.days .form-group').eq(1).find('label').text(),
|
|
|
|
this.$('.days .form-group').eq(0).find('label').text(),
|
|
|
|
'new input has correct label'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
this.$('.days .form-group').eq(1).find('label').hasClass('sr-only'),
|
|
|
|
'label ofnew input is hidden cause it\'s repeated'
|
2016-01-22 00:19:46 +01:00
|
|
|
);
|
|
|
|
});
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2016-01-22 00:19:46 +01:00
|
|
|
test('allows to delete an option', function(assert) {
|
2016-06-06 00:37:26 +02:00
|
|
|
// validation is based on validation of every option fragment
|
|
|
|
// which validates according to poll model it belongs to
|
|
|
|
// therefore each option needs to be pushed to poll model to have it as
|
|
|
|
// it's owner
|
|
|
|
Ember.run(() => {
|
|
|
|
this.set('poll', this.store.createRecord('poll', {
|
|
|
|
isFindADate: true,
|
2016-06-08 13:55:00 +02:00
|
|
|
isMakeAPoll: false,
|
|
|
|
options: [
|
|
|
|
{ title: moment('2015-01-01T11:11').toISOString() },
|
|
|
|
{ title: moment('2015-01-01T22:22').toISOString() }
|
|
|
|
]
|
2016-06-06 00:37:26 +02:00
|
|
|
}));
|
|
|
|
});
|
2016-06-08 13:55:00 +02:00
|
|
|
this.render(hbs`{{create-options-datetime dates=poll.options}}`);
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2016-01-22 00:19:46 +01:00
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days input').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
2,
|
|
|
|
'there are two input fields before'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
this.$('.delete').get().every((el) => {
|
|
|
|
return el.disabled === false;
|
|
|
|
}),
|
|
|
|
'options are deleteable'
|
|
|
|
);
|
2016-06-06 00:37:26 +02:00
|
|
|
this.$('.days .form-group').eq(0).find('.delete').click();
|
2016-01-22 00:19:46 +01:00
|
|
|
Ember.run(() => {
|
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group input').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
1,
|
|
|
|
'one input field is removed after deletion'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group input').val(),
|
2016-01-22 00:19:46 +01:00
|
|
|
'22:22',
|
|
|
|
'correct input field is deleted'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-06-08 13:55:00 +02:00
|
|
|
this.get('poll.options.length'),
|
2016-01-22 00:19:46 +01:00
|
|
|
1,
|
|
|
|
'is also delete from option'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-06-08 13:55:00 +02:00
|
|
|
this.get('poll.options.firstObject.title'),
|
2016-01-22 00:19:46 +01:00
|
|
|
moment('2015-01-01T22:22').toISOString(),
|
|
|
|
'correct option is deleted'
|
|
|
|
);
|
|
|
|
});
|
2016-01-20 02:52:21 +01:00
|
|
|
});
|
2016-02-16 04:02:59 +01:00
|
|
|
|
|
|
|
test('adopt times of first day - simple', function(assert) {
|
2016-05-20 21:49:29 +02:00
|
|
|
// validation is based on validation of every option fragment
|
|
|
|
// which validates according to poll model it belongs to
|
|
|
|
// therefore each option needs to be pushed to poll model to have it as
|
|
|
|
// it's owner
|
|
|
|
Ember.run(() => {
|
2016-06-08 13:55:00 +02:00
|
|
|
this.set('poll', this.store.createRecord('poll', {
|
2016-05-20 21:49:29 +02:00
|
|
|
options: [
|
|
|
|
{ title: moment().hour(10).minute(0).toISOString() },
|
|
|
|
{ title: '2015-02-02' },
|
|
|
|
{ title: '2015-03-03' }
|
|
|
|
]
|
2016-06-08 13:55:00 +02:00
|
|
|
}));
|
2016-05-20 21:49:29 +02:00
|
|
|
});
|
2016-06-08 13:55:00 +02:00
|
|
|
this.render(hbs`{{create-options-datetime dates=poll.options}}`);
|
2016-02-16 04:02:59 +01:00
|
|
|
Ember.run(() => {
|
|
|
|
this.$('button.adopt-times-of-first-day').click();
|
|
|
|
});
|
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group').eq(0).find('input').val(),
|
2016-02-16 04:02:59 +01:00
|
|
|
'10:00',
|
|
|
|
'time was not changed for first day'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group').eq(1).find('input').val(),
|
2016-02-16 04:02:59 +01:00
|
|
|
'10:00',
|
|
|
|
'time was adopted for second day'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.days .form-group').eq(2).find('input').val(),
|
2016-02-16 04:02:59 +01:00
|
|
|
'10:00',
|
|
|
|
'time was adopted for third day'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('adopt times of first day - more times on first day than on others', function(assert) {
|
2016-05-20 21:49:29 +02:00
|
|
|
// validation is based on validation of every option fragment
|
|
|
|
// which validates according to poll model it belongs to
|
|
|
|
// therefore each option needs to be pushed to poll model to have it as
|
|
|
|
// it's owner
|
|
|
|
Ember.run(() => {
|
2016-06-08 13:55:00 +02:00
|
|
|
this.set('poll', this.store.createRecord('poll', {
|
2016-05-20 21:49:29 +02:00
|
|
|
options: [
|
|
|
|
{ title: moment().hour(10).minute(0).toISOString() },
|
|
|
|
{ title: moment().hour(22).minute(0).toISOString() },
|
|
|
|
{ title: '2015-02-02' },
|
|
|
|
{ title: '2015-03-03' }
|
|
|
|
]
|
2016-06-08 13:55:00 +02:00
|
|
|
}));
|
2016-05-20 21:49:29 +02:00
|
|
|
});
|
2016-06-08 13:55:00 +02:00
|
|
|
this.render(hbs`{{create-options-datetime dates=poll.options}}`);
|
2016-02-16 04:02:59 +01:00
|
|
|
Ember.run(() => {
|
|
|
|
this.$('button.adopt-times-of-first-day').click();
|
|
|
|
});
|
|
|
|
assert.deepEqual(
|
2017-07-29 15:00:11 +02:00
|
|
|
this.$('.days .form-group input').map((i, el) => jQuery(el).val()).toArray(),
|
2016-06-08 13:55:00 +02:00
|
|
|
['10:00', '22:00', '10:00', '22:00', '10:00', '22:00'],
|
|
|
|
'times were adopted correctly'
|
2016-02-16 04:02:59 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('adopt times of first day - excess times on other days got deleted', function(assert) {
|
2016-06-06 00:37:26 +02:00
|
|
|
// validation is based on validation of every option fragment
|
|
|
|
// which validates according to poll model it belongs to
|
|
|
|
// therefore each option needs to be pushed to poll model to have it as
|
|
|
|
// it's owner
|
|
|
|
Ember.run(() => {
|
|
|
|
this.set('poll', this.store.createRecord('poll', {
|
|
|
|
isFindADate: true,
|
2016-06-08 13:55:00 +02:00
|
|
|
isMakeAPoll: false,
|
|
|
|
options: [
|
|
|
|
{ title: moment().hour(10).minute(0).toISOString() },
|
|
|
|
{ title: moment().add(1, 'day').hour(10).minute(0).toISOString() },
|
|
|
|
{ title: moment().add(1, 'day').hour(22).minute(0).toISOString() }
|
|
|
|
]
|
2016-06-06 00:37:26 +02:00
|
|
|
}));
|
|
|
|
});
|
2016-06-08 13:55:00 +02:00
|
|
|
this.render(hbs`{{create-options-datetime dates=poll.options}}`);
|
2016-02-16 04:02:59 +01:00
|
|
|
Ember.run(() => {
|
|
|
|
this.$('button.adopt-times-of-first-day').click();
|
|
|
|
});
|
2016-06-08 13:55:00 +02:00
|
|
|
assert.equal(
|
|
|
|
this.$('.days .form-group').length,
|
|
|
|
2,
|
|
|
|
'one excess time input got deleted'
|
|
|
|
);
|
2016-02-16 04:02:59 +01:00
|
|
|
assert.deepEqual(
|
2017-07-29 15:00:11 +02:00
|
|
|
this.$('.days .form-group input').map((i, el) => jQuery(el).val()).toArray(),
|
2016-06-08 13:55:00 +02:00
|
|
|
['10:00', '10:00'],
|
2016-02-16 04:02:59 +01:00
|
|
|
'additional time on secondary day got deleted'
|
|
|
|
);
|
|
|
|
});
|
2016-06-06 00:37:26 +02:00
|
|
|
|
|
|
|
test('validation', function(assert) {
|
|
|
|
// validation is based on validation of every option fragment
|
|
|
|
// which validates according to poll model it belongs to
|
|
|
|
// therefore each option needs to be pushed to poll model to have it as
|
|
|
|
// it's owner
|
|
|
|
Ember.run(() => {
|
|
|
|
this.set('poll', this.store.createRecord('poll', {
|
|
|
|
isFindADate: true,
|
|
|
|
isMakeAPoll: false
|
|
|
|
}));
|
|
|
|
this.set('options', Ember.computed.alias('poll.options'));
|
|
|
|
this.get('options').pushObjects([
|
|
|
|
{ title: '2015-01-01' },
|
|
|
|
{ title: '2015-02-02' }
|
|
|
|
]);
|
|
|
|
});
|
2016-06-08 13:55:00 +02:00
|
|
|
this.render(hbs`{{create-options-datetime dates=options}}`);
|
2016-06-06 00:37:26 +02:00
|
|
|
assert.ok(
|
|
|
|
this.$('.has-error').length === 0,
|
|
|
|
'does not show a validation error before user interaction'
|
|
|
|
);
|
|
|
|
this.$('.form-group').eq(1).find('input').trigger('focusout');
|
|
|
|
assert.ok(
|
|
|
|
this.$('.form-group').eq(1).hasClass('has-success'),
|
|
|
|
'does show validation errors after user interaction'
|
|
|
|
);
|
|
|
|
this.$('.form-group').eq(1).find('input').val('10:').trigger('change');
|
|
|
|
assert.ok(
|
|
|
|
this.$('.form-group').eq(1).hasClass('has-error') ||
|
|
|
|
// browsers with input type time support prevent non time input
|
|
|
|
this.$('.form-group').eq(1).find('input').val() === '',
|
|
|
|
'shows error after invalid input or prevents invalid input'
|
|
|
|
);
|
|
|
|
// simulate unique violation
|
|
|
|
this.$('.form-group').eq(0).find('.add').click();
|
2016-06-10 11:27:09 +02:00
|
|
|
this.$('.form-group input').eq(0).val('10:00').trigger('change');
|
|
|
|
this.$('.form-group input').eq(1).val('10:00').trigger('change');
|
|
|
|
this.$('.form-group input').eq(2).val('10:00').trigger('change');
|
2016-06-06 00:37:26 +02:00
|
|
|
this.$('form').submit();
|
|
|
|
assert.ok(
|
|
|
|
this.$('.form-group').eq(0).hasClass('has-success'),
|
|
|
|
'first time shows validation success'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
this.$('.form-group').eq(1).hasClass('has-error'),
|
|
|
|
'same time for same day shows validation error'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
this.$('.form-group').eq(2).hasClass('has-success'),
|
|
|
|
'same time for different day shows validation success'
|
|
|
|
);
|
|
|
|
});
|