Skip to content

Feature/ncj validation#644

Merged
t-anjam merged 11 commits intoncjfrom
feature/ncj-validation
Sep 6, 2017
Merged

Feature/ncj validation#644
t-anjam merged 11 commits intoncjfrom
feature/ncj-validation

Conversation

@t-anjam
Copy link

@t-anjam t-anjam commented Aug 29, 2017

Added validation to the NCJ form. Able to validate for required, minValue, maxValue, minLength, and maxLength. Run button only turns on when form is valid. Also added tool tip to run button. Added unit tests.

image
image

@msftclas
Copy link

@t-anjam,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

return {
validJsonConfig: {
valid: false,
message: "FormControl is invalid",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the message here to contain what the error is(Look into the parameterValue.errors)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const valid = this.parameterValue.valid;
if (valid) { return null; }
return {
validJsonConfig: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also change this key

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

public isFormValid() {
return (this.modeState === Modes.NewPoolAndJob && this.jobParams.valid && this.poolParams.valid) ||
Copy link
Member

@timotheeguerin timotheeguerin Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should just be able to have this.form.valid instead of this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different mode will have different conditions for submit

for (let key of templateParameters) {
if (template.parameters[key].defaultValue) {
const defaultValue = String(template.parameters[key].defaultValue);
templateFormGroup[key] = new FormControl(defaultValue, Validators.required );
Copy link
Member

@timotheeguerin timotheeguerin Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't create the control twice here, do just set the default value to null if needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

<div [title]="getToolTip()" class="submit-box" *ngIf="modeState !== Modes.None">
<bl-server-error [error]="error"> </bl-server-error>
<bl-button [action]="submit" type="wide" class="submit-job" color="success">
<bl-button [disabled]="!isFormValid()" [action]="submit" type="wide" class="submit-job" color="success">
Copy link
Member

@timotheeguerin timotheeguerin Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make the tooltip here instead of being on the outer div. also make it a getter public get submitTooltip() instead of a function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


it("should validate minimum value constraint", () => {
const input = 5;
testComponent.param = new NcjParameterWrapper("frameEnd", {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for those test add the param restriction in the beforeEach() so you have less duplicate and just include both restriction at the same time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

expect(inputEl.nativeElement.value).toBe(updatedInput);
});

it("should validate minimum length constraint", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also check for the error message

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

} else {
let messageText = "unknown error";
if (this.parameterValue.errors.minlength) {
messageText = "FormControl minLength error";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the message provided don't rewrite it. Here you are losing information.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add more detail to error message

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

let messageText = "unknown error";
if (this.parameterValue.errors.minlength) {
messageText = "FormControl minLength error:";
messageText = messageText + " minlength: " + this.parameterValue.errors.minlength.requiredLength;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save this.parameterValue.errors in a local variable so you don't have to repeat all that.
Also make the message look nicer like "Should be at least x characters`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And try to use string interpolation ${} instead of +

const error = this.parameterValue.errors;
if (error.minlength) {
const minLength = String(error.minlength.requiredLength);
messageText = `Should be atleast ${minLength} characters`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least and at most below

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

messageText = `Should be atmost ${maxLength} characters`;
} else if (error.min) {
const minValue = String(error.min.min);
messageText = `Should be greater than ${minValue}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greater than or equal to

messageText = `Should be greater than ${minValue}`;
} else if (this.parameterValue.errors.max) {
const maxValue = String(error.max.max);
messageText = `Should be less than ${maxValue}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less than or equal to


public get submitToolTip(): string {
if (this.isFormValid()) {
return "Click to submit form";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to "Click to submit job"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tooltip text will also be displayed when user is in pool only mode.

if (valid) {
return null;
} else {
let messageText = `unknown error`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I noticed below you are using "" instead of ``. Any reason in particular?

Example:

return "Click to submit form";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should actually use `` only if using interpolation. Use "" otherwise

@t-anjam t-anjam merged commit 39e84b5 into ncj Sep 6, 2017
@timotheeguerin timotheeguerin deleted the feature/ncj-validation branch September 6, 2017 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants