Skip to content

Commit 7646e01

Browse files
authored
Merge pull request #8185 from stopfstedt/5711_multiday_event_creation
prevent offering from being updated with invalid hour/minute input for end-date.
2 parents 5d0a228 + b128938 commit 7646e01

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

packages/ilios-common/addon/components/offering-form.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,11 @@ export default class OfferingForm extends Component {
525525
}
526526

527527
updateDurationHours = restartableTask(async (hours) => {
528+
// The corresponding input field passes an empty string if the input blank or invalid.
529+
// Here, we ignore invalid input and exit early.
530+
if ('' === hours) {
531+
return;
532+
}
528533
await timeout(DEBOUNCE_DELAY);
529534
this.addErrorDisplayFor('durationHours');
530535
this.addErrorDisplayFor('durationMinutes');
@@ -535,6 +540,11 @@ export default class OfferingForm extends Component {
535540
});
536541

537542
updateDurationMinutes = restartableTask(async (minutes) => {
543+
// The corresponding input field passes an empty string if the input blank or invalid.
544+
// Here, we ignore invalid input and exit early.
545+
if ('' === minutes) {
546+
return;
547+
}
538548
await timeout(DEBOUNCE_DELAY);
539549
this.addErrorDisplayFor('durationHours');
540550
this.addErrorDisplayFor('durationMinutes');

packages/test-app/tests/integration/components/offering-form-test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,56 @@ module('Integration | Component | offering form', function (hooks) {
470470
assert.ok(component.duration.minutes.hasError);
471471
});
472472

473+
test('blanking minutes or hours is ignored', async function (assert) {
474+
await render(hbs`<OfferingForm @close={{(noop)}} @save={{(noop)}} />`);
475+
476+
// Verify the initial end-date.
477+
assert.strictEqual(
478+
this.intl.formatDate(DateTime.fromObject({ hour: 9, minute: 0 }).toJSDate(), {
479+
month: '2-digit',
480+
day: '2-digit',
481+
year: 'numeric',
482+
hour: '2-digit',
483+
minute: '2-digit',
484+
}),
485+
component.endDate.value,
486+
);
487+
488+
// Change the duration, verify the calculated end-date.
489+
await component.duration.minutes.set('4');
490+
await component.duration.hours.set('9');
491+
const newEndDate = this.intl.formatDate(
492+
DateTime.fromObject({ hour: 17, minute: 4 }).toJSDate(),
493+
{
494+
month: '2-digit',
495+
day: '2-digit',
496+
year: 'numeric',
497+
hour: '2-digit',
498+
minute: '2-digit',
499+
},
500+
);
501+
assert.strictEqual(newEndDate, component.endDate.value);
502+
503+
// Provide blank input for the duration fields, verify that the end-date does not change again.
504+
await component.duration.minutes.set('');
505+
await component.duration.hours.set('');
506+
assert.strictEqual(newEndDate, component.endDate.value);
507+
508+
// Change the duration again, verify that the calculated end-date has changed and is correct.
509+
await component.duration.minutes.set('12');
510+
await component.duration.hours.set('2');
511+
assert.strictEqual(
512+
this.intl.formatDate(DateTime.fromObject({ hour: 10, minute: 12 }).toJSDate(), {
513+
month: '2-digit',
514+
day: '2-digit',
515+
year: 'numeric',
516+
hour: '2-digit',
517+
minute: '2-digit',
518+
}),
519+
component.endDate.value,
520+
);
521+
});
522+
473523
test('learner manager is not present in small-group mode', async function (assert) {
474524
await render(hbs`<OfferingForm @close={{(noop)}} @smallGroupMode={{true}} />`);
475525
assert.notOk(component.learnerManager.learnerSelectionManager.isPresent);

0 commit comments

Comments
 (0)