Skip to content

Commit f3426b2

Browse files
committedApr 15, 2016
support creating polls with only one option
There might be use cases and it simplifies validation a lot. Also fixes this missing translation message mentioned in #84: > /create/options-datetime: There isn't any validation error shown when validation fails due to not enough times.
1 parent 1954625 commit f3426b2

File tree

6 files changed

+258
-15
lines changed

6 files changed

+258
-15
lines changed
 

‎app/components/create-options-datetime.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let Validations = buildValidations({
1111
validator('collection', true),
1212
validator('length', {
1313
dependentKeys: ['options.[]'],
14-
min: 2
14+
min: 1
1515
// message: Ember.I18n.t('create.options.error.notEnoughOptions')
1616
}),
1717
validator('unique-collection', {

‎app/components/create-options.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ let Validations = buildValidations({
99
validator('collection', true),
1010
validator('length', {
1111
dependentKeys: ['options.[]'],
12-
min() {
13-
if (this.model.get('isFindADate') && this.model.get('isDateTime')) {
14-
return 1;
15-
} else {
16-
return 2;
17-
}
18-
}
12+
min: 1
1913
// message: Ember.I18n.t('create.options.error.notEnoughOptions')
2014
}),
2115
validator('unique-collection', {

‎app/routes/create/settings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default Ember.Route.extend({
1616
});
1717
}
1818
// check if less then two options are defined
19-
else if (create.get('options.length') < 2) {
19+
else if (create.get('options.length') < 1) {
2020
this.transitionTo('create.options');
2121
}
2222
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{fm-input-group
22
content=options
33
label=(t 'create.options.options.label')
4-
minimumInputFields=2
4+
minimumInputFields=1
55
addElement='addOption'
66
deleteElement='deleteOption'
77
}}

‎tests/acceptance/create-a-poll-test.js

+235
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,241 @@ test('create a poll with only one day and multiple times', function(assert) {
426426
});
427427
});
428428

429+
test('create a poll with only one day (without time)', function(assert) {
430+
let day = moment().add(1, 'day');
431+
const dayFormat = moment.localeData().longDateFormat('LLLL')
432+
.replace(
433+
moment.localeData().longDateFormat('LT'), '')
434+
.trim();
435+
436+
pageCreateIndex
437+
.visit();
438+
439+
andThen(function() {
440+
pageCreateIndex
441+
.next();
442+
443+
andThen(function() {
444+
assert.equal(currentPath(), 'create.meta');
445+
446+
pageCreateMeta
447+
.title('default poll')
448+
.description('a sample description')
449+
.next();
450+
451+
andThen(function() {
452+
assert.equal(currentPath(), 'create.options');
453+
454+
pageCreateOptions
455+
.dateOptions([ day ]);
456+
pageCreateOptions
457+
.next();
458+
459+
andThen(function() {
460+
assert.equal(currentPath(), 'create.options-datetime');
461+
462+
assert.deepEqual(
463+
pageCreateOptionsDatetime.days().labels,
464+
[ day.format(dayFormat) ],
465+
'time inputs having days as label'
466+
);
467+
468+
pageCreateOptionsDatetime
469+
.next();
470+
andThen(function() {
471+
assert.equal(currentPath(), 'create.settings');
472+
473+
pageCreateSettings
474+
.next();
475+
476+
andThen(function() {
477+
assert.equal(currentPath(), 'poll.participation');
478+
assert.ok(
479+
pagePollParticipation.urlIsValid() === true,
480+
'poll url is valid'
481+
);
482+
assert.equal(
483+
pagePollParticipation.title,
484+
'default poll',
485+
'poll title is correct'
486+
);
487+
assert.equal(
488+
pagePollParticipation.description,
489+
'a sample description',
490+
'poll description is correct'
491+
);
492+
assert.deepEqual(
493+
pagePollParticipation.options().labels,
494+
[
495+
day.format(dayFormat)
496+
],
497+
'options are correctly labeled'
498+
);
499+
});
500+
});
501+
});
502+
});
503+
});
504+
});
505+
});
506+
507+
test('create a poll with only one day (with time)', function(assert) {
508+
let day = moment().add(1, 'day');
509+
const dayFormat = moment.localeData().longDateFormat('LLLL')
510+
.replace(
511+
moment.localeData().longDateFormat('LT'), '')
512+
.trim();
513+
514+
pageCreateIndex
515+
.visit();
516+
517+
andThen(function() {
518+
pageCreateIndex
519+
.next();
520+
521+
andThen(function() {
522+
assert.equal(currentPath(), 'create.meta');
523+
524+
pageCreateMeta
525+
.title('default poll')
526+
.description('a sample description')
527+
.next();
528+
529+
andThen(function() {
530+
assert.equal(currentPath(), 'create.options');
531+
532+
pageCreateOptions
533+
.dateOptions([ day ]);
534+
pageCreateOptions
535+
.next();
536+
537+
andThen(function() {
538+
assert.equal(currentPath(), 'create.options-datetime');
539+
540+
assert.deepEqual(
541+
pageCreateOptionsDatetime.days().labels,
542+
[ day.format(dayFormat) ],
543+
'time inputs having days as label'
544+
);
545+
546+
pageCreateOptionsDatetime
547+
.days(0).times(0).time('22:30');
548+
pageCreateOptionsDatetime
549+
.next();
550+
551+
andThen(function() {
552+
assert.equal(currentPath(), 'create.settings');
553+
554+
pageCreateSettings
555+
.next();
556+
557+
andThen(function() {
558+
assert.equal(currentPath(), 'poll.participation');
559+
assert.ok(
560+
pagePollParticipation.urlIsValid() === true,
561+
'poll url is valid'
562+
);
563+
assert.equal(
564+
pagePollParticipation.title,
565+
'default poll',
566+
'poll title is correct'
567+
);
568+
assert.equal(
569+
pagePollParticipation.description,
570+
'a sample description',
571+
'poll description is correct'
572+
);
573+
assert.deepEqual(
574+
pagePollParticipation.options().labels,
575+
[
576+
day.hour(22).minute(30).format('LLLL')
577+
],
578+
'options are correctly labeled'
579+
);
580+
});
581+
});
582+
});
583+
});
584+
});
585+
});
586+
});
587+
588+
test('create a poll for answering a question with only one option', function(assert) {
589+
pageCreateIndex
590+
.visit();
591+
592+
andThen(function() {
593+
pageCreateIndex
594+
.pollType('MakeAPoll')
595+
.next();
596+
597+
andThen(function() {
598+
assert.equal(currentPath(), 'create.meta');
599+
600+
pageCreateMeta
601+
.title('default poll')
602+
.next();
603+
604+
andThen(function() {
605+
assert.equal(currentPath(), 'create.options');
606+
expectComponent('create-options-text');
607+
608+
assert.equal(
609+
pageCreateOptions.textOptions().count,
610+
2,
611+
'there are two input fields as default'
612+
);
613+
614+
pageCreateOptions
615+
.textOptions(0).title('option a');
616+
pageCreateOptions
617+
.textOptions(1).delete();
618+
619+
andThen(function() {
620+
assert.equal(
621+
pageCreateOptions.textOptions().count,
622+
1,
623+
'option was deleted'
624+
);
625+
626+
pageCreateOptions
627+
.next();
628+
629+
andThen(function() {
630+
assert.equal(currentPath(), 'create.settings');
631+
632+
pageCreateSettings
633+
.next();
634+
635+
andThen(function() {
636+
assert.equal(currentPath(), 'poll.participation');
637+
assert.ok(
638+
pagePollParticipation.urlIsValid() === true,
639+
'poll url is valid'
640+
);
641+
assert.equal(
642+
pagePollParticipation.title,
643+
'default poll',
644+
'poll title is correct'
645+
);
646+
assert.equal(
647+
pagePollParticipation.description,
648+
'',
649+
'poll description is correct'
650+
);
651+
assert.deepEqual(
652+
pagePollParticipation.options().labels,
653+
['option a'],
654+
'options are labeled correctly'
655+
);
656+
});
657+
});
658+
});
659+
});
660+
});
661+
});
662+
});
663+
429664
test('create a poll and using back button (find a date)', function(assert) {
430665
let days = [
431666
moment().add(1, 'day'),

‎tests/unit/components/create-options-test.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { moduleForComponent, test } from 'ember-qunit';
22
import Ember from 'ember';
3+
import moment from 'moment';
34

45
moduleForComponent('create-options', 'Unit | Component | create options', {
56
needs: [
@@ -50,9 +51,9 @@ test('validation for make a poll', function(assert) {
5051
poll.get('options').pushObject(option);
5152
component.get('options').pushObject(option);
5253
});
53-
assert.notOk(
54+
assert.ok(
5455
component.get('validations.isValid'),
55-
'invalid for only one option'
56+
'valid if there is atleast one valid option'
5657
);
5758
Ember.run(() => {
5859
let option = this.store.createFragment('option', {
@@ -105,9 +106,9 @@ test('validation for find a date without times', function(assert) {
105106
poll.get('options').pushObject(option);
106107
component.get('options').pushObject(option);
107108
});
108-
assert.notOk(
109+
assert.ok(
109110
component.get('validations.isValid'),
110-
'invalid if there is only one valid date'
111+
'valid if there is atleast one valid date'
111112
);
112113
Ember.run(() => {
113114
let option = this.store.createFragment('option', {
@@ -173,7 +174,7 @@ test('validation for find a date with times', function(assert) {
173174
);
174175
Ember.run(() => {
175176
let option = this.store.createFragment('option', {
176-
title: '2015-01-01'
177+
title: moment().add('1', 'day').format('YYYY-MM-DD')
177178
});
178179
poll.get('options').pushObject(option);
179180
component.get('options').pushObject(option);
@@ -182,4 +183,17 @@ test('validation for find a date with times', function(assert) {
182183
component.get('validations.isValid'),
183184
'valid if there is atleast one valid date'
184185
);
186+
/*
187+
Ember.run(() => {
188+
let option = this.store.createFragment('option', {
189+
title: moment().add('1', 'day').hour(22).minute(30).seconds(0).milliseconds(0).toISOString()
190+
});
191+
poll.get('options').pushObject(option);
192+
component.get('options').pushObject(option);
193+
});
194+
assert.notOk(
195+
component.get('validations.isValid'),
196+
'invalid if there is a option without time for a day with has another option with time specified'
197+
);
198+
*/
185199
});

0 commit comments

Comments
 (0)