2016-01-20 02:52:21 +01:00
|
|
|
import { moduleForComponent, test } from 'ember-qunit';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
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) {
|
|
|
|
this.set('options', [
|
|
|
|
Ember.Object.create({ title: '2015-01-01' })
|
|
|
|
]);
|
2016-05-20 21:49:29 +02:00
|
|
|
this.render(hbs`{{create-options-datetime options=options}}`);
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2016-01-22 00:19:46 +01:00
|
|
|
assert.equal(
|
2016-02-16 02:26:27 +01:00
|
|
|
this.$('.grouped-input .form-group input:not(.ws-inputreplace)').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
1,
|
|
|
|
'there is one input field'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-02-16 02:26:27 +01:00
|
|
|
this.$('.grouped-input .form-group input:not(.ws-inputreplace)').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-01-22 00:19:46 +01:00
|
|
|
this.set('options', [
|
|
|
|
Ember.Object.create({ title: '2015-01-01T11:11:00.000Z' })
|
|
|
|
]);
|
2016-05-20 21:49:29 +02:00
|
|
|
this.render(hbs`{{create-options-datetime options=options}}`);
|
2016-01-22 00:19:46 +01:00
|
|
|
|
|
|
|
assert.equal(
|
2016-02-16 02:26:27 +01:00
|
|
|
this.$('.grouped-input .form-group input:not(.ws-inputreplace)').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
1,
|
|
|
|
'there is one input field'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-02-16 02:26:27 +01:00
|
|
|
this.$('.grouped-input .form-group input:not(.ws-inputreplace)').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'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it groups input fields per date', function(assert) {
|
|
|
|
this.set('options', [
|
|
|
|
Ember.Object.create({ title: moment('2015-01-01T10:11').toISOString() }),
|
|
|
|
Ember.Object.create({ title: moment('2015-01-01T22:22').toISOString() }),
|
|
|
|
Ember.Object.create({ title: '2015-02-02' })
|
|
|
|
]);
|
2016-05-20 21:49:29 +02:00
|
|
|
this.render(hbs`{{create-options-datetime options=options}}`);
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2016-01-22 00:19:46 +01:00
|
|
|
assert.equal(
|
|
|
|
this.$('.grouped-input').length,
|
|
|
|
2,
|
|
|
|
'there are two form groups for the two different dates'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-01-29 12:54:54 +01:00
|
|
|
this.$('.grouped-input').eq(0).find('input:not(.ws-inputreplace)').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
2,
|
|
|
|
'the first form group has two input fields for two different times'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-01-29 12:54:54 +01:00
|
|
|
this.$('.grouped-input').eq(0).find('input:not(.ws-inputreplace)').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
2,
|
|
|
|
'the first form group with two differnt times for one day has two input fields'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-01-29 12:54:54 +01:00
|
|
|
this.$('.grouped-input').eq(1).find('input:not(.ws-inputreplace)').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
1,
|
|
|
|
'the second form group without time has only one input field'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
let poll;
|
|
|
|
Ember.run(() => {
|
|
|
|
poll = this.store.createRecord('poll', {
|
|
|
|
options: [
|
|
|
|
{ title: '2015-01-01' },
|
|
|
|
{ title: '2015-02-02' }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.set('options', poll.get('options'));
|
|
|
|
this.render(hbs`{{create-options-datetime options=options}}`);
|
2016-01-22 00:19:46 +01:00
|
|
|
|
|
|
|
assert.equal(
|
2016-02-16 02:26:27 +01:00
|
|
|
this.$('.grouped-input .form-group input:not(.ws-inputreplace)').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
2,
|
|
|
|
'there are two input fields before'
|
|
|
|
);
|
|
|
|
this.$('.grouped-input').eq(0).find('.add').click();
|
|
|
|
assert.equal(
|
2016-02-16 02:26:27 +01:00
|
|
|
this.$('.grouped-input .form-group input:not(.ws-inputreplace)').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
3,
|
|
|
|
'another input field is added'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-01-29 12:54:54 +01:00
|
|
|
this.$('.grouped-input').eq(0).find('input:not(.ws-inputreplace)').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
2,
|
|
|
|
'it is added in correct date input'
|
|
|
|
);
|
|
|
|
});
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2016-01-22 00:19:46 +01:00
|
|
|
test('allows to delete an option', function(assert) {
|
|
|
|
this.set('options', [
|
|
|
|
Ember.Object.create({ title: moment('2015-01-01T11:11').toISOString() }),
|
|
|
|
Ember.Object.create({ title: moment('2015-01-01T22:22').toISOString() })
|
|
|
|
]);
|
2016-05-20 21:49:29 +02:00
|
|
|
this.render(hbs`{{create-options-datetime options=options}}`);
|
2016-01-20 02:52:21 +01:00
|
|
|
|
2016-01-22 00:19:46 +01:00
|
|
|
assert.equal(
|
2016-01-29 12:54:54 +01:00
|
|
|
this.$('.grouped-input input:not(.ws-inputreplace)').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-02-16 02:26:27 +01:00
|
|
|
this.$('.grouped-input .form-group').eq(0).find('.delete').click();
|
2016-01-22 00:19:46 +01:00
|
|
|
Ember.run(() => {
|
|
|
|
assert.equal(
|
2016-02-16 02:26:27 +01:00
|
|
|
this.$('.grouped-input .form-group input:not(.ws-inputreplace)').length,
|
2016-01-22 00:19:46 +01:00
|
|
|
1,
|
|
|
|
'one input field is removed after deletion'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2016-02-16 02:26:27 +01:00
|
|
|
this.$('.grouped-input .form-group input:not(.ws-inputreplace)').val(),
|
2016-01-22 00:19:46 +01:00
|
|
|
'22:22',
|
|
|
|
'correct input field is deleted'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
this.get('options.length'),
|
|
|
|
1,
|
|
|
|
'is also delete from option'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
this.get('options.firstObject.title'),
|
|
|
|
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
|
|
|
|
let poll;
|
|
|
|
Ember.run(() => {
|
|
|
|
poll = this.store.createRecord('poll', {
|
|
|
|
options: [
|
|
|
|
{ title: moment().hour(10).minute(0).toISOString() },
|
|
|
|
{ title: '2015-02-02' },
|
|
|
|
{ title: '2015-03-03' }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.set('options', poll.get('options'));
|
|
|
|
this.render(hbs`{{create-options-datetime options=options}}`);
|
2016-02-16 04:02:59 +01:00
|
|
|
Ember.run(() => {
|
|
|
|
this.$('button.adopt-times-of-first-day').click();
|
|
|
|
});
|
|
|
|
assert.equal(
|
|
|
|
this.$('.grouped-input:eq(0) input:not(.ws-inputreplace)').val(),
|
|
|
|
'10:00',
|
|
|
|
'time was not changed for first day'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
this.$('.grouped-input:eq(1) input:not(.ws-inputreplace)').val(),
|
|
|
|
'10:00',
|
|
|
|
'time was adopted for second day'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
this.$('.grouped-input:eq(1) input:not(.ws-inputreplace)').val(),
|
|
|
|
'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
|
|
|
|
let poll;
|
|
|
|
Ember.run(() => {
|
|
|
|
poll = this.store.createRecord('poll', {
|
|
|
|
options: [
|
|
|
|
{ title: moment().hour(10).minute(0).toISOString() },
|
|
|
|
{ title: moment().hour(22).minute(0).toISOString() },
|
|
|
|
{ title: '2015-02-02' },
|
|
|
|
{ title: '2015-03-03' }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.set('options', poll.get('options'));
|
|
|
|
this.render(hbs`{{create-options-datetime options=options}}`);
|
2016-02-16 04:02:59 +01:00
|
|
|
Ember.run(() => {
|
|
|
|
this.$('button.adopt-times-of-first-day').click();
|
|
|
|
});
|
|
|
|
assert.deepEqual(
|
|
|
|
this.$('.grouped-input:eq(0) input:not(.ws-inputreplace)').map((i, el) => $(el).val()).toArray(),
|
|
|
|
['10:00', '22:00'],
|
|
|
|
'time was not changed for first day after additionally time was added to first day'
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
2016-03-21 22:06:08 +01:00
|
|
|
this.$('.grouped-input:eq(1) input:not(.ws-inputreplace)').map((i, el) => $(el).val()).toArray(),
|
2016-02-16 04:02:59 +01:00
|
|
|
['10:00', '22:00'],
|
|
|
|
'time was adopted for second day after additionally time was added to first day'
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
2016-03-21 22:06:08 +01:00
|
|
|
this.$('.grouped-input:eq(2) input:not(.ws-inputreplace)').map((i, el) => $(el).val()).toArray(),
|
2016-02-16 04:02:59 +01:00
|
|
|
['10:00', '22:00'],
|
|
|
|
'time was adopted for third day after additionally time was added to first day'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('adopt times of first day - excess times on other days got deleted', function(assert) {
|
|
|
|
this.set('options', [
|
|
|
|
Ember.Object.create({ title: moment().hour(10).minute(0).toISOString() }),
|
|
|
|
Ember.Object.create({ title: moment().add(1, 'day').hour(10).minute(0).toISOString() }),
|
|
|
|
Ember.Object.create({ title: moment().add(1, 'day').hour(22).minute(0).toISOString() })
|
|
|
|
]);
|
2016-05-20 21:49:29 +02:00
|
|
|
this.render(hbs`{{create-options-datetime options=options}}`);
|
2016-02-16 04:02:59 +01:00
|
|
|
Ember.run(() => {
|
|
|
|
this.$('button.adopt-times-of-first-day').click();
|
|
|
|
});
|
|
|
|
assert.deepEqual(
|
|
|
|
this.$('.grouped-input:eq(1) input:not(.ws-inputreplace)').map((i, el) => $(el).val()).toArray(),
|
|
|
|
['10:00'],
|
|
|
|
'additional time on secondary day got deleted'
|
|
|
|
);
|
|
|
|
});
|