-
-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debounced validation functionality #92
Changes from 2 commits
1f5abfd
047e752
4ee9fa7
fcca0c9
7991bf1
475505f
22b4dcd
2859fec
2e7d7b6
98faae8
e3030b3
e12b7a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,3 +247,35 @@ test("custom messages object", function(assert) { | |
assert.equal(object.get('validations.attrs.firstName.isValidating'), false); | ||
assert.equal(object.get('validations.attrs.firstName.message'), 'Test error message'); | ||
}); | ||
|
||
test("debounced validations", function(assert) { | ||
var done = assert.async(); | ||
var Validations = buildValidations({ | ||
firstName: validator(Validators.presence), | ||
lastName: validator(Validators.presence, { debounce: 500 }), | ||
}); | ||
var object = setupObject(this, Ember.Object.extend(Validations)); | ||
|
||
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE'); | ||
// TODO: I feel like initially a debounced validation should not be debounced. | ||
assert.equal(object.get('validations.isValidating'), true, 'isValidating was expected to be TRUE'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right when we create the object, the |
||
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE'); | ||
|
||
Ember.run.later(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont know if this is the correct behavior. Instantly, we have to wait for all the debounced validations to finish before we can do anything else. I guess one solution is just to call |
||
assert.equal(object.get('validations.attrs.lastName.isValid'), false); | ||
assert.equal(object.get('validations.attrs.lastName.isValidating'), false); | ||
assert.equal(object.get('validations.attrs.lastName.message'), 'lastName should be present'); | ||
|
||
object.set('lastName', 'Golan'); | ||
// TODO: This is true because a new Validation result object is created which initially defaults to TRUE | ||
assert.equal(object.get('validations.attrs.lastName.isValid'), true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this doesnt feel right. When we set a new value to the debounced CP, it creates a new ValidationResult object with the new promise but that new object gets instantiated by default with |
||
assert.equal(object.get('validations.attrs.lastName.isValidating'), true); | ||
|
||
Ember.run.later(() => { | ||
assert.equal(object.get('validations.attrs.lastName.isValid'), true); | ||
assert.equal(object.get('validations.attrs.lastName.isValidating'), false); | ||
assert.equal(object.get('validations.attrs.lastName.message'), null); | ||
done(); | ||
}, 600); | ||
}, 600); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of this function, we should likely just do the following, from the calling side.