Merge pull request #2879 from DSpace/backport-2877-to-dspace-7_x

[Port dspace-7_x] System-wide alert shouldn't be created when the message is empty
This commit is contained in:
Alan Orth
2024-03-26 11:26:31 +03:00
committed by GitHub
2 changed files with 15 additions and 5 deletions

View File

@@ -302,6 +302,14 @@ describe('SystemWideAlertFormComponent', () => {
expect(comp.back).not.toHaveBeenCalled();
});
it('should not create the new alert when the enable button is clicked on an invalid the form', () => {
spyOn(comp as any, 'handleResponse');
comp.formMessage.patchValue('');
comp.save();
expect((comp as any).handleResponse).not.toHaveBeenCalled();
});
});
describe('back', () => {
it('should navigate back to the home page', () => {

View File

@@ -219,11 +219,13 @@ export class SystemWideAlertFormComponent implements OnInit {
} else {
alert.countdownTo = null;
}
if (hasValue(this.currentAlert)) {
const updatedAlert = Object.assign(new SystemWideAlert(), this.currentAlert, alert);
this.handleResponse(this.systemWideAlertDataService.put(updatedAlert), 'system-wide-alert.form.update', navigateToHomePage);
} else {
this.handleResponse(this.systemWideAlertDataService.create(alert), 'system-wide-alert.form.create', navigateToHomePage);
if (this.alertForm.valid) {
if (hasValue(this.currentAlert)) {
const updatedAlert = Object.assign(new SystemWideAlert(), this.currentAlert, alert);
this.handleResponse(this.systemWideAlertDataService.put(updatedAlert), 'system-wide-alert.form.update', navigateToHomePage);
} else {
this.handleResponse(this.systemWideAlertDataService.create(alert), 'system-wide-alert.form.create', navigateToHomePage);
}
}
}