Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
87a4f170
Commit
87a4f170
authored
Dec 03, 2021
by
Paul Slaughter
Committed by
Natalia Tepluhina
Dec 03, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve deteriminism of simulateDrag
parent
60fa93af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
12 deletions
+30
-12
app/assets/javascripts/test_utils/simulate_drag.js
app/assets/javascripts/test_utils/simulate_drag.js
+30
-12
No files found.
app/assets/javascripts/test_utils/simulate_drag.js
View file @
87a4f170
...
...
@@ -122,7 +122,6 @@ export default function simulateDrag(options) {
const
firstRect
=
getRect
(
firstEl
);
const
lastRect
=
getRect
(
lastEl
);
const
startTime
=
new
Date
().
getTime
();
const
duration
=
options
.
duration
||
1000
;
simulateEvent
(
fromEl
,
'
pointerdown
'
,
{
...
...
@@ -140,8 +139,28 @@ export default function simulateDrag(options) {
toRect
.
cy
=
lastRect
.
y
+
lastRect
.
h
+
50
;
}
const
dragInterval
=
setInterval
(()
=>
{
const
progress
=
(
new
Date
().
getTime
()
-
startTime
)
/
duration
;
let
startTime
;
// Called within dragFn when the drag should finish
const
finishFn
=
()
=>
{
if
(
options
.
ondragend
)
options
.
ondragend
();
if
(
options
.
performDrop
)
{
simulateEvent
(
toEl
,
'
mouseup
'
);
}
window
.
SIMULATE_DRAG_ACTIVE
=
0
;
};
const
dragFn
=
(
timestamp
)
=>
{
if
(
!
startTime
)
{
startTime
=
timestamp
;
}
const
elapsed
=
timestamp
-
startTime
;
// Make sure that progress maxes at 1
const
progress
=
Math
.
min
(
elapsed
/
duration
,
1
);
const
x
=
fromRect
.
cx
+
(
toRect
.
cx
-
fromRect
.
cx
)
*
progress
;
const
y
=
fromRect
.
cy
+
(
toRect
.
cy
-
fromRect
.
cy
+
options
.
extraHeight
)
*
progress
;
const
overEl
=
fromEl
.
ownerDocument
.
elementFromPoint
(
x
,
y
);
...
...
@@ -152,16 +171,15 @@ export default function simulateDrag(options) {
});
if
(
progress
>=
1
)
{
if
(
options
.
ondragend
)
options
.
ondragend
();
if
(
options
.
performDrop
)
{
simulateEvent
(
toEl
,
'
mouseup
'
);
}
clearInterval
(
dragInterval
);
window
.
SIMULATE_DRAG_ACTIVE
=
0
;
// finish on next frame, so we can pause in the correct position for a frame
requestAnimationFrame
(
finishFn
);
}
else
{
requestAnimationFrame
(
dragFn
);
}
},
100
);
};
// Start the drag animation
requestAnimationFrame
(
dragFn
);
return
{
target
:
fromEl
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment