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

Commit

Permalink
Merge pull request #83 from thgreasi/master
Browse files Browse the repository at this point in the history
Backported some tests from angular1.2 branch.
  • Loading branch information
thgreasi committed Dec 21, 2013
2 parents 718ffce + da7d756 commit e787b29
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bower_components/
node_modules/
node_modules/
coverage/
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
],
"dependencies": {
"angular": "~1.0.x",
"jquery-ui": ">= 1.9",
"jquery-simulate": "latest"
"jquery-ui": ">= 1.9"
},
"devDependencies": {
"angular-mocks": "~1.0.x"
"angular-mocks": "~1.0.x",
"jquery-simulate": "latest"
}
}
39 changes: 23 additions & 16 deletions gruntFile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (grunt) {
module.exports = function(grunt) {

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

var testacularConfig = function(configFile, customOptions) {
var options = { configFile: configFile, keepalive: true };
var travisOptions = process.env.TRAVIS && { browsers: ['Firefox'], reporters: 'dots' };
var options = {
configFile: configFile,
keepalive: true
};
var travisOptions = process.env.TRAVIS && {
browsers: ['Firefox'],
reporters: 'dots'
};
return grunt.util._.extend(options, customOptions, travisOptions);
};

Expand All @@ -19,19 +25,20 @@ module.exports = function (grunt) {
options: testacularConfig('test/test.conf.js')
}
},
jshint:{
files:['src/**/*.js', 'test/**/*.js', 'demo/**/*.js'],
options:{
curly:true,
eqeqeq:true,
immed:true,
latedef:true,
newcap:true,
noarg:true,
sub:true,
boss:true,
eqnull:true,
globals:{}
jshint: {
files: ['src/**/*.js', 'test/**/*.js', 'demo/**/*.js', '!test/libs/*.js'],
options: {
curly: true,
eqeqeq: true,
immed: true,
//indent: 2,
latedef: true,
newcap: true,
noarg: true,
sub: true,
boss: true,
eqnull: true,
globals: {}
}
}
});
Expand Down
60 changes: 60 additions & 0 deletions test/libs/jquery.simulate.dragandrevert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
;(function($, undefined) {
function findCenter(elem) {
var offset,
document = $(elem.ownerDocument);
elem = $(elem);
offset = elem.offset();

return {
x: offset.left + elem.outerWidth() / 2 - document.scrollLeft(),
y: offset.top + elem.outerHeight() / 2 - document.scrollTop()
};
}

$.extend($.simulate.prototype, {
simulateDragAndRevert: function() {
var i = 0,
target = this.target,
options = this.options,
center = findCenter(target),
x = Math.floor(center.x),
y = Math.floor(center.y),
dx = options.dx || 0,
dy = options.dy || 0,
moves = options.moves || 3,
coord = {
clientX: x,
clientY: y
};

this.simulateEvent(target, "mousedown", coord);

for (; i < moves; i++) {
x += dx / moves;
y += dy / moves;

coord = {
clientX: Math.round(x),
clientY: Math.round(y)
};

this.simulateEvent(document, "mousemove", coord);
}

for (i = 0; i < moves; i++) {
x -= dx / moves;
y -= dy / moves;

coord = {
clientX: Math.round(x),
clientY: Math.round(y)
};

this.simulateEvent(document, "mousemove", coord);
}

this.simulateEvent(target, "mouseup", coord);
this.simulateEvent(target, "click", coord);
}
});
})(jQuery);
Loading

0 comments on commit e787b29

Please sign in to comment.