Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Hiding the Password Strength progress when the field is empty #910

Merged
merged 2 commits into from
Oct 17, 2015

Conversation

jloveland
Copy link
Contributor

Renaming strength meter to requirements meter, hiding when password field is empty, and refactoring directives to use $validators, adding tests
bad pass
getting better
success

@jloveland
Copy link
Contributor Author

@mleanos

@mleanos
Copy link
Member

mleanos commented Sep 13, 2015

@jloveland This is what I had originally changed to hide the indicator. However, I'd rather be checking the passwordDetails.newPassword model. Could you explain what undesired behavior exists, if you return password from here? https://github.com/meanjs/mean/blob/master/modules/users/client/directives/password-validator.client.directive.js#L33
I ended up returning password & I couldn't see any negative side effects. I don't think for the purposes of this directive, that it should set the ngModel to be undefined. It could have a negative impact over something else relying on the model.

It was brought up to me by someone testing my app, that the wording "Password Strength" is misleading. This isn't really a standard strength indicator; it's a requirement meter. How do you feel about changing the wording? Maybe something along the lines of "Minimum Strength Requirement" ?

@jloveland
Copy link
Contributor Author

@mleanos I agree. I was reviewing more docs and see that I can use $validators instead of $parse. This will leave the model in tact as the user types. I will push an update soon.

Also, do you think Password Requirements above the progress bar would be clear enough instead of Password Strength?

@jloveland
Copy link
Contributor Author

depending on whether we decide to change the name from Password Strength to Password Requirements, I can change the name of variables to match the language...

@mleanos
Copy link
Member

mleanos commented Sep 14, 2015

@jloveland I think Password Requirements would be much more clear.

As for the model, try merely changing the returned value from undefined to password and play around with it. I did this & couldn't see anything else that behaved differently, other than the model being intact. You might see something that I don't. The required validator that is already implemented on that field should be sufficient.

@jloveland
Copy link
Contributor Author

@mleanos I made some updates, renaming the strength meter to requirements meter. I am also hiding the requirements meter by checking the required validator only.

I am convinced that moving from the $parsers pipeline to the $validators pipeline is the best choice with Angular 1.3. see this blog for reference:
http://blog.thoughtram.io/angularjs/2015/01/11/exploring-angular-1.3-validators-pipeline.html

{ color: "primary", progress: "80"},
{ color: "success", progress: "100"}
];
var requirementsMax = requirementsMeter.length;
Copy link
Member

Choose a reason for hiding this comment

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

where is this being used? I don't see it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch! it's not used, I will remove.

@mleanos
Copy link
Member

mleanos commented Sep 15, 2015

@jloveland Looks great! I'm still concerned as to why the the ng-model for the password remains undefined until the validators pass... Can you explain that a bit to me? I think I'm missing something very fundamental.

My preference would be to not affect the ng-model & leave it intact, but for these purposes it's probably not a huge deal.

@lirantal lirantal added this to the 0.4.2 milestone Sep 15, 2015
@lirantal
Copy link
Member

@ilanbiala I added you to review this one

@ilanbiala
Copy link
Member

@lirantal are you okay with the change? If so, then @jloveland please add tests. I'd prefer from now on to prevent bugs and issues that we require tests with any PRs, because it already helps to make reviewing easier and already shows some validity of the code.

if (origin !== viewValue) {
modelCtrl.$setValidity("passwordVerify", false);
return undefined;
if (origin !== password) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we just clean this up to be a ternary op?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure!

@ilanbiala
Copy link
Member

@jloveland another thing, I remember @rhutchison doing something with ng-messages. @rhutchison was that cleaner?

@lirantal
Copy link
Member

I'm ok with this.
I'll also add that if you are submitting a PR please add screenshots, which is extra important when you are doing frontend PRs. If I did that for my server-side PRs then you should have no problems doing it for frontend.

@jloveland
Copy link
Contributor Author

@mleanos, ngModel = undefined is the default behavior by design for the $validators pipeline. Please review this issue: angular/angular.js#1412

@jloveland
Copy link
Contributor Author

@ilanbiala and @rhutchison I added the errors returned from password-validator within the ng-messages block. for example:
https://github.com/meanjs/mean/blob/master/modules/users/client/views/authentication/signup.client.view.html#L40
do you see anything wrong with this approach?

@mleanos
Copy link
Member

mleanos commented Sep 16, 2015

@jloveland Thanks for the reference. I think for the purposes of this exact implementation (used for Password validation), we can go with it.

However, if we implement $validators somewhere else in the project, we should pay attention to this behavior. I can see some cases where the ngModel value would need to be retained even when not valid.

This LGTM, and is ready to be merged from my perspective.

}
});
};
}
});
}
Copy link
Member

Choose a reason for hiding this comment

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

@jloveland Slight indentation issue.

@mleanos
Copy link
Member

mleanos commented Sep 16, 2015

For reference.. If the behavior of the ngModel being set to undefined is undesired, we could use the allowInvalid ng-model-options setting.

ng-model-options="{ allowInvalid: true }"

This will allow the ng-model to retain the value, while still marking the model as invalid from the $validator. Again, I don't think this option is needed for this particular case. But wanted to drop this here for anyone coming along later.

@jloveland
Copy link
Contributor Author

@ilanbiala I am trying to develop karma and e2e tests for this. I am seeing this error with protractor: Error: Angular could not be found on the page http://localhost:3000/authentication/signin : retries looking for angular exceeded. Is this a bug with mean.js? or am I doing something wrong?

@ilanbiala
Copy link
Member

@jloveland I think you have something set up incorrectly. In a separate commit, can you add what you have so far for tests?

@ilanbiala
Copy link
Member

@jloveland is the testing issue fixed with the PR you have open right now?

@jloveland
Copy link
Contributor Author

@ilanbiala e2e testing issues have been resolved.
I am planning on adding unit tests for the directives to this PR.
Should I also add e2e tests here? or would it be easier to review if I added those e2e tests to a different PR?

@ilanbiala
Copy link
Member

@jloveland add all the tests to this PR.

@@ -110,6 +110,7 @@
"karma-ng-html2js-preprocessor": "^0.1.2",
"karma-phantomjs-launcher": "~0.2.0",
"load-grunt-tasks": "^3.2.0",
"protractor": "git://github.com/angular/protractor.git#master",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for some reason, this isn't doing the trick with node v.10 even though this PR was thought to fix the issue.
https://github.com/angular/protractor/pull/2591/files
https://travis-ci.org/angular/protractor/jobs/84351567

Anyone have thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ilanbiala I am seeing that travis is failing to run using node v0.10. it looks like the error is due to node_modules/grunt-protractor-runner/node_modules/protractor/lib/configParser.js:102:29) which seems to be an embedded protractor version..so, I suppose we need to wait until grunt-protractor-runner upgrades or we can use my fork..not sure what the best option is..

@ilanbiala
Copy link
Member

@jloveland what do you mean?

@jloveland
Copy link
Contributor Author

@ilanbiala sorry for all the chatter here..never mind, I was looking at an old build...looks like all tests pass

@ilanbiala
Copy link
Member

@jloveland just curious to see if any functionality wasn't covered in the tests, do you think you could try adding https://github.com/karma-runner/karma-coverage to Grunt and Gulp in a PR so we can verify?

@jloveland
Copy link
Contributor Author

@ilanbiala I am also curious about that. I can add another PR for karma coverage.

I was having issues writing unit tests for the directives. For the password-validator and password-verify directives, I am having trouble determining how to mock the services that the directive depends on...also, it doesn't seem to me that the directives are being loaded in the tests. I added e2e tests instead of unit tests because of the challenges I am having with figuring out how to unit test the directive that is dependent on services..

@ilanbiala
Copy link
Member

@jloveland let's start with a PR for karma/e2e coverage, and then we can see specifically what else needs to be tested and how to rework the tests so they are clean and intuitive.

@mleanos
Copy link
Member

mleanos commented Oct 11, 2015

@jloveland Per our Gitter discussion...

I verified the directives are being loaded with the tests. However, just like you, I was experiencing the password-validator $parser wasn't executing. I had to manually execute the $parser function on the model, inside a test like so..

scope.userForm.password.$parsers[0](scope.credentials.password); - may not be the correct way to handle this, but at least it's a hint at what we need to do. Might want to put this into a function inside the test file for reuse.

I verified that scope.passwordErrors was being properly populated based on the validation.

Also, to answer your question about whether or not we should put this into a separate PR. I think so. I think we should put Directive tests into their own files, since they behave differently than the other tests. For instance, we could add a new test file to modules/users/tests/client called password-validator.client.directive.tests.js

Let me know what you think about this.

@jloveland
Copy link
Contributor Author

Thanks to the huge help from @mleanos, I was able to add tests for the password-validator and password-verify directives.

@ilanbiala I have PR #985 with karma test coverage. Does anyone out there want to take on the e2e coverage PR?

@mleanos
Copy link
Member

mleanos commented Oct 14, 2015

@jloveland I was happy to help out!

The tests look great. However, I did run into an issue with the E2E tests. I got the same error, as the build.
https://travis-ci.org/meanjs/mean/jobs/85249711#L715

All in all, this looks really good. +8.5 is nothing to sneeze at :) Great job!

@jloveland
Copy link
Contributor Author

@mleanos thanks for reviewing. I am fixing the e2e test now..also rebasing..

@mleanos
Copy link
Member

mleanos commented Oct 14, 2015

Everything is passing now! Thanks for all the hard work you put into this @jloveland Our test coverage is getting there.

Now that there's so many more E2E tests, it's entertaining to sit back & watch them run :)

LGTM

@lirantal
Copy link
Member

Good job guys 👍

@jloveland
Copy link
Contributor Author

I believe this is ready to merge.

@codydaig
Copy link
Member

LGTM 👍

ilanbiala added a commit that referenced this pull request Oct 17, 2015
Hide the password strength progress when the field is empty
@ilanbiala ilanbiala merged commit cc486d5 into meanjs:master Oct 17, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants