Skip to content

Commit 0bf2427

Browse files
committed
Migrated gulp tasks and protractor tests
1 parent e497e3a commit 0bf2427

14 files changed

+277
-42
lines changed

examples/bootstrap-example.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ <h3>Schema</h3>
203203
<script type="text/javascript" src="../bower_components/ace-builds/src-min-noconflict/ace.js"></script>
204204
<script type="text/javascript" src="../bower_components/angular/angular.js"></script>
205205
<script type="text/javascript" src="../bower_components/angular-sanitize/angular-sanitize.min.js"></script>
206-
<!--
206+
207207
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.min.js"></script>
208208
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.2.0/ZeroClipboard.min.js"></script>
209209
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ng-clip/0.2.6/ng-clip.min.js"></script>
210210
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
211211
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.1/ui-bootstrap.min.js"></script>
212-
-->
212+
213213
<!-- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script> -->
214214
<!-- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular-sanitize.min.js"></script> -->
215215

@@ -282,7 +282,7 @@ <h3>Schema</h3>
282282
$scope.selectedTest = $scope.tests[0];
283283
});
284284
} else {
285-
$scope.selectedTest = $scope.tests[4];
285+
$scope.selectedTest = $scope.tests[0];
286286
}
287287

288288
$scope.$watch('selectedTest',function(val){

examples/custom-validators.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ <h3>Demo of custom validators, async validators and parsers</h3>
2424

2525
<script type="text/javascript" src="../bower_components/objectpath/lib/ObjectPath.js"></script>
2626

27-
<script type="text/javascript" src="../dist/schema-form.js"></script>
28-
<script type="text/javascript" src="../dist/bootstrap-decorator.min.js"></script>
27+
<script type="text/javascript" src="../bower_components/angular-schema-form/dist/schema-form.js"></script>
28+
<script type="text/javascript" src="../bootstrap-decorator.js"></script>
2929

3030
<script>
3131
angular.module('test', ['schemaForm']).controller('TestCtrl', function($scope, $q, $timeout) {

gulp/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var fs = require('fs'),
2+
tasks = fs.readdirSync('./gulp/tasks'),
3+
gulp = require('gulp');
4+
5+
tasks.forEach(function(task) {
6+
require('./tasks/' + task);
7+
});

gulp/tasks/bootstrap-datepicker.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var gulp = require('gulp'),
2+
streamqueue = require('streamqueue'),
3+
minifyHtml = require('gulp-minify-html'),
4+
templateCache = require('gulp-angular-templatecache'),
5+
concat = require('gulp-concat'),
6+
uglify = require('gulp-uglify');
7+
8+
gulp.task('bootstrap-datepicker', function() {
9+
var stream = streamqueue({objectMode: true});
10+
stream.queue(
11+
gulp.src('./src/directives/decorators/bootstrap/datepicker/*.html')
12+
.pipe(minifyHtml({
13+
empty: true,
14+
spare: true,
15+
quotes: true
16+
}))
17+
.pipe(templateCache({
18+
module: 'schemaForm',
19+
root: 'directives/decorators/bootstrap/datepicker/'
20+
}))
21+
);
22+
stream.queue(gulp.src('./src/directives/decorators/bootstrap/datepicker/*.js'));
23+
24+
stream.done()
25+
.pipe(concat('bootstrap-datepicker.min.js'))
26+
.pipe(uglify())
27+
.pipe(gulp.dest('./dist/'));
28+
29+
});

gulp/tasks/default.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var gulp = require('gulp');
2+
3+
gulp.task('default', [
4+
'minify'
5+
]);

gulp/tasks/jscs.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var gulp = require('gulp'),
2+
jscs = require('gulp-jscs');
3+
4+
gulp.task('jscs', function() {
5+
gulp.src('./src/**/*.js')
6+
.pipe(jscs());
7+
});

gulp/tasks/minify.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var gulp = require('gulp'),
2+
streamqueue = require('streamqueue'),
3+
minifyHtml = require('gulp-minify-html'),
4+
templateCache = require('gulp-angular-templatecache'),
5+
concat = require('gulp-concat'),
6+
rename = require('gulp-rename'),
7+
uglify = require('gulp-uglify');
8+
9+
gulp.task('minify', function() {
10+
var stream = streamqueue({objectMode: true});
11+
stream.queue(
12+
gulp.src('./src/**/*.html')
13+
.pipe(minifyHtml({
14+
empty: true,
15+
spare: true,
16+
quotes: true
17+
}))
18+
.pipe(templateCache({
19+
module: 'schemaForm',
20+
root: 'decorators/bootstrap/'
21+
}))
22+
);
23+
stream.queue(gulp.src('./src/**/*.js'));
24+
25+
stream.done()
26+
.pipe(concat('bootstrap-decorator.js'))
27+
.pipe(gulp.dest('./'))
28+
.pipe(uglify())
29+
.pipe(rename('bootstrap-decorator.min.js'))
30+
.pipe(gulp.dest('./'));
31+
32+
});

gulp/tasks/protractor.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var gulp = require('gulp');
2+
3+
// The protractor task
4+
var protractor = require('gulp-protractor');
5+
6+
// Start a standalone server
7+
var webdriver_standalone = protractor.webdriver_standalone;
8+
9+
// Download and update the selenium driver
10+
var webdriver_update = protractor.webdriver_update;
11+
12+
// Downloads the selenium webdriver
13+
gulp.task('webdriver-update', webdriver_update);
14+
15+
// Start the standalone selenium server
16+
// NOTE: This is not needed if you reference the
17+
// seleniumServerJar in your protractor.conf.js
18+
gulp.task('webdriver-standalone', webdriver_standalone);
19+
20+
21+
// Setting up the test task
22+
gulp.task('protractor', ['webdriver-update'], function(cb) {
23+
gulp.src(['test/protractor/specs/**/*.js']).pipe(protractor.protractor({
24+
configFile: 'test/protractor/conf.js',
25+
})).on('error', function(e) {
26+
console.log(e);
27+
}).on('end', cb);
28+
});
29+
30+
['validation-messages', 'custom-validation'].forEach(function(name) {
31+
gulp.task('protractor:' + name, ['webdriver-update'], function(cb) {
32+
gulp.src(['test/protractor/specs/' + name + '.js']).pipe(protractor.protractor({
33+
configFile: 'test/protractor/conf.js',
34+
})).on('error', function(e) {
35+
console.log(e);
36+
}).on('end', cb);
37+
});
38+
});

gulp/tasks/watch.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var gulp = require('gulp');
2+
3+
gulp.task('watch', function() {
4+
gulp.watch('./src/**/*', ['default']);
5+
});

gulpfile.js

+3-37
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,5 @@
1-
var gulp = require('gulp'),
2-
streamqueue = require('streamqueue'),
3-
minifyHtml = require('gulp-minify-html'),
4-
templateCache = require('gulp-angular-templatecache'),
5-
concat = require('gulp-concat'),
6-
rename = require('gulp-rename'),
7-
uglify = require('gulp-uglify');
81

9-
gulp.task('build', function() {
10-
var stream = streamqueue({objectMode: true});
11-
stream.queue(
12-
gulp.src('./src/**/*.html')
13-
.pipe(minifyHtml({
14-
empty: true,
15-
spare: true,
16-
quotes: true
17-
}))
18-
.pipe(templateCache({
19-
module: 'schemaForm',
20-
root: 'decorators/bootstrap/'
21-
}))
22-
);
23-
stream.queue(gulp.src('./src/**/*.js'));
2+
//all of the tasks themselves are contained in the gulp/tasks directory,
3+
//which is accessed through gulp/index.js
244

25-
stream.done()
26-
.pipe(concat('bootstrap-decorator.js'))
27-
.pipe(gulp.dest('./'))
28-
.pipe(uglify())
29-
.pipe(rename('bootstrap-decorator.min.js'))
30-
.pipe(gulp.dest('./'));
31-
32-
});
33-
34-
35-
gulp.task('watch', function() {
36-
gulp.watch('./src/**/*', ['default']);
37-
});
38-
39-
gulp.task('default', ['build']);
5+
require('./gulp');

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
"gulp": "^3.8.11",
1616
"gulp-angular-templatecache": "^1.6.0",
1717
"gulp-concat": "^2.5.2",
18+
"gulp-jscs": "^2.0.0",
1819
"gulp-minify-html": "^1.0.2",
20+
"gulp-protractor": "^1.0.0",
1921
"gulp-rename": "^1.2.2",
2022
"gulp-uglify": "^1.2.0",
23+
"gulp-umd": "^0.2.0",
2124
"gulp-watch": "^4.2.4",
2225
"streamqueue": "^0.1.3"
2326
}

test/protractor/conf.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exports.config = {
2+
seleniumAddress: 'http://localhost:4444/wd/hub'
3+
}
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
describe('Schema Form custom validators', function() {
2+
it('should have a form with content', function() {
3+
browser.get('http://localhost:8080/examples/custom-validators.html');
4+
5+
expect(element(by.css('form')).getInnerHtml()).not.toEqual('');
6+
});
7+
8+
describe('#name', function() {
9+
it('should not complain if it gets a normal name', function() {
10+
browser.get('http://localhost:8080/examples/custom-validators.html');
11+
var input = element.all(by.css('form input')).first();
12+
input.sendKeys('Joe Schmoe');
13+
14+
expect(input.getAttribute('value')).toEqual('Joe Schmoe');
15+
expect(input.evaluate('ngModel.$valid')).toEqual(true);
16+
17+
});
18+
19+
it('should complain if it gets a "Bob" as a name', function() {
20+
browser.get('http://localhost:8080/examples/custom-validators.html');
21+
var input = element.all(by.css('form input')).first();
22+
input.sendKeys('Bob');
23+
24+
expect(input.getAttribute('value')).toEqual('Bob');
25+
expect(input.evaluate('ngModel.$valid')).toEqual(false);
26+
});
27+
});
28+
29+
describe('#email', function() {
30+
it('should not complain if it gets a normal email', function() {
31+
browser.get('http://localhost:8080/examples/custom-validators.html');
32+
var input = element.all(by.css('form input')).get(1);
33+
input.sendKeys('[email protected]');
34+
35+
expect(input.getAttribute('value')).toEqual('[email protected]');
36+
expect(input.evaluate('ngModel.$valid')).toEqual(true);
37+
38+
});
39+
40+
it('should complain if it gets a my email', function() {
41+
browser.get('http://localhost:8080/examples/custom-validators.html');
42+
var input = element.all(by.css('form input')).get(1);
43+
input.sendKeys('[email protected]');
44+
45+
expect(input.getAttribute('value')).toEqual('[email protected]');
46+
expect(input.evaluate('ngModel.$valid')).toEqual(false);
47+
});
48+
});
49+
50+
describe('#comment', function() {
51+
it('should not complain if it gets a normal email', function() {
52+
browser.get('http://localhost:8080/examples/custom-validators.html');
53+
var input = element.all(by.css('form input')).get(1);
54+
input.sendKeys('[email protected]');
55+
56+
expect(input.getAttribute('value')).toEqual('[email protected]');
57+
expect(input.evaluate('ngModel.$valid')).toEqual(true);
58+
59+
});
60+
61+
it('should complain if it gets a my email', function() {
62+
browser.get('http://localhost:8080/examples/custom-validators.html');
63+
var input = element.all(by.css('form input')).get(1);
64+
input.sendKeys('[email protected]');
65+
66+
expect(input.getAttribute('value')).toEqual('[email protected]');
67+
expect(input.evaluate('ngModel.$valid')).toEqual(false);
68+
});
69+
});
70+
71+
72+
73+
74+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* global browser, it, describe, element, by */
2+
3+
describe('Schema Form validation messages', function() {
4+
5+
describe('#string', function() {
6+
var URL = 'http://localhost:8080/examples/bootstrap-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+
expect(message.getText()).toEqual(validationMessage);
28+
29+
});
30+
};
31+
32+
var stringTests = {
33+
's': 'String is too short (1 chars), minimum 3',
34+
'tooo long string': 'String is too long (11 chars), maximum 10',
35+
'foo 66': 'String does not match pattern: ^[a-zA-Z ]+$'
36+
};
37+
38+
Object.keys(stringTests).forEach(function(value) {
39+
validationMessageTestBuider(0, value, stringTests[value]);
40+
});
41+
42+
43+
var integerTests = {
44+
'3': '3 is less than the allowed minimum of 6',
45+
'66': '66 is greater than the allowed maximum of 50',
46+
'11': 'Value is not a multiple of 3',
47+
'aaa': 'Value is not a valid number'
48+
};
49+
50+
Object.keys(integerTests).forEach(function(value) {
51+
validationMessageTestBuider(1, value, integerTests[value]);
52+
});
53+
54+
55+
it('should say "Required" when fields are required', function() {
56+
browser.get(URL);
57+
element.all(by.css('form[name=ngform]')).submit();
58+
var input = element.all(by.css('form[name=ngform] input')).get(1);
59+
60+
var message = element.all(by.css('form[name=ngform] div[sf-message]')).get(1);
61+
expect(input.evaluate('ngModel.$valid')).toEqual(false);
62+
expect(message.getText()).toEqual('Required');
63+
64+
});
65+
});
66+
});

0 commit comments

Comments
 (0)