Skip to content
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

adding isTruelyInvalid property #540

Merged
merged 3 commits into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addon/-private/internal-result-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default Ember.Object.extend({
isInvalid: not('isValid'),
isNotValidating: not('isValidating'),
isTruelyValid: and('isNotValidating', 'isValid'),
isTruelyInvalid: and('isNotValidating', 'isInvalid'),

isAsync: computed('_promise', function() {
return isPromise(get(this, '_promise'));
Expand Down
7 changes: 7 additions & 0 deletions addon/-private/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ const Result = Ember.Object.extend({
*/
isTruelyValid: readOnly('_result.isTruelyValid'),

/**
* @property isTruelyInvalid
* @readOnly
* @type {Boolean}
*/
isTruelyInvalid: readOnly('_result.isTruelyInvalid'),

/**
* @property isAsync
* @readOnly
Expand Down
1 change: 1 addition & 0 deletions addon/validations/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ function createTopLevelPropsMixin(validatableAttrs) {
'isNotValidating',
'isInvalid',
'isTruelyValid',
'isTruelyInvalid',
'hasWarnings',
'messages',
'message',
Expand Down
16 changes: 16 additions & 0 deletions addon/validations/result-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ export default Ember.ArrayProxy.extend({
*/
isTruelyValid: isEvery('content', 'isTruelyValid', true, true).readOnly(),

/**
* Will be true only if isValid is `false` and isValidating is `false`
*
* ```javascript
* // Examples
* get(user, 'validations.isTruelyInvalid')
* get(user, 'validations.attrs.username.isTruelyInvalid')
* ```
*
* @property isTruelyInvalid
* @default false
* @readOnly
* @type {Boolean}
*/
isTruelyInvalid: isAny('content', 'isTruelyInvalid', true, false).readOnly(),

/**
* Will be true is the attribute in question is not `null` or `undefined`. If the object being
* validated is an Ember Data Model and you have a `defaultValue` specified, then it will use that for comparison.
Expand Down
2 changes: 1 addition & 1 deletion addon/validators/dependent.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Dependent = Base.extend({

let dependentValidations = getWithDefault(options, 'on', A()).map((dependent) => get(model, `validations.attrs.${dependent}`));

if (!isEmpty(dependentValidations.filter((v) => !get(v, 'isTruelyValid')))) {
if (!isEmpty(dependentValidations.filter((v) => get(v, 'isTruelyInvalid')))) {
return this.createErrorMessage('invalid', value, options);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/integration/validations/factory-general-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test('basic sync validation – invalid', function(assert) {
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be FALSE');
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE');
assert.equal(object.get('validations.isTruelyInvalid'), true, 'isTruelyInvalid was expected to be TRUE');

assert.equal(object.get('validations.attrs.firstName.isValid'), false);
assert.equal(object.get('validations.attrs.firstName.isValidating'), false);
Expand All @@ -60,6 +61,7 @@ test('basic sync validation – invalid', function(assert) {
assert.equal(object.get('validations.isValid'), true, 'isValid was expected to be TRUE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be TRUE');
assert.equal(object.get('validations.isTruelyValid'), true, 'isTruelyValid was expected to be TRUE');
assert.equal(object.get('validations.isTruelyInvalid'), false, 'isTruelyInvalid was expected to be FALSE');

assert.equal(object.get('validations.attrs.firstName.isValid'), true);
assert.equal(object.get('validations.attrs.firstName.isValidating'), false);
Expand All @@ -81,6 +83,7 @@ test('basic sync validation - valid', function(assert) {
assert.equal(object.get('validations.isValid'), true, 'isValid was expected to be TRUE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be FALSE');
assert.equal(object.get('validations.isTruelyValid'), true, 'isTruelyValid was expected to be TRUE');
assert.equal(object.get('validations.isTruelyInvalid'), false, 'isTruelyInvalid was expected to be FALSE');

assert.equal(object.get('validations.attrs.firstName.isValid'), true);
assert.equal(object.get('validations.attrs.firstName.isValidating'), false);
Expand All @@ -99,6 +102,7 @@ test('basic sync validation - 50% invalid', function(assert) {
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be FALSE');
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE');
assert.equal(object.get('validations.isTruelyInvalid'), true, 'isTruelyInvalid was expected to be TRUE');

assert.equal(object.get('validations.attrs.firstName.isValid'), true);
assert.equal(object.get('validations.attrs.firstName.isValidating'), false);
Expand Down Expand Up @@ -134,6 +138,7 @@ test('basic sync validation - API - #validation', function(assert) {
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be FALSE');
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE');
assert.equal(object.get('validations.isTruelyInvalid'), true, 'isTruelyInvalid was expected to be TRUE');

assert.equal(object.get('validations.attrs.firstName.isValid'), true);
assert.equal(object.get('validations.attrs.firstName.isValidating'), false);
Expand Down Expand Up @@ -172,6 +177,7 @@ test('basic sync validation - API - #validationSync', function(assert) {
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be FALSE');
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE');
assert.equal(object.get('validations.isTruelyInvalid'), true, 'isTruelyInvalid was expected to be TRUE');

assert.equal(object.get('validations.attrs.firstName.isValid'), true);
assert.equal(object.get('validations.attrs.firstName.isValidating'), false);
Expand All @@ -193,6 +199,7 @@ test('basic sync validation returns null', function(assert) {
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be FALSE');
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE');
assert.equal(object.get('validations.isTruelyInvalid'), true, 'isTruelyInvalid was expected to be TRUE');

assert.equal(object.get('validations.attrs.firstName.isValid'), false);
assert.equal(object.get('validations.attrs.firstName.isValidating'), false);
Expand Down Expand Up @@ -321,6 +328,7 @@ test('debounced validations', function(assert) {
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be TRUE');
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE');
assert.equal(object.get('validations.isTruelyInvalid'), true, 'isTruelyInvalid was expected to be TRUE');

assert.equal(object.get('validations.attrs.lastName.isValid'), false);
assert.equal(object.get('validations.attrs.lastName.isValidating'), false);
Expand Down Expand Up @@ -390,6 +398,7 @@ test('debounced validations should cleanup on object destroy', function(assert)
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be TRUE');
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE');
assert.equal(object.get('validations.isTruelyInvalid'), true, 'isTruelyInvalid was expected to be TRUE');

assert.equal(object.get('validations.attrs.lastName.isValid'), false);
assert.equal(object.get('validations.attrs.lastName.isValidating'), false);
Expand Down Expand Up @@ -426,6 +435,7 @@ test('disabled validations - simple', function(assert) {
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be TRUE');
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE');
assert.equal(object.get('validations.isTruelyInvalid'), true, 'isTruelyInvalid was expected to be TRUE');

assert.equal(object.get('validations.attrs.lastName.isValid'), true);
assert.equal(object.get('validations.attrs.firstName.isValid'), false);
Expand All @@ -450,6 +460,7 @@ test('disabled validations - cp with dependent key', function(assert) {
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be TRUE');
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE');
assert.equal(object.get('validations.isTruelyInvalid'), true, 'isTruelyInvalid was expected to be TRUE');

assert.equal(object.get('validations.attrs.lastName.isValid'), false);
assert.equal(object.get('validations.attrs.firstName.isValid'), true);
Expand Down Expand Up @@ -926,6 +937,7 @@ test('options CP changes trigger attribute revalidation', function(assert) {
assert.equal(object.get('validations.isValid'), false, 'isValid was expected to be FALSE');
assert.equal(object.get('validations.isValidating'), false, 'isValidating was expected to be FALSE');
assert.equal(object.get('validations.isTruelyValid'), false, 'isTruelyValid was expected to be FALSE');
assert.equal(object.get('validations.isTruelyInvalid'), true, 'isTruelyInvalid was expected to be TRUE');

assert.equal(object.get('validations.attrs.firstName.isValid'), false);
assert.equal(object.get('validations.attrs.firstName.message'), 'First Name is too short (minimum is 6 characters)');
Expand Down