Skip to content

Commit a730367

Browse files
author
Sebastien Chartier
committed
Added test folder (inactive for the moment)
1 parent 5a8a514 commit a730367

13 files changed

+1988
-0
lines changed

test/.jshintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"node": true,
3+
"globals": {
4+
"angular": false,
5+
"inject": false,
6+
"$": false,
7+
8+
"jasmine": false,
9+
"afterEach": false,
10+
"beforeEach": false,
11+
"ddescribe": false,
12+
"describe": false,
13+
"expect": false,
14+
"iit": false,
15+
"it": false,
16+
"spyOn": false,
17+
"xdescribe": false,
18+
"xit": false
19+
}
20+
}

test/bower_overrides.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"jquery-simulate": {
3+
"main": "jquery.simulate.js",
4+
"dependencies": {
5+
"jquery": ""
6+
}
7+
},
8+
"angular": {
9+
"dependencies": {
10+
"jquery": ""
11+
}
12+
}
13+
}

test/karma.conf.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Karma configuration
2+
// Generated on Sat Dec 28 2013 20:27:08 GMT+0100 (CET)
3+
4+
'use strict';
5+
6+
module.exports = function(config) {
7+
var wiredep = require('wiredep');
8+
9+
var fs = require('fs');
10+
var bowerOverrides = JSON.parse(fs.readFileSync('./test/bower_overrides.json'));
11+
12+
var devJSDependencies = wiredep({
13+
devDependencies: true,
14+
overrides: bowerOverrides
15+
}).js;
16+
17+
config.set({
18+
19+
// base path, that will be used to resolve files and exclude
20+
basePath: '..',
21+
22+
// frameworks to use
23+
frameworks: ['jasmine'],
24+
25+
// list of files / patterns to load in the browser
26+
files: devJSDependencies.concat([
27+
'test/libs/jquery.simulate.dragandrevert.js',
28+
'angular-sortable.js',
29+
'test/sortable.test-helper.js',
30+
'test/sortable.test-directives.js',
31+
'test/spec/*.js',
32+
'angular-sortable.css'
33+
]),
34+
35+
// list of files to exclude
36+
exclude: [
37+
38+
],
39+
40+
41+
// test results reporter to use
42+
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
43+
// reporters: ['progress'],
44+
45+
46+
// web server port
47+
port: 9876,
48+
49+
50+
// enable / disable colors in the output (reporters and logs)
51+
colors: true,
52+
53+
54+
// level of logging
55+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
56+
logLevel: config.LOG_INFO,
57+
58+
59+
// enable / disable watching file and executing tests whenever any file changes
60+
autoWatch: false,
61+
62+
63+
// Start these browsers, currently available:
64+
// - Chrome
65+
// - ChromeCanary
66+
// - Firefox
67+
// - Opera (has to be installed with `npm install karma-opera-launcher`)
68+
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
69+
// - PhantomJS
70+
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
71+
browsers: ['Chrome', 'Firefox', 'PhantomJS'],
72+
73+
74+
// If browser does not capture in given timeout [ms], kill it
75+
captureTimeout: 60000,
76+
77+
78+
// Continuous Integration mode
79+
// if true, it capture browsers, run tests and exit
80+
singleRun: false
81+
});
82+
};
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);

test/sortable.e2e.callbacks.spec.js

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
'use strict';
2+
3+
describe('uiSortable', function() {
4+
5+
// Ensure the sortable angular module is loaded
6+
beforeEach(module('ui.sortable'));
7+
beforeEach(module('ui.sortable.testHelper'));
8+
9+
var EXTRA_DY_PERCENTAGE, listContent;
10+
11+
beforeEach(inject(function (sortableTestHelper) {
12+
EXTRA_DY_PERCENTAGE = sortableTestHelper.EXTRA_DY_PERCENTAGE;
13+
listContent = sortableTestHelper.listContent;
14+
}));
15+
16+
describe('Callbacks related', function() {
17+
18+
var host;
19+
20+
beforeEach(inject(function() {
21+
host = $('<div id="test-host"></div>');
22+
$('body').append(host);
23+
}));
24+
25+
afterEach(function() {
26+
host.remove();
27+
host = null;
28+
});
29+
30+
it('should cancel sorting of node "Two"', function() {
31+
inject(function($compile, $rootScope) {
32+
var element;
33+
element = $compile('<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($rootScope);
34+
$rootScope.$apply(function() {
35+
$rootScope.opts = {
36+
update: function(e, ui) {
37+
if (ui.item.scope().item === 'Two') {
38+
ui.item.sortable.cancel();
39+
}
40+
}
41+
};
42+
$rootScope.items = ['One', 'Two', 'Three'];
43+
});
44+
45+
host.append(element);
46+
47+
var li = element.find(':eq(1)');
48+
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
49+
li.simulate('drag', { dy: dy });
50+
expect($rootScope.items).toEqual(['One', 'Two', 'Three']);
51+
expect($rootScope.items).toEqual(listContent(element));
52+
53+
li = element.find(':eq(0)');
54+
dy = (2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
55+
li.simulate('drag', { dy: dy });
56+
expect($rootScope.items).toEqual(['Two', 'Three', 'One']);
57+
expect($rootScope.items).toEqual(listContent(element));
58+
59+
li = element.find(':eq(2)');
60+
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
61+
li.simulate('drag', { dy: dy });
62+
expect($rootScope.items).toEqual(['One', 'Two', 'Three']);
63+
expect($rootScope.items).toEqual(listContent(element));
64+
65+
$(element).remove();
66+
});
67+
});
68+
69+
it('should cancel sorting of node "Two" and "helper: function" that returns a list element is used', function() {
70+
inject(function($compile, $rootScope) {
71+
var element;
72+
element = $compile('<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($rootScope);
73+
$rootScope.$apply(function() {
74+
$rootScope.opts = {
75+
update: function(e, ui) {
76+
if (ui.item.scope().item === 'Two') {
77+
ui.item.sortable.cancel();
78+
}
79+
}
80+
};
81+
$rootScope.items = ['One', 'Two', 'Three'];
82+
});
83+
84+
host.append(element);
85+
86+
var li = element.find(':eq(1)');
87+
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
88+
li.simulate('drag', { dy: dy });
89+
expect($rootScope.items).toEqual(['One', 'Two', 'Three']);
90+
expect($rootScope.items).toEqual(listContent(element));
91+
92+
li = element.find(':eq(0)');
93+
dy = (2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
94+
li.simulate('drag', { dy: dy });
95+
expect($rootScope.items).toEqual(['Two', 'Three', 'One']);
96+
expect($rootScope.items).toEqual(listContent(element));
97+
98+
li = element.find(':eq(2)');
99+
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
100+
li.simulate('drag', { dy: dy });
101+
expect($rootScope.items).toEqual(['One', 'Two', 'Three']);
102+
expect($rootScope.items).toEqual(listContent(element));
103+
104+
$(element).remove();
105+
});
106+
});
107+
108+
it('should update model from update() callback', function() {
109+
inject(function($compile, $rootScope) {
110+
var element, logsElement;
111+
element = $compile('<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($rootScope);
112+
logsElement = $compile('<ul ng-model="logs"><li ng-repeat="log in logs" id="l-{{$index}}">{{ log }}</li></ul>')($rootScope);
113+
$rootScope.$apply(function() {
114+
$rootScope.opts = {
115+
update: function(e, ui) {
116+
$rootScope.logs.push('Moved element ' + ui.item.scope().item);
117+
}
118+
};
119+
$rootScope.items = ['One', 'Two', 'Three'];
120+
$rootScope.logs = [];
121+
});
122+
123+
host.append(element).append(logsElement);
124+
125+
var li = element.find(':eq(1)');
126+
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
127+
li.simulate('drag', { dy: dy });
128+
expect($rootScope.items).toEqual(['One', 'Three', 'Two']);
129+
expect($rootScope.logs).toEqual(['Moved element Two']);
130+
expect($rootScope.items).toEqual(listContent(element));
131+
expect($rootScope.logs).toEqual(listContent(logsElement));
132+
133+
$(element).remove();
134+
$(logsElement).remove();
135+
});
136+
});
137+
138+
// ensure scope.apply() is called after a stop() callback
139+
it('should update model from stop() callback', function() {
140+
inject(function($compile, $rootScope) {
141+
var element, logsElement;
142+
element = $compile('<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($rootScope);
143+
logsElement = $compile('<ul ng-model="logs"><li ng-repeat="log in logs" id="l-{{$index}}">{{ log }}</li></ul>')($rootScope);
144+
$rootScope.$apply(function() {
145+
$rootScope.opts = {
146+
stop: function(e, ui) {
147+
$rootScope.logs.push('Moved element ' + ui.item.scope().item);
148+
}
149+
};
150+
$rootScope.items = ['One', 'Two', 'Three'];
151+
$rootScope.logs = [];
152+
});
153+
154+
host.append(element).append(logsElement);
155+
156+
var li = element.find(':eq(1)');
157+
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
158+
li.simulate('drag', { dy: dy });
159+
expect($rootScope.items).toEqual(['One', 'Three', 'Two']);
160+
expect($rootScope.logs).toEqual(['Moved element Two']);
161+
expect($rootScope.items).toEqual(listContent(element));
162+
expect($rootScope.logs).toEqual(listContent(logsElement));
163+
164+
$(element).remove();
165+
$(logsElement).remove();
166+
});
167+
});
168+
169+
it('should call the create() callback when initialized', function() {
170+
inject(function($compile, $rootScope) {
171+
var element;
172+
$rootScope.$apply(function() {
173+
$rootScope.items = ['One', 'Two', 'Three'];
174+
$rootScope.opts = {
175+
create: function() {
176+
177+
}
178+
};
179+
spyOn($rootScope.opts, 'create');
180+
element = $compile('<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($rootScope);
181+
});
182+
183+
host.append(element);
184+
185+
expect($rootScope.opts.create).toHaveBeenCalled();
186+
187+
$(element).remove();
188+
});
189+
});
190+
191+
});
192+
193+
});

0 commit comments

Comments
 (0)