summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/test_utils
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-02-17 14:44:39 +0000
committerPhil Hughes <me@iamphill.com>2017-02-17 14:44:39 +0000
commit034397d31f0ff64771520e8ee0cc745d793f31e4 (patch)
treea9661a6a406b09320a8cbfe6eb02d06e64d0a495 /app/assets/javascripts/test_utils
parent3ab101ccb16eaa19b41cd8825299d811f142c044 (diff)
downloadgitlab-ce-034397d31f0ff64771520e8ee0cc745d793f31e4.tar.gz
This should make the ordering feature specs more reliable
Diffstat (limited to 'app/assets/javascripts/test_utils')
-rw-r--r--app/assets/javascripts/test_utils/simulate_drag.js36
1 files changed, 24 insertions, 12 deletions
diff --git a/app/assets/javascripts/test_utils/simulate_drag.js b/app/assets/javascripts/test_utils/simulate_drag.js
index b49f8310c2a..d48f2404fa5 100644
--- a/app/assets/javascripts/test_utils/simulate_drag.js
+++ b/app/assets/javascripts/test_utils/simulate_drag.js
@@ -43,7 +43,14 @@
return event;
}
- function getTraget(target) {
+ function isLast(target) {
+ var el = typeof target.el === 'string' ? document.getElementById(target.el.substr(1)) : target.el;
+ var children = el.children;
+
+ return children.length - 1 === target.index;
+ }
+
+ function getTarget(target) {
var el = typeof target.el === 'string' ? document.getElementById(target.el.substr(1)) : target.el;
var children = el.children;
@@ -55,13 +62,6 @@
);
}
- function isLast(target) {
- var el = typeof target.el === 'string' ? document.getElementById(target.el.substr(1)) : target.el;
- var children = el.children;
-
- return children.length - 1 === target.index;
- }
-
function getRect(el) {
var rect = el.getBoundingClientRect();
var width = rect.right - rect.left;
@@ -82,12 +82,22 @@
function simulateDrag(options, callback) {
options.to.el = options.to.el || options.from.el;
- var fromEl = getTraget(options.from);
- var toEl = getTraget(options.to);
+ var fromEl = getTarget(options.from);
+ var toEl = getTarget(options.to);
+ var firstEl = getTarget({
+ el: options.to.el,
+ index: 'first'
+ });
+ var lastEl = getTarget({
+ el: options.to.el,
+ index: 'last'
+ });
var scrollable = options.scrollable;
var fromRect = getRect(fromEl);
var toRect = getRect(toEl);
+ var firstRect = getRect(firstEl);
+ var lastRect = getRect(lastEl);
var startTime = new Date().getTime();
var duration = options.duration || 1000;
@@ -95,8 +105,10 @@
options.ontap && options.ontap();
window.SIMULATE_DRAG_ACTIVE = 1;
- if (isLast(options.to)) {
- toRect.cy += 100;
+ if (options.to.index === 0) {
+ toRect.cy = firstRect.y;
+ } else if (isLast(options.to)) {
+ toRect.cy = lastRect.y + lastRect.h + 50;
}
var dragInterval = setInterval(function loop() {