Skip to content

Commit

Permalink
Default to zero when a user does not enter a number
Browse files Browse the repository at this point in the history
Signed-off-by: seajamied <[email protected]>
  • Loading branch information
seajamied committed Mar 19, 2020
1 parent 5e23ef2 commit 152890d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { HttpClientTestingModule } from '@angular/common/http/testing';
import { FormGroup, FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
// import { MatOptionModule } from '@angular/material;
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { ngrxReducers, runtimeChecks } from 'app/ngrx.reducers';
Expand Down Expand Up @@ -50,7 +49,6 @@ describe('AutomateSettingsComponent', () => {
ReactiveFormsModule,
MatFormFieldModule,
MatSelectModule,
// MatOptionModule,
BrowserAnimationsModule,
HttpClientTestingModule,
StoreModule.forRoot(ngrxReducers, { runtimeChecks })
Expand Down Expand Up @@ -243,7 +241,7 @@ describe('AutomateSettingsComponent', () => {
], function(formName: string, disabledStatus: boolean, threshold: number | string) {
it(`when form nested, it updates the ${formName} form group correctly`, () => {
component.updateForm(mockJobSchedulerStatus);
fixture.detectChanges();
// fixture.detectChanges();

const newFormValues = component[formName].value;

Expand All @@ -256,6 +254,7 @@ describe('AutomateSettingsComponent', () => {
it('saves settings', () => {
component.updateForm(mockJobSchedulerStatus);
component.applyChanges();

expect(component.formChanged).toEqual(false);
expect(component.notificationType).toEqual('info');
expect(component.notificationMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
IngestJobs
} from '../../entities/automate-settings/automate-settings.model';
import { TelemetryService } from '../../services/telemetry/telemetry.service';
import { JobProfilesFormComponent } from 'app/page-components/job-profiles-form/job-profiles-form.component';

@Component({
templateUrl: './automate-settings.component.html',
Expand Down Expand Up @@ -220,7 +221,6 @@ export class AutomateSettingsComponent implements OnInit, OnDestroy {
}
}


public toggleInput(form, checked: boolean) {
// patchValue is a workaround for the chef-checkbox because we need to be
// able to store a reference to it being checked or not
Expand All @@ -234,7 +234,7 @@ export class AutomateSettingsComponent implements OnInit, OnDestroy {
if ( checked ) {
form.get(control).enable();
} else {
form.get(control).disable();
form.get(control).disable();
}
});
}
Expand Down Expand Up @@ -264,13 +264,14 @@ export class AutomateSettingsComponent implements OnInit, OnDestroy {
job.category = jobForm.category;
job.name = jobForm.name;
job.disabled = jobForm.disabled;
job.threshold = jobForm.threshold + jobForm.unit;

// If the user doesn't enter any number at all - this defaults to 0
job.threshold = jobForm.threshold === null
? '0' + jobForm.unit : jobForm.threshold + jobForm.unit;
if ( isNested ) {
job.nested_name = jobForm.nested_name;
job.threshold = jobForm.threshold;
job.threshold = job.threshold;
}
// If the user doesn't enter any number at all - this defaults to 0
job.threshold = job.threshold === null ? '0' : job.threshold;

return job;
});
Expand Down

0 comments on commit 152890d

Please sign in to comment.