Skip to content

Commit 767de4b

Browse files
Prevent system-wide alert to be activated with empty message
1 parent 404ccd9 commit 767de4b

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/app/system-wide-alert/alert-form/system-wide-alert-form.component.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ describe('SystemWideAlertFormComponent', () => {
302302
expect(comp.back).not.toHaveBeenCalled();
303303

304304
});
305+
it('should not create the new alert when the enable button is clicked on an invalid the form', () => {
306+
spyOn(comp as any, 'handleResponse');
307+
308+
comp.formMessage.patchValue('');
309+
comp.save();
310+
311+
expect((comp as any).handleResponse).not.toHaveBeenCalled();
312+
});
305313
});
306314
describe('back', () => {
307315
it('should navigate back to the home page', () => {

src/app/system-wide-alert/alert-form/system-wide-alert-form.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,13 @@ export class SystemWideAlertFormComponent implements OnInit {
219219
} else {
220220
alert.countdownTo = null;
221221
}
222-
if (hasValue(this.currentAlert)) {
223-
const updatedAlert = Object.assign(new SystemWideAlert(), this.currentAlert, alert);
224-
this.handleResponse(this.systemWideAlertDataService.put(updatedAlert), 'system-wide-alert.form.update', navigateToHomePage);
225-
} else {
226-
this.handleResponse(this.systemWideAlertDataService.create(alert), 'system-wide-alert.form.create', navigateToHomePage);
222+
if (this.alertForm.valid) {
223+
if (hasValue(this.currentAlert)) {
224+
const updatedAlert = Object.assign(new SystemWideAlert(), this.currentAlert, alert);
225+
this.handleResponse(this.systemWideAlertDataService.put(updatedAlert), 'system-wide-alert.form.update', navigateToHomePage);
226+
} else {
227+
this.handleResponse(this.systemWideAlertDataService.create(alert), 'system-wide-alert.form.create', navigateToHomePage);
228+
}
227229
}
228230
}
229231

0 commit comments

Comments
 (0)