Skip to content

Commit

Permalink
Merge branch 'master' into FIX/12664/accessibility-comment-button
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoHW committed Jul 29, 2024
2 parents beedc96 + 9181467 commit eb61739
Show file tree
Hide file tree
Showing 8 changed files with 481 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import SpyInstance = jest.SpyInstance;
import { PerQuestionViewResponsesComponent } from './per-question-view-responses.component';
import { FeedbackResponsesService } from '../../../../services/feedback-responses.service';
import testEventEmission from '../../../../test-helpers/test-event-emitter';
import {
CommentVisibilityType, FeedbackParticipantType, FeedbackQuestionType,
NumberOfEntitiesToGiveFeedbackToSetting,
Expand Down Expand Up @@ -143,4 +144,52 @@ describe('PerQuestionViewResponsesComponent', () => {
expect(JSON.stringify(component.responsesToShow[0]))
.toBe(JSON.stringify(responseOutput));
});

it('triggerDeleteCommentEvent: should emit correct responseID and index to deleteCommentEvent', () => {
let emittedID: string | undefined;
let emittedIndex: number | undefined;
testEventEmission(component.deleteCommentEvent, (val) => { emittedID = val.responseId; emittedIndex = val.index; });

component.triggerDeleteCommentEvent('testID', 5);
expect(emittedID).toBe('testID');
expect(emittedIndex).toBe(5);
});

it('triggerUpdateCommentEvent: should emit correct responseID and index to updateCommentEvent', () => {
let emittedID: string | undefined;
let emittedIndex: number | undefined;
testEventEmission(component.updateCommentEvent, (val) => { emittedID = val.responseId; emittedIndex = val.index; });

component.triggerUpdateCommentEvent('testID2', 6);
expect(emittedID).toBe('testID2');
expect(emittedIndex).toBe(6);
});

it('triggerSaveNewCommentEvent: should emit correct responseID to saveNewCommentEvent', () => {
let emittedID: string | undefined;
testEventEmission(component.saveNewCommentEvent, (responseId) => { emittedID = responseId; });

component.triggerSaveNewCommentEvent('testID3');
expect(emittedID).toBe('testID3');
});

it('triggerModelChangeForSingleResponse: should emit correct Record to instructorCommentTableModelChange', () => {
let emittedRecord: Record<string, CommentTableModel> | undefined;
testEventEmission(component.instructorCommentTableModelChange, (record) => { emittedRecord = record; });

const testRecord: Record<string, CommentTableModel> = { responseId: commentTableModel };

component.triggerModelChangeForSingleResponse('responseId', commentTableModel);
expect(emittedRecord).toEqual(testRecord);
});

it('triggerModelChange: should emit correct instructorCommentTableModel Record to triggerModelChange', () => {
let emittedRecord: Record<string, CommentTableModel> | undefined;
testEventEmission(component.instructorCommentTableModelChange, (record) => { emittedRecord = record; });

const testRecord: Record<string, CommentTableModel> = {};

component.triggerModelChange(testRecord);
expect(emittedRecord).toEqual(testRecord);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ <h2 class="question-details"><b>Question {{ model.questionNumber }}: </b>{{ mode
<tm-ajax-loading *ngIf="isSavingResponses"></tm-ajax-loading>
<span>{{ isQuestionCountOne ? "Submit Response" : "Submit Response for Question " + model.questionNumber }}</span>
</button>
<button type="button" class="btn btn-warning float-end" (click)="resetForm(); resetTooltip.close();" ngbTooltip="Reset your responses for this question to the last submitted state."
#resetTooltip="ngbTooltip" (mouseenter)="resetTooltip.open()" [disabled]="!hasResponseChanged">{{ "Reset Question " + model.questionNumber }}</button>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class QuestionSubmissionFormComponent implements DoCheck {

this.model.isTabExpandedForRecipients.set(recipient.recipientIdentifier, true);
});
this.hasResponseChanged = Array.from(this.model.hasResponseChangedForRecipients.values()).some((value) => value);
}

@Input()
Expand All @@ -118,6 +119,12 @@ export class QuestionSubmissionFormComponent implements DoCheck {
@Output()
responsesSave: EventEmitter<QuestionSubmissionFormModel> = new EventEmitter();

@Output()
autoSave: EventEmitter<{ id: string, model: QuestionSubmissionFormModel }> = new EventEmitter();

@Output()
resetFeedback: EventEmitter<QuestionSubmissionFormModel> = new EventEmitter<QuestionSubmissionFormModel>();

@ViewChild(ContributionQuestionConstraintComponent)
private contributionQuestionConstraint!: ContributionQuestionConstraintComponent;

Expand Down Expand Up @@ -168,6 +175,8 @@ export class QuestionSubmissionFormComponent implements DoCheck {
visibilityStateMachine: VisibilityStateMachine;
isEveryRecipientSorted: boolean = false;

autosaveTimeout: any;

constructor(private feedbackQuestionsService: FeedbackQuestionsService,
private feedbackResponseService: FeedbackResponsesService) {
this.visibilityStateMachine =
Expand Down Expand Up @@ -221,6 +230,13 @@ export class QuestionSubmissionFormComponent implements DoCheck {
});
}

resetForm(): void {
this.resetFeedback.emit(this.model);
this.isSaved = true;
this.hasResponseChanged = false;
clearTimeout(this.autosaveTimeout);
}

toggleQuestionTab(): void {
if (this.currentSelectedSessionView === this.allSessionViews.DEFAULT) {
this.model.isTabExpanded = !this.model.isTabExpanded;
Expand Down Expand Up @@ -350,7 +366,6 @@ export class QuestionSubmissionFormComponent implements DoCheck {
*/
triggerRecipientSubmissionFormChange(index: number, field: string, data: any): void {
if (!this.isFormsDisabled) {
this.hasResponseChanged = true;
this.isSubmitAllClickedChange.emit(false);
this.model.hasResponseChangedForRecipients.set(this.model.recipientList[index].recipientIdentifier, true);

Expand All @@ -362,6 +377,12 @@ export class QuestionSubmissionFormComponent implements DoCheck {

this.updateIsValidByQuestionConstraint();
this.formModelChange.emit(this.model);

this.autoSave.emit({ id: this.model.feedbackQuestionId, model: this.model });
clearTimeout(this.autosaveTimeout);
this.autosaveTimeout = setTimeout(() => {
this.hasResponseChanged = true;
}, 100); // 0.1 second to prevent people from trying to immediately reset before autosave kicks in
}
}

Expand Down Expand Up @@ -451,6 +472,7 @@ export class QuestionSubmissionFormComponent implements DoCheck {
* Triggers saving of responses for the specific question.
*/
saveFeedbackResponses(): void {
clearTimeout(this.autosaveTimeout);
this.isSaved = true;
this.hasResponseChanged = false;
this.model.hasResponseChangedForRecipients.forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ describe('SessionEditFormComponent', () => {
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.model.customSessionVisibleDate = dateTimeService
.getDateInstance(moment().tz(component.model.timeZone).subtract(1, 'days'));
component.model.customSessionVisibleTime = dateTimeService
.getTimeInstance(moment().tz(component.model.timeZone).subtract(1, 'hours'));
component.configureSessionVisibleDateTime(date, time);
expect(component.model.customSessionVisibleDate).not.toEqual(date);
expect(component.model.customSessionVisibleTime).not.toEqual(time);
Expand Down
Loading

0 comments on commit eb61739

Please sign in to comment.