Prevent system-wide alert to be activated with empty message

(cherry picked from commit 767de4b5c8)
This commit is contained in:
Alexandre Vryghem
2024-03-23 15:12:48 +01:00
committed by github-actions[bot]
parent 4c693a1294
commit d05438dc3e
2 changed files with 15 additions and 5 deletions

View File

@@ -302,6 +302,14 @@ describe('SystemWideAlertFormComponent', () => {
expect(comp.back).not.toHaveBeenCalled(); 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', () => { describe('back', () => {
it('should navigate back to the home page', () => { it('should navigate back to the home page', () => {

View File

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