@enact/spotlight 3.4.9-experimental-3 → 3.4.9-experimental-7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
- package/Accelerator/Accelerator.js +149 -156
- package/CHANGELOG.md +22 -0
- package/{build/Pause → Pause}/Pause.d.ts +0 -0
- package/Pause/Pause.js +102 -80
- package/Pause/tests/Pause-specs.js +65 -97
- package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
- package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
- package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
- package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
- package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
- package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
- package/Spottable/Spottable.js +448 -410
- package/Spottable/tests/Spottable-specs.js +90 -117
- package/package.json +3 -2
- package/src/container.js +718 -653
- package/src/navigate.js +406 -491
- package/src/pointer.js +86 -78
- package/{build/src → src}/spotlight.d.ts +0 -0
- package/src/spotlight.js +846 -885
- package/src/target.js +448 -474
- package/src/tests/container-specs.js +643 -1251
- package/src/tests/navigate-specs.js +77 -134
- package/src/tests/pointer-specs.js +126 -182
- package/src/tests/spotlight-specs.js +103 -133
- package/src/tests/target-specs.js +597 -960
- package/src/tests/utils.js +89 -67
- package/src/utils.js +155 -158
- package/build/Accelerator/Accelerator.js +0 -162
- package/build/Accelerator/package.json +0 -3
- package/build/CHANGELOG.md +0 -838
- package/build/Pause/Pause.js +0 -164
- package/build/Pause/package.json +0 -3
- package/build/Pause/tests/Pause-specs.js +0 -65
- package/build/README.md +0 -61
- package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
- package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
- package/build/SpotlightContainerDecorator/package.json +0 -3
- package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
- package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
- package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
- package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
- package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
- package/build/SpotlightRootDecorator/package.json +0 -3
- package/build/Spottable/Spottable.js +0 -491
- package/build/Spottable/package.json +0 -3
- package/build/Spottable/tests/Spottable-specs.js +0 -90
- package/build/package-lock.json +0 -229
- package/build/package.json +0 -28
- package/build/src/container.js +0 -1201
- package/build/src/navigate.js +0 -419
- package/build/src/pointer.js +0 -183
- package/build/src/spotlight.js +0 -896
- package/build/src/target.js +0 -507
- package/build/src/tests/container-specs.js +0 -653
- package/build/src/tests/navigate-specs.js +0 -87
- package/build/src/tests/pointer-specs.js +0 -130
- package/build/src/tests/spotlight-specs.js +0 -112
- package/build/src/tests/target-specs.js +0 -614
- package/build/src/tests/utils.js +0 -104
- package/build/src/utils.js +0 -180
- package/build/styles/debug.less +0 -97
- package/build/styles/mixins.less +0 -63
- package/docs/index.md +0 -364
|
@@ -1,144 +1,87 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
function getRect (top, left, height, width, elem) {
|
|
5
|
-
const rect = {
|
|
6
|
-
left,
|
|
7
|
-
top,
|
|
8
|
-
width,
|
|
9
|
-
height
|
|
10
|
-
};
|
|
11
|
-
rect.element = elem;
|
|
12
|
-
rect.right = rect.left + rect.width;
|
|
13
|
-
rect.bottom = rect.top + rect.height;
|
|
14
|
-
rect.center = {
|
|
15
|
-
x: rect.left + Math.floor(rect.width / 2),
|
|
16
|
-
y: rect.top + Math.floor(rect.height / 2)
|
|
17
|
-
};
|
|
18
|
-
rect.center.left = rect.center.right = rect.center.x;
|
|
19
|
-
rect.center.top = rect.center.bottom = rect.center.y;
|
|
20
|
-
return rect;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
describe('navigate', () => {
|
|
24
|
-
test('should return the element above when direction="up"', () => {
|
|
25
|
-
const targetRect = getRect(100, 100, 10, 10);
|
|
26
|
-
const rects = [
|
|
27
|
-
[100, 110, 10, 10, 'right'],
|
|
28
|
-
[100, 90, 10, 10, 'left'],
|
|
29
|
-
[90, 100, 10, 10, 'above'],
|
|
30
|
-
[110, 100, 10, 10, 'below']
|
|
31
|
-
].map(args => getRect(...args));
|
|
32
|
-
|
|
33
|
-
const expected = 'above';
|
|
34
|
-
const actual = navigate(
|
|
35
|
-
targetRect,
|
|
36
|
-
'up',
|
|
37
|
-
rects,
|
|
38
|
-
{}
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
expect(actual).toBe(expected);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('should return the element to the left when direction="left"', () => {
|
|
45
|
-
const targetRect = getRect(100, 100, 10, 10);
|
|
46
|
-
const rects = [
|
|
47
|
-
[100, 110, 10, 10, 'right'],
|
|
48
|
-
[100, 90, 10, 10, 'left'],
|
|
49
|
-
[90, 100, 10, 10, 'above'],
|
|
50
|
-
[110, 100, 10, 10, 'below']
|
|
51
|
-
].map(args => getRect(...args));
|
|
3
|
+
var _navigate = _interopRequireDefault(require("../navigate"));
|
|
52
4
|
|
|
53
|
-
|
|
54
|
-
const actual = navigate(
|
|
55
|
-
targetRect,
|
|
56
|
-
'left',
|
|
57
|
-
rects,
|
|
58
|
-
{}
|
|
59
|
-
);
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
60
6
|
|
|
61
|
-
|
|
62
|
-
});
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
63
8
|
|
|
64
|
-
|
|
65
|
-
const targetRect = getRect(100, 100, 10, 10);
|
|
66
|
-
const rects = [
|
|
67
|
-
[100, 110, 10, 10, 'right'],
|
|
68
|
-
[100, 90, 10, 10, 'left'],
|
|
69
|
-
[90, 100, 10, 10, 'above'],
|
|
70
|
-
[110, 100, 10, 10, 'below']
|
|
71
|
-
].map(args => getRect(...args));
|
|
9
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
72
10
|
|
|
73
|
-
|
|
74
|
-
const actual = navigate(
|
|
75
|
-
targetRect,
|
|
76
|
-
'down',
|
|
77
|
-
rects,
|
|
78
|
-
{}
|
|
79
|
-
);
|
|
11
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
80
12
|
|
|
81
|
-
|
|
82
|
-
});
|
|
13
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
83
14
|
|
|
84
|
-
|
|
85
|
-
const targetRect = getRect(100, 100, 10, 10);
|
|
86
|
-
const rects = [
|
|
87
|
-
[100, 110, 10, 10, 'right'],
|
|
88
|
-
[100, 90, 10, 10, 'left'],
|
|
89
|
-
[90, 100, 10, 10, 'above'],
|
|
90
|
-
[110, 100, 10, 10, 'below']
|
|
91
|
-
].map(args => getRect(...args));
|
|
15
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
92
16
|
|
|
93
|
-
|
|
94
|
-
const actual = navigate(
|
|
95
|
-
targetRect,
|
|
96
|
-
'right',
|
|
97
|
-
rects,
|
|
98
|
-
{}
|
|
99
|
-
);
|
|
17
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
100
18
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)).toBe('under');
|
|
121
|
-
|
|
122
|
-
expect(navigate(
|
|
123
|
-
targetRect,
|
|
124
|
-
'down',
|
|
125
|
-
rects,
|
|
126
|
-
{}
|
|
127
|
-
)).toBe('below');
|
|
128
|
-
|
|
129
|
-
expect(navigate(
|
|
130
|
-
targetRect,
|
|
131
|
-
'left',
|
|
132
|
-
rects,
|
|
133
|
-
{}
|
|
134
|
-
)).toBe('left');
|
|
19
|
+
// loose copy from utils/getRect to fabricate a rect for navigation
|
|
20
|
+
function getRect(top, left, height, width, elem) {
|
|
21
|
+
var rect = {
|
|
22
|
+
left: left,
|
|
23
|
+
top: top,
|
|
24
|
+
width: width,
|
|
25
|
+
height: height
|
|
26
|
+
};
|
|
27
|
+
rect.element = elem;
|
|
28
|
+
rect.right = rect.left + rect.width;
|
|
29
|
+
rect.bottom = rect.top + rect.height;
|
|
30
|
+
rect.center = {
|
|
31
|
+
x: rect.left + Math.floor(rect.width / 2),
|
|
32
|
+
y: rect.top + Math.floor(rect.height / 2)
|
|
33
|
+
};
|
|
34
|
+
rect.center.left = rect.center.right = rect.center.x;
|
|
35
|
+
rect.center.top = rect.center.bottom = rect.center.y;
|
|
36
|
+
return rect;
|
|
37
|
+
}
|
|
135
38
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
39
|
+
describe('navigate', function () {
|
|
40
|
+
test('should return the element above when direction="up"', function () {
|
|
41
|
+
var targetRect = getRect(100, 100, 10, 10);
|
|
42
|
+
var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 100, 10, 10, 'above'], [110, 100, 10, 10, 'below']].map(function (args) {
|
|
43
|
+
return getRect.apply(void 0, _toConsumableArray(args));
|
|
44
|
+
});
|
|
45
|
+
var expected = 'above';
|
|
46
|
+
var actual = (0, _navigate["default"])(targetRect, 'up', rects, {});
|
|
47
|
+
expect(actual).toBe(expected);
|
|
48
|
+
});
|
|
49
|
+
test('should return the element to the left when direction="left"', function () {
|
|
50
|
+
var targetRect = getRect(100, 100, 10, 10);
|
|
51
|
+
var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 100, 10, 10, 'above'], [110, 100, 10, 10, 'below']].map(function (args) {
|
|
52
|
+
return getRect.apply(void 0, _toConsumableArray(args));
|
|
53
|
+
});
|
|
54
|
+
var expected = 'left';
|
|
55
|
+
var actual = (0, _navigate["default"])(targetRect, 'left', rects, {});
|
|
56
|
+
expect(actual).toBe(expected);
|
|
57
|
+
});
|
|
58
|
+
test('should return the element below when direction="down"', function () {
|
|
59
|
+
var targetRect = getRect(100, 100, 10, 10);
|
|
60
|
+
var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 100, 10, 10, 'above'], [110, 100, 10, 10, 'below']].map(function (args) {
|
|
61
|
+
return getRect.apply(void 0, _toConsumableArray(args));
|
|
62
|
+
});
|
|
63
|
+
var expected = 'below';
|
|
64
|
+
var actual = (0, _navigate["default"])(targetRect, 'down', rects, {});
|
|
65
|
+
expect(actual).toBe(expected);
|
|
66
|
+
});
|
|
67
|
+
test('should return the element to the right when direction="right"', function () {
|
|
68
|
+
var targetRect = getRect(100, 100, 10, 10);
|
|
69
|
+
var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 100, 10, 10, 'above'], [110, 100, 10, 10, 'below']].map(function (args) {
|
|
70
|
+
return getRect.apply(void 0, _toConsumableArray(args));
|
|
71
|
+
});
|
|
72
|
+
var expected = 'right';
|
|
73
|
+
var actual = (0, _navigate["default"])(targetRect, 'right', rects, {});
|
|
74
|
+
expect(actual).toBe(expected);
|
|
75
|
+
});
|
|
76
|
+
test('should return the element "under" when its center is nearest in that direction', function () {
|
|
77
|
+
var targetRect = getRect(105, 100, 10, 10);
|
|
78
|
+
var rects = [[100, 110, 10, 10, 'right'], [100, 90, 10, 10, 'left'], [90, 90, 30, 30, 'under'], // completely contains the targetRect
|
|
79
|
+
[110, 100, 10, 10, 'below']].map(function (args) {
|
|
80
|
+
return getRect.apply(void 0, _toConsumableArray(args));
|
|
81
|
+
});
|
|
82
|
+
expect((0, _navigate["default"])(targetRect, 'up', rects, {})).toBe('under');
|
|
83
|
+
expect((0, _navigate["default"])(targetRect, 'down', rects, {})).toBe('below');
|
|
84
|
+
expect((0, _navigate["default"])(targetRect, 'left', rects, {})).toBe('left');
|
|
85
|
+
expect((0, _navigate["default"])(targetRect, 'right', rects, {})).toBe('right');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -1,186 +1,130 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
getLastPointerPosition,
|
|
5
|
-
getPointerMode,
|
|
6
|
-
notifyKeyDown,
|
|
7
|
-
notifyPointerMove,
|
|
8
|
-
setPointerMode,
|
|
9
|
-
updatePointerPosition
|
|
10
|
-
} from '../pointer';
|
|
3
|
+
var _keymap = require("@enact/core/keymap");
|
|
11
4
|
|
|
12
|
-
|
|
13
|
-
updatePointerPosition(null, null);
|
|
14
|
-
setPointerMode(true);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
describe('pointer', () => {
|
|
18
|
-
afterEach(reset);
|
|
19
|
-
|
|
20
|
-
describe('#getLastPointerPosition', () => {
|
|
21
|
-
test('should return an object with x and y keys', () => {
|
|
22
|
-
const expected = ['x', 'y'];
|
|
23
|
-
const actual = Object.keys(getLastPointerPosition());
|
|
24
|
-
|
|
25
|
-
expect(actual).toEqual(expected);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('#notifyKeyDown', () => {
|
|
30
|
-
// notifyKeyDown() will start a job which will set pointer mode for `pointerHide` key
|
|
31
|
-
// events. If adding async tests, be sure to pass a callback to notifyKeyDown() to be
|
|
32
|
-
// notified when the job completes before continuing.
|
|
33
|
-
|
|
34
|
-
const keyMap = {
|
|
35
|
-
pointerHide: 999,
|
|
36
|
-
pointerShow: 888
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
beforeAll(() => addAll(keyMap));
|
|
40
|
-
afterAll(() => removeAll(keyMap));
|
|
41
|
-
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
// establish a consistent pointer mode state for each test
|
|
44
|
-
setPointerMode(false);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('should return true for pointer hide key events', () => {
|
|
48
|
-
const expected = true;
|
|
49
|
-
const actual = notifyKeyDown(keyMap.pointerHide);
|
|
50
|
-
|
|
51
|
-
expect(actual).toBe(expected);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('should return true for pointer show key events', () => {
|
|
55
|
-
const expected = true;
|
|
56
|
-
const actual = notifyKeyDown(keyMap.pointerShow);
|
|
57
|
-
|
|
58
|
-
expect(actual).toBe(expected);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('should enable pointer mode for pointer show key events', () => {
|
|
62
|
-
notifyKeyDown(keyMap.pointerShow);
|
|
63
|
-
|
|
64
|
-
const expected = true;
|
|
65
|
-
const actual = getPointerMode();
|
|
66
|
-
|
|
67
|
-
expect(actual).toBe(expected);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('should disable pointer mode for pointer show key events', (done) => {
|
|
71
|
-
setPointerMode(true);
|
|
72
|
-
notifyKeyDown(keyMap.pointerHide, () => {
|
|
73
|
-
const expected = false;
|
|
74
|
-
const actual = getPointerMode();
|
|
75
|
-
|
|
76
|
-
expect(actual).toBe(expected);
|
|
77
|
-
|
|
78
|
-
done();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('should disable pointer mode for non-pointer key events', () => {
|
|
83
|
-
setPointerMode(true);
|
|
84
|
-
notifyKeyDown(12);
|
|
85
|
-
|
|
86
|
-
const expected = false;
|
|
87
|
-
const actual = getPointerMode();
|
|
88
|
-
|
|
89
|
-
expect(actual).toBe(expected);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('#notifyPointerMove', () => {
|
|
94
|
-
test('should update the pointer position if x changes', () => {
|
|
95
|
-
const x = 20;
|
|
96
|
-
|
|
97
|
-
notifyPointerMove(null, null, x, null);
|
|
98
|
-
|
|
99
|
-
const expected = 20;
|
|
100
|
-
const actual = getLastPointerPosition().x;
|
|
5
|
+
var _pointer = require("../pointer");
|
|
101
6
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const y = 20;
|
|
107
|
-
|
|
108
|
-
notifyPointerMove(null, null, null, y);
|
|
109
|
-
|
|
110
|
-
const expected = 20;
|
|
111
|
-
const actual = getLastPointerPosition().y;
|
|
112
|
-
|
|
113
|
-
expect(actual).toBe(expected);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('should enable pointer mode if the pointer positionchanges', () => {
|
|
117
|
-
setPointerMode(false);
|
|
118
|
-
notifyPointerMove(null, null, 5, 5);
|
|
119
|
-
|
|
120
|
-
const expected = true;
|
|
121
|
-
const actual = getPointerMode();
|
|
122
|
-
|
|
123
|
-
expect(actual).toBe(expected);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test('should return false if the pointer has not moved', () => {
|
|
127
|
-
notifyPointerMove(null, null, 5, 5);
|
|
128
|
-
|
|
129
|
-
const expected = false;
|
|
130
|
-
const actual = notifyPointerMove(null, null, 5, 5);
|
|
131
|
-
|
|
132
|
-
expect(actual).toBe(expected);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('should return true if pointer mode was disabled', () => {
|
|
136
|
-
// change into pointer mode indicates a potential for change of focus
|
|
137
|
-
setPointerMode(false);
|
|
138
|
-
|
|
139
|
-
const expected = true;
|
|
140
|
-
const actual = notifyPointerMove(null, null, 5, 5);
|
|
141
|
-
|
|
142
|
-
expect(actual).toBe(expected);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test(
|
|
146
|
-
'should return true if the pointer has moved and current is falsy',
|
|
147
|
-
() => {
|
|
148
|
-
const expected = true;
|
|
149
|
-
const actual = notifyPointerMove(null, null, 5, 5);
|
|
150
|
-
|
|
151
|
-
expect(actual).toBe(expected);
|
|
152
|
-
}
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
test(
|
|
156
|
-
'should return false if the pointer has moved and target is within current',
|
|
157
|
-
() => {
|
|
158
|
-
const current = document.createElement('div');
|
|
159
|
-
const target = document.createElement('div');
|
|
160
|
-
current.appendChild(target);
|
|
161
|
-
|
|
162
|
-
notifyPointerMove(null, current, 5, 5);
|
|
163
|
-
|
|
164
|
-
const expected = false;
|
|
165
|
-
const actual = notifyPointerMove(current, target, 10, 10);
|
|
166
|
-
|
|
167
|
-
expect(actual).toBe(expected);
|
|
168
|
-
}
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
test(
|
|
172
|
-
'should return true if the pointer has moved and target is not within current',
|
|
173
|
-
() => {
|
|
174
|
-
const current = document.createElement('div');
|
|
175
|
-
const target = document.createElement('div');
|
|
176
|
-
|
|
177
|
-
notifyPointerMove(null, current, 5, 5);
|
|
178
|
-
|
|
179
|
-
const expected = true;
|
|
180
|
-
const actual = notifyPointerMove(current, target, 10, 10);
|
|
7
|
+
var reset = function reset() {
|
|
8
|
+
(0, _pointer.updatePointerPosition)(null, null);
|
|
9
|
+
(0, _pointer.setPointerMode)(true);
|
|
10
|
+
};
|
|
181
11
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
12
|
+
describe('pointer', function () {
|
|
13
|
+
afterEach(reset);
|
|
14
|
+
describe('#getLastPointerPosition', function () {
|
|
15
|
+
test('should return an object with x and y keys', function () {
|
|
16
|
+
var expected = ['x', 'y'];
|
|
17
|
+
var actual = Object.keys((0, _pointer.getLastPointerPosition)());
|
|
18
|
+
expect(actual).toEqual(expected);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe('#notifyKeyDown', function () {
|
|
22
|
+
// notifyKeyDown() will start a job which will set pointer mode for `pointerHide` key
|
|
23
|
+
// events. If adding async tests, be sure to pass a callback to notifyKeyDown() to be
|
|
24
|
+
// notified when the job completes before continuing.
|
|
25
|
+
var keyMap = {
|
|
26
|
+
pointerHide: 999,
|
|
27
|
+
pointerShow: 888
|
|
28
|
+
};
|
|
29
|
+
beforeAll(function () {
|
|
30
|
+
return (0, _keymap.addAll)(keyMap);
|
|
31
|
+
});
|
|
32
|
+
afterAll(function () {
|
|
33
|
+
return (0, _keymap.removeAll)(keyMap);
|
|
34
|
+
});
|
|
35
|
+
beforeEach(function () {
|
|
36
|
+
// establish a consistent pointer mode state for each test
|
|
37
|
+
(0, _pointer.setPointerMode)(false);
|
|
38
|
+
});
|
|
39
|
+
test('should return true for pointer hide key events', function () {
|
|
40
|
+
var expected = true;
|
|
41
|
+
var actual = (0, _pointer.notifyKeyDown)(keyMap.pointerHide);
|
|
42
|
+
expect(actual).toBe(expected);
|
|
43
|
+
});
|
|
44
|
+
test('should return true for pointer show key events', function () {
|
|
45
|
+
var expected = true;
|
|
46
|
+
var actual = (0, _pointer.notifyKeyDown)(keyMap.pointerShow);
|
|
47
|
+
expect(actual).toBe(expected);
|
|
48
|
+
});
|
|
49
|
+
test('should enable pointer mode for pointer show key events', function () {
|
|
50
|
+
(0, _pointer.notifyKeyDown)(keyMap.pointerShow);
|
|
51
|
+
var expected = true;
|
|
52
|
+
var actual = (0, _pointer.getPointerMode)();
|
|
53
|
+
expect(actual).toBe(expected);
|
|
54
|
+
});
|
|
55
|
+
test('should disable pointer mode for pointer show key events', function (done) {
|
|
56
|
+
(0, _pointer.setPointerMode)(true);
|
|
57
|
+
(0, _pointer.notifyKeyDown)(keyMap.pointerHide, function () {
|
|
58
|
+
var expected = false;
|
|
59
|
+
var actual = (0, _pointer.getPointerMode)();
|
|
60
|
+
expect(actual).toBe(expected);
|
|
61
|
+
done();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
test('should disable pointer mode for non-pointer key events', function () {
|
|
65
|
+
(0, _pointer.setPointerMode)(true);
|
|
66
|
+
(0, _pointer.notifyKeyDown)(12);
|
|
67
|
+
var expected = false;
|
|
68
|
+
var actual = (0, _pointer.getPointerMode)();
|
|
69
|
+
expect(actual).toBe(expected);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('#notifyPointerMove', function () {
|
|
73
|
+
test('should update the pointer position if x changes', function () {
|
|
74
|
+
var x = 20;
|
|
75
|
+
(0, _pointer.notifyPointerMove)(null, null, x, null);
|
|
76
|
+
var expected = 20;
|
|
77
|
+
var actual = (0, _pointer.getLastPointerPosition)().x;
|
|
78
|
+
expect(actual).toBe(expected);
|
|
79
|
+
});
|
|
80
|
+
test('should update the pointer position if y changes', function () {
|
|
81
|
+
var y = 20;
|
|
82
|
+
(0, _pointer.notifyPointerMove)(null, null, null, y);
|
|
83
|
+
var expected = 20;
|
|
84
|
+
var actual = (0, _pointer.getLastPointerPosition)().y;
|
|
85
|
+
expect(actual).toBe(expected);
|
|
86
|
+
});
|
|
87
|
+
test('should enable pointer mode if the pointer positionchanges', function () {
|
|
88
|
+
(0, _pointer.setPointerMode)(false);
|
|
89
|
+
(0, _pointer.notifyPointerMove)(null, null, 5, 5);
|
|
90
|
+
var expected = true;
|
|
91
|
+
var actual = (0, _pointer.getPointerMode)();
|
|
92
|
+
expect(actual).toBe(expected);
|
|
93
|
+
});
|
|
94
|
+
test('should return false if the pointer has not moved', function () {
|
|
95
|
+
(0, _pointer.notifyPointerMove)(null, null, 5, 5);
|
|
96
|
+
var expected = false;
|
|
97
|
+
var actual = (0, _pointer.notifyPointerMove)(null, null, 5, 5);
|
|
98
|
+
expect(actual).toBe(expected);
|
|
99
|
+
});
|
|
100
|
+
test('should return true if pointer mode was disabled', function () {
|
|
101
|
+
// change into pointer mode indicates a potential for change of focus
|
|
102
|
+
(0, _pointer.setPointerMode)(false);
|
|
103
|
+
var expected = true;
|
|
104
|
+
var actual = (0, _pointer.notifyPointerMove)(null, null, 5, 5);
|
|
105
|
+
expect(actual).toBe(expected);
|
|
106
|
+
});
|
|
107
|
+
test('should return true if the pointer has moved and current is falsy', function () {
|
|
108
|
+
var expected = true;
|
|
109
|
+
var actual = (0, _pointer.notifyPointerMove)(null, null, 5, 5);
|
|
110
|
+
expect(actual).toBe(expected);
|
|
111
|
+
});
|
|
112
|
+
test('should return false if the pointer has moved and target is within current', function () {
|
|
113
|
+
var current = document.createElement('div');
|
|
114
|
+
var target = document.createElement('div');
|
|
115
|
+
current.appendChild(target);
|
|
116
|
+
(0, _pointer.notifyPointerMove)(null, current, 5, 5);
|
|
117
|
+
var expected = false;
|
|
118
|
+
var actual = (0, _pointer.notifyPointerMove)(current, target, 10, 10);
|
|
119
|
+
expect(actual).toBe(expected);
|
|
120
|
+
});
|
|
121
|
+
test('should return true if the pointer has moved and target is not within current', function () {
|
|
122
|
+
var current = document.createElement('div');
|
|
123
|
+
var target = document.createElement('div');
|
|
124
|
+
(0, _pointer.notifyPointerMove)(null, current, 5, 5);
|
|
125
|
+
var expected = true;
|
|
126
|
+
var actual = (0, _pointer.notifyPointerMove)(current, target, 10, 10);
|
|
127
|
+
expect(actual).toBe(expected);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|