forked from adopted-ember-addons/ember-sortable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reorder.js
56 lines (46 loc) · 1.31 KB
/
reorder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { registerAsyncHelper } from '@ember/test';
/**
In tests, the dummy app is rendered at half size.
To avoid rounding errors, we must therefore double
the overshoot.
*/
const OVERSHOOT = 2;
/**
Reorders elements to the specified state.
Examples
reorder(
'mouse',
'.some-list li',
'[data-id="66278893"]',
'[data-id="66278894"]',
'[data-id="66278892"]'
);
@method reorder
@param {'mouse'|'touch'} [mode]
event mode
@param {String} [itemSelector]
selector for all items
@param {...String} [resultSelectors]
selectors for the resultant order
@return {Promise}
*/
export function reorder(app, mode, itemSelector, ...resultSelectors) {
const {
andThen,
drag,
findWithAssert,
wait
} = app.testHelpers;
resultSelectors.forEach((selector, targetIndex) => {
andThen(() => {
let items = findWithAssert(itemSelector);
let element = items.filter(selector);
let targetElement = items.eq(targetIndex);
let dx = targetElement.offset().left - OVERSHOOT - element.offset().left;
let dy = targetElement.offset().top - OVERSHOOT - element.offset().top;
drag(mode, element, () => { return { dx: dx, dy: dy }; });
});
});
return wait();
}
export default registerAsyncHelper('reorder', reorder);