- {
let dateTimeService: DateTimeService;
const submissionStartDateField = 'submissionStartDate';
+ const submissionStartTimeField = 'submissionStartTime';
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
@@ -94,6 +95,41 @@ describe('SessionEditFormComponent', () => {
expect(configureSubmissionOpeningTimeSpy).not.toHaveBeenCalled();
});
+ it('should trigger the change of the model when the submission opening time '
+ + 'changes to before the visibility time', () => {
+ const date: DateFormat = { day: 12, month: 7, year: 2024 };
+ const time: TimeFormat = { hour: 4, minute: 0 };
+ const visibilityTime: TimeFormat = { hour: 14, minute: 0 };
+ const triggerModelChangeSpy = jest.spyOn(component, 'triggerModelChange');
+ const configureSessionVisibleDateTimeSpy = jest.spyOn(component, 'configureSessionVisibleDateTime');
+ component.model.customSessionVisibleDate = date;
+ component.model.submissionStartDate = date;
+ component.model.customSessionVisibleTime = visibilityTime;
+ component.triggerSubmissionOpeningTimeModelChange(submissionStartTimeField, time);
+ expect(triggerModelChangeSpy).toHaveBeenCalledWith(submissionStartTimeField, time);
+ expect(configureSessionVisibleDateTimeSpy).toHaveBeenCalledWith(date, time);
+ });
+
+ it('should adjust the session visibility date if submission opening date is earlier', () => {
+ const date: DateFormat = { day: 12, month: 7, year: 2024 };
+ const time: TimeFormat = { hour: 14, minute: 0 };
+ component.model.customSessionVisibleDate = { day: 13, month: 7, year: 2024 };
+ component.model.customSessionVisibleTime = time;
+ component.configureSessionVisibleDateTime(date, time);
+ expect(component.model.customSessionVisibleDate).toEqual(date);
+ expect(component.model.customSessionVisibleTime).toEqual(time);
+ });
+
+ it('should not adjust the session visibility date and time if submission opening date and time are later', () => {
+ const date: DateFormat = component.minDateForSubmissionStart;
+ const time: TimeFormat = component.minTimeForSubmissionStart;
+ component.model.customSessionVisibleDate = dateTimeService.getDateInstance(moment().subtract(1, 'days'));
+ component.model.customSessionVisibleTime = dateTimeService.getTimeInstance(moment().subtract(1, 'hours'));
+ component.configureSessionVisibleDateTime(date, time);
+ expect(component.model.customSessionVisibleDate).not.toEqual(date);
+ expect(component.model.customSessionVisibleTime).not.toEqual(time);
+ });
+
it('should emit a modelChange event with the updated field when triggerModelChange is called', () => {
const field = 'courseId';
const data = 'testId';
diff --git a/src/web/app/components/session-edit-form/session-edit-form.component.ts b/src/web/app/components/session-edit-form/session-edit-form.component.ts
index 700ed3e1a48..b6fc2791afb 100644
--- a/src/web/app/components/session-edit-form/session-edit-form.component.ts
+++ b/src/web/app/components/session-edit-form/session-edit-form.component.ts
@@ -128,12 +128,51 @@ export class SessionEditFormComponent {
* Triggers the change of the model for the form.
*/
triggerModelChange(field: string, data: any): void {
+ if (field === 'submissionStartDate' || field === 'submissionStartTime') {
+ this.adjustSessionVisibilityTime(data, field);
+ }
this.modelChange.emit({
...this.model,
[field]: data,
});
}
+ /**
+ * Adjusts session visibility time to ensure it does not occur after submission opening time.
+ */
+ adjustSessionVisibilityTime(value: any, field: string): void {
+ const submissionDateTime = this.combineDateAndTime(
+ field === 'submissionStartDate' ? value : this.model.submissionStartDate,
+ field === 'submissionStartTime' ? value : this.model.submissionStartTime,
+ );
+
+ const visibilityDateTime = this.combineDateAndTime(
+ this.model.customSessionVisibleDate,
+ this.model.customSessionVisibleTime,
+ );
+
+ if (submissionDateTime.isBefore(visibilityDateTime)) {
+ if (field === 'submissionStartDate') {
+ this.model.customSessionVisibleDate = value;
+ } else {
+ this.model.customSessionVisibleTime = value;
+ }
+ }
+ }
+
+ /**
+ * Combines date and time into a single moment instance.
+ */
+ combineDateAndTime(date: DateFormat, time: TimeFormat): moment.Moment {
+ return moment.tz({
+ year: date.year,
+ month: date.month - 1,
+ day: date.day,
+ hour: time.hour,
+ minute: time.minute,
+ }, this.model.timeZone);
+ }
+
/**
* Triggers the change of the model when the submission opening date changes.
*/
@@ -148,6 +187,7 @@ export class SessionEditFormComponent {
this.model.submissionStartTime = minTime;
}
+ this.adjustSessionVisibilityTime(date, field);
this.triggerModelChange(field, date);
}
@@ -164,6 +204,37 @@ export class SessionEditFormComponent {
}
}
+ /**
+ * Triggers the change of the model when the submission opening time changes.
+ */
+ triggerSubmissionOpeningTimeModelChange(field: string, time: TimeFormat): void {
+ const date: DateFormat = this.model.submissionStartDate;
+ const sessionDate: DateFormat = this.model.customSessionVisibleDate;
+ const sessionTime: TimeFormat = this.model.customSessionVisibleTime;
+
+ if (DateTimeService.compareDateFormat(date, sessionDate) === 0
+ && DateTimeService.compareTimeFormat(time, sessionTime) === -1) {
+ this.configureSessionVisibleDateTime(date, time);
+ }
+
+ this.triggerModelChange(field, time);
+ }
+
+ /**
+ * Configures the session visible date and time to ensure it is not after submission opening time.
+ */
+ configureSessionVisibleDateTime(date: DateFormat, time: TimeFormat): void {
+ const sessionDate: DateFormat = this.model.customSessionVisibleDate;
+ const sessionTime: TimeFormat = this.model.customSessionVisibleTime;
+
+ if (DateTimeService.compareDateFormat(date, sessionDate) === -1) {
+ this.model.customSessionVisibleDate = date;
+ } else if (DateTimeService.compareDateFormat(date, sessionDate) === 0
+ && DateTimeService.compareTimeFormat(time, sessionTime) === -1) {
+ this.model.customSessionVisibleTime = time;
+ }
+ }
+
/**
* Handles course Id change event.
*
diff --git a/src/web/app/pages-session/session-submission-page/__snapshots__/session-submission-page.component.spec.ts.snap b/src/web/app/pages-session/session-submission-page/__snapshots__/session-submission-page.component.spec.ts.snap
index 5110ed14b92..d0f974f68b8 100644
--- a/src/web/app/pages-session/session-submission-page/__snapshots__/session-submission-page.component.spec.ts.snap
+++ b/src/web/app/pages-session/session-submission-page/__snapshots__/session-submission-page.component.spec.ts.snap
@@ -2,11 +2,13 @@
exports[`SessionSubmissionPageComponent should snap when feedback session questions have failed to load 1`] = `
+
@@ -1547,6 +1571,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 3
+
@@ -1980,6 +2012,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 4
+
@@ -2195,6 +2235,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 5
+
@@ -2424,6 +2472,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 6
+
@@ -2883,6 +2939,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 7
+
@@ -3227,6 +3291,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 8
+
@@ -3509,6 +3581,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 9
+
@@ -3741,6 +3821,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 10
+
@@ -3770,11 +3858,13 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
exports[`SessionSubmissionPageComponent should snap with feedback session question submission forms when disabled 1`] = `
+
@@ -4563,6 +4662,13 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 3
+
@@ -5002,6 +5108,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 4
+
@@ -5219,6 +5333,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 5
+
@@ -5450,6 +5572,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 6
+
@@ -5911,6 +6041,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 7
+
@@ -6265,6 +6403,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 8
+
@@ -6549,6 +6695,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 9
+
@@ -6782,6 +6936,14 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
Submit Response for Question 10
+
@@ -6812,11 +6974,13 @@ exports[`SessionSubmissionPageComponent should snap with feedback session questi
exports[`SessionSubmissionPageComponent should snap with user that is logged in and using session link 1`] = `
{{ getRecipientName(entry.key) }}