Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit da7d756

Browse files
committed
Backported some tests from angular1.2 branch.
1 parent c8b3c4a commit da7d756

File tree

6 files changed

+391
-28
lines changed

6 files changed

+391
-28
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bower_components/
2-
node_modules/
2+
node_modules/
3+
coverage/

bower.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
],
1818
"dependencies": {
1919
"angular": "~1.0.x",
20-
"jquery-ui": ">= 1.9",
21-
"jquery-simulate": "latest"
20+
"jquery-ui": ">= 1.9"
2221
},
2322
"devDependencies": {
24-
"angular-mocks": "~1.0.x"
23+
"angular-mocks": "~1.0.x",
24+
"jquery-simulate": "latest"
2525
}
2626
}

gruntFile.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function (grunt) {
1+
module.exports = function(grunt) {
22

33
grunt.loadNpmTasks('grunt-testacular');
44
grunt.loadNpmTasks('grunt-contrib-jshint');
@@ -7,8 +7,14 @@ module.exports = function (grunt) {
77
grunt.registerTask('default', ['jshint', 'testacular']);
88

99
var testacularConfig = function(configFile, customOptions) {
10-
var options = { configFile: configFile, keepalive: true };
11-
var travisOptions = process.env.TRAVIS && { browsers: ['Firefox'], reporters: 'dots' };
10+
var options = {
11+
configFile: configFile,
12+
keepalive: true
13+
};
14+
var travisOptions = process.env.TRAVIS && {
15+
browsers: ['Firefox'],
16+
reporters: 'dots'
17+
};
1218
return grunt.util._.extend(options, customOptions, travisOptions);
1319
};
1420

@@ -19,19 +25,20 @@ module.exports = function (grunt) {
1925
options: testacularConfig('test/test.conf.js')
2026
}
2127
},
22-
jshint:{
23-
files:['src/**/*.js', 'test/**/*.js', 'demo/**/*.js'],
24-
options:{
25-
curly:true,
26-
eqeqeq:true,
27-
immed:true,
28-
latedef:true,
29-
newcap:true,
30-
noarg:true,
31-
sub:true,
32-
boss:true,
33-
eqnull:true,
34-
globals:{}
28+
jshint: {
29+
files: ['src/**/*.js', 'test/**/*.js', 'demo/**/*.js', '!test/libs/*.js'],
30+
options: {
31+
curly: true,
32+
eqeqeq: true,
33+
immed: true,
34+
//indent: 2,
35+
latedef: true,
36+
newcap: true,
37+
noarg: true,
38+
sub: true,
39+
boss: true,
40+
eqnull: true,
41+
globals: {}
3542
}
3643
}
3744
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
;(function($, undefined) {
2+
function findCenter(elem) {
3+
var offset,
4+
document = $(elem.ownerDocument);
5+
elem = $(elem);
6+
offset = elem.offset();
7+
8+
return {
9+
x: offset.left + elem.outerWidth() / 2 - document.scrollLeft(),
10+
y: offset.top + elem.outerHeight() / 2 - document.scrollTop()
11+
};
12+
}
13+
14+
$.extend($.simulate.prototype, {
15+
simulateDragAndRevert: function() {
16+
var i = 0,
17+
target = this.target,
18+
options = this.options,
19+
center = findCenter(target),
20+
x = Math.floor(center.x),
21+
y = Math.floor(center.y),
22+
dx = options.dx || 0,
23+
dy = options.dy || 0,
24+
moves = options.moves || 3,
25+
coord = {
26+
clientX: x,
27+
clientY: y
28+
};
29+
30+
this.simulateEvent(target, "mousedown", coord);
31+
32+
for (; i < moves; i++) {
33+
x += dx / moves;
34+
y += dy / moves;
35+
36+
coord = {
37+
clientX: Math.round(x),
38+
clientY: Math.round(y)
39+
};
40+
41+
this.simulateEvent(document, "mousemove", coord);
42+
}
43+
44+
for (i = 0; i < moves; i++) {
45+
x -= dx / moves;
46+
y -= dy / moves;
47+
48+
coord = {
49+
clientX: Math.round(x),
50+
clientY: Math.round(y)
51+
};
52+
53+
this.simulateEvent(document, "mousemove", coord);
54+
}
55+
56+
this.simulateEvent(target, "mouseup", coord);
57+
this.simulateEvent(target, "click", coord);
58+
}
59+
});
60+
})(jQuery);

0 commit comments

Comments
 (0)