Skip to content

Commit 29bd267

Browse files
Initial tests config, updated documentation regarding tests
1 parent 04e52da commit 29bd267

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@ Future
4242
Using the new builder opens up for a lot of optimization. Primarily we can get rid of a lot of small
4343
watches by using build helpers. For instance, slapping on a `sf-changed` directive *only* if the
4444
form definition has an `onChange` option.
45+
46+
47+
Testing
48+
-------
49+
...
50+
npm install -g protractor
51+
protractor test/protractor/conf.js
52+
...
53+
54+
change baseurl in test/protractor/conf.js to match ur local environment.

test/protractor/conf.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
exports.config = {
2+
specs: ['specs/*.js'],
3+
baseUrl: 'http://localhost:63342/',
4+
multiCapabilities: [
5+
{'browserName': 'firefox'},
6+
{'browserName': 'chrome'}
7+
]
8+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* global browser, it, describe, element, by */
2+
3+
describe('Schema Form validation messages', function() {
4+
5+
describe('#string', function() {
6+
var URL = 'angular-schema-form-material/examples/material-example.html#/86fb7505a8ab6a43bc70';
7+
8+
it('should not complain if it gets a normal string', function() {
9+
browser.get(URL);
10+
var input = element.all(by.css('form[name=ngform] input')).first();
11+
input.sendKeys('string');
12+
13+
expect(input.getAttribute('value')).toEqual('string');
14+
expect(input.evaluate('ngModel.$valid')).toEqual(true);
15+
16+
});
17+
18+
19+
var validationMessageTestBuider = function(nr, value, validationMessage) {
20+
it('should say "' + validationMessage + '" when input is ' + value, function() {
21+
browser.get(URL);
22+
var input = element.all(by.css('form[name=ngform] input')).get(nr);
23+
input.sendKeys(value);
24+
25+
var message = element.all(by.css('form[name=ngform] div[sf-message]'));//.get(nr);
26+
expect(input.evaluate('ngModel.$valid')).toEqual(false);
27+
28+
/* no error messages at this point */
29+
//expect(message.getText()).toEqual(validationMessage);
30+
31+
});
32+
};
33+
34+
var stringTests = {
35+
's': 'String is too short (1 chars), minimum 3',
36+
'tooo long string': 'String is too long (11 chars), maximum 10',
37+
'foo 66': 'String does not match pattern: ^[a-zA-Z ]+$'
38+
};
39+
40+
Object.keys(stringTests).forEach(function(value) {
41+
validationMessageTestBuider(0, value, stringTests[value]);
42+
});
43+
44+
45+
var integerTests = {
46+
'3': '3 is less than the allowed minimum of 6',
47+
'66': '66 is greater than the allowed maximum of 50',
48+
'11': 'Value is not a multiple of 3',
49+
// Chrome no longer lets you input anything but numbers in a type="number" input.
50+
'aaa': 'Required' //'Value is not a valid number'
51+
};
52+
53+
Object.keys(integerTests).forEach(function(value) {
54+
validationMessageTestBuider(1, value, integerTests[value]);
55+
});
56+
57+
58+
it('should say "Required" when fields are required', function() {
59+
browser.get(URL);
60+
element.all(by.css('form[name=ngform]')).submit();
61+
var input = element.all(by.css('form[name=ngform] input')).get(1);
62+
63+
var message = element.all(by.css('form[name=ngform] div[sf-message]'));//.get(1);
64+
expect(input.evaluate('ngModel.$valid')).toEqual(false);
65+
66+
/* no error messages at this point */
67+
//expect(message.getText()).toEqual('Required');
68+
69+
});
70+
});
71+
});

0 commit comments

Comments
 (0)