Skip to content

Commit

Permalink
12679[Name for copied session should not be whitespace]
Browse files Browse the repository at this point in the history
  • Loading branch information
ArunErram committed Apr 21, 2024
1 parent 735afbd commit 03bf2e1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ exports[`CopySessionModalComponent should snap with some session and courses can
/>
<div
class="invalid-field"
hidden=""
>
<i
aria-hidden="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ <h5 class="modal-title">
<label><b>Name for copied session*</b></label>
<input id="copy-session-name" type="text" class="form-control" [(ngModel)]="newFeedbackSessionName" [maxlength]="FEEDBACK_SESSION_NAME_MAX_LENGTH"
required #newSessionName="ngModel">
<div [hidden]="newSessionName.valid || (newSessionName.pristine && newSessionName.untouched)" class="invalid-field">
<div [hidden]="validatenewFeedbackSessionName(newSessionName.value)" class="invalid-field">
<i class="fa fa-exclamation-circle" aria-hidden="true"></i>
The field "Name for copied session" should not be empty.
</div>
</div>

<span>{{ FEEDBACK_SESSION_NAME_MAX_LENGTH - newFeedbackSessionName.length }} characters left</span>
</div>
<div class="form-check" *ngFor="let course of courseCandidates">
Expand All @@ -35,5 +36,5 @@ <h5 class="modal-title">
<div class="modal-footer">
<button type="button" class="btn btn-light" (click)="activeModal.dismiss()">Cancel</button>
<button id="btn-confirm-copy-course" type="button" class="btn btn-primary" (click)="copy()"
[disabled]="!newFeedbackSessionName || copyToCourseSet.size < 1">Copy</button>
[disabled]="!newFeedbackSessionName || copyToCourseSet.size < 1 || !validatenewFeedbackSessionName(newSessionName.value)">Copy</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('CopySessionModalComponent', () => {
fixture.detectChanges();

const copyButton: any = fixture.debugElement.query(By.css('button.btn.btn-primary'));
expect(copyButton.nativeElement.disabled).toBeFalsy();
expect(copyButton.nativeElement.disabled).toBeTruthy();
});

it('should close the modal with the correct data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export class CopySessionModalComponent {
* Fires the copy event.
*/
copy(): void {
this.activeModal.close({
newFeedbackSessionName: this.newFeedbackSessionName,
sessionToCopyCourseId: this.sessionToCopyCourseId,
copyToCourseList: Array.from(this.copyToCourseSet),
});
if(this.validatenewFeedbackSessionName(this.newFeedbackSessionName)){
this.activeModal.close({
newFeedbackSessionName: this.newFeedbackSessionName,
sessionToCopyCourseId: this.sessionToCopyCourseId,
copyToCourseList: Array.from(this.copyToCourseSet),
});
}
}

/**
Expand All @@ -48,4 +50,19 @@ export class CopySessionModalComponent {
this.copyToCourseSet.add(courseId);
}
}
/**
* validation of newFeedbackSessionName for a course to copy to in set.
*/
validatenewFeedbackSessionName(newFeedbackSessionName: string): boolean {
if (newFeedbackSessionName !== null) { // Add a null check
const regex_pattern = /^(?!\s*$).+/;
if (regex_pattern.test(newFeedbackSessionName)) {
return true;
} else {
return false;
}
} else {
return true; // If newFeedbackSessionName is null, consider it invalid
}
}
}

0 comments on commit 03bf2e1

Please sign in to comment.