forked from json-schema-form/angular-schema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Number fields got "Required" insted of "Value is not a number" since the input[type="number"] stopped the value being written to the model and we had higher precedence on tv4 error messages. This is no longer the case we show some ordinary angular validation messages as well. This fixes json-schema-form#322 Also fixed some small bugs regarding the error messages. Often `viewValue` is what you want in the error message. Plus a start with protractor.
- Loading branch information
Showing
12 changed files
with
152 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"preset": "google", | ||
"maximumLineLength": 100 | ||
"maximumLineLength": 100, | ||
"disallowMultipleLineBreaks": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var gulp = require('gulp'); | ||
|
||
// The protractor task | ||
var protractor = require('gulp-protractor'); | ||
|
||
// Start a standalone server | ||
var webdriver_standalone = protractor.webdriver_standalone; | ||
|
||
// Download and update the selenium driver | ||
var webdriver_update = protractor.webdriver_update; | ||
|
||
// Downloads the selenium webdriver | ||
gulp.task('webdriver-update', webdriver_update); | ||
|
||
// Start the standalone selenium server | ||
// NOTE: This is not needed if you reference the | ||
// seleniumServerJar in your protractor.conf.js | ||
gulp.task('webdriver-standalone', webdriver_standalone); | ||
|
||
|
||
// Setting up the test task | ||
gulp.task('protractor', ['webdriver-update'], function(cb) { | ||
gulp.src(['test/protractor/specs/**/*.js']).pipe(protractor.protractor({ | ||
configFile: 'test/protractor/conf.js', | ||
})).on('error', function(e) { | ||
console.log(e); | ||
}).on('end', cb); | ||
}); | ||
|
||
['validation-messages', 'custom-validation'].forEach(function(name) { | ||
gulp.task('protractor:' + name, ['webdriver-update'], function(cb) { | ||
gulp.src(['test/protractor/specs/' + name + '.js']).pipe(protractor.protractor({ | ||
configFile: 'test/protractor/conf.js', | ||
})).on('error', function(e) { | ||
console.log(e); | ||
}).on('end', cb); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
exports.config = { | ||
seleniumAddress: 'http://localhost:4444/wd/hub', | ||
specs: ['custom-validation.js'] | ||
seleniumAddress: 'http://localhost:4444/wd/hub' | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* global browser, it, describe, element, by */ | ||
|
||
describe('Schema Form validation messages', function() { | ||
|
||
describe('#string', function() { | ||
var URL = 'http://localhost:8080/examples/bootstrap-example.html#/86fb7505a8ab6a43bc70'; | ||
|
||
it('should not complain if it gets a normal string', function() { | ||
browser.get(URL); | ||
var input = element.all(by.css('form[name=ngform] input')).first(); | ||
input.sendKeys('string'); | ||
|
||
expect(input.getAttribute('value')).toEqual('string'); | ||
expect(input.evaluate('ngModel.$valid')).toEqual(true); | ||
|
||
}); | ||
|
||
|
||
var validationMessageTestBuider = function(nr, value, validationMessage) { | ||
it('should say "' + validationMessage + '" when input is ' + value, function() { | ||
browser.get(URL); | ||
var input = element.all(by.css('form[name=ngform] input')).get(nr); | ||
input.sendKeys(value); | ||
|
||
var message = element.all(by.css('form[name=ngform] div[sf-message]')).get(nr); | ||
expect(input.evaluate('ngModel.$valid')).toEqual(false); | ||
expect(message.getText()).toEqual(validationMessage); | ||
|
||
}); | ||
}; | ||
|
||
var stringTests = { | ||
's': 'String is too short (1 chars), minimum 3', | ||
'tooo long string': 'String is too long (11 chars), maximum 10', | ||
'foo 66': 'String does not match pattern: ^[a-zA-Z ]+$' | ||
}; | ||
|
||
Object.keys(stringTests).forEach(function(value) { | ||
validationMessageTestBuider(0, value, stringTests[value]); | ||
}); | ||
|
||
|
||
var integerTests = { | ||
'3': '3 is less than the allowed minimum of 6', | ||
'66': '66 is greater than the allowed maximum of 50', | ||
'11': 'Value is not a multiple of 3', | ||
'aaa': 'Value is not a valid number' | ||
}; | ||
|
||
Object.keys(integerTests).forEach(function(value) { | ||
validationMessageTestBuider(1, value, integerTests[value]); | ||
}); | ||
|
||
|
||
it('should say "Required" when fields are required', function() { | ||
browser.get(URL); | ||
element.all(by.css('form[name=ngform]')).submit(); | ||
var input = element.all(by.css('form[name=ngform] input')).get(1); | ||
|
||
var message = element.all(by.css('form[name=ngform] div[sf-message]')).get(1); | ||
expect(input.evaluate('ngModel.$valid')).toEqual(false); | ||
expect(message.getText()).toEqual('Required'); | ||
|
||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters