aboutsummaryrefslogtreecommitdiff
path: root/test/unit/specs/services/gesture_service/gesture_service.spec.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-03-30 12:31:50 +0200
committerHenry Jameson <me@hjkos.com>2019-03-30 12:31:50 +0200
commit9f4a9bff464e43e1c01d621e8c55db6105d327de (patch)
tree3124790d8a00ef148acb199efeac59594879f875 /test/unit/specs/services/gesture_service/gesture_service.spec.js
parente89a62200532a4d61de35d73299c33555aad8bed (diff)
parent0117f6af9f8ae600e613402590de4c9364806967 (diff)
Merge remote-tracking branch 'upstream/develop' into minimal-scopes-mode
* upstream/develop: (173 commits) Fix: Change condition fix typo update store according to retweeted status #433 - update sort by for conversation display replies_count right after reply icon expose replies_count from mastodon api Apparently, MastoAPI gives status in ancestors if you try opening a repeat... make side drawer use gesture service and fix its animations review/remove error hiding errata review #433 - sort conversation for retweets and clean up Revert "Merge branch 'revert-987b5162' into 'develop'" Revert "Merge branch 'mastoapi/friends-tl' into 'develop'" Add await to login action' Remove console log Fix warnings in user profile routing Add tests for gesture service, fix bug with perpendicular directions #255 - clean up autocomplete form #255 - clean up user settings page with self-closing html tags ...
Diffstat (limited to 'test/unit/specs/services/gesture_service/gesture_service.spec.js')
-rw-r--r--test/unit/specs/services/gesture_service/gesture_service.spec.js120
1 files changed, 120 insertions, 0 deletions
diff --git a/test/unit/specs/services/gesture_service/gesture_service.spec.js b/test/unit/specs/services/gesture_service/gesture_service.spec.js
new file mode 100644
index 00000000..4a1b009a
--- /dev/null
+++ b/test/unit/specs/services/gesture_service/gesture_service.spec.js
@@ -0,0 +1,120 @@
+import GestureService from 'src/services/gesture_service/gesture_service.js'
+
+const mockTouchEvent = (x, y) => ({
+ touches: [
+ {
+ screenX: x,
+ screenY: y
+ }
+ ]
+})
+
+describe.only('GestureService', () => {
+ describe('swipeGesture', () => {
+ it('calls the callback on a successful swipe', () => {
+ let swiped = false
+ const callback = () => { swiped = true }
+ const gesture = GestureService.swipeGesture(
+ GestureService.DIRECTION_RIGHT,
+ callback
+ )
+
+ GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
+ GestureService.updateSwipe(mockTouchEvent(200, 100), gesture)
+
+ expect(swiped).to.eql(true)
+ })
+
+ it('calls the callback only once per begin', () => {
+ let hits = 0
+ const callback = () => { hits += 1 }
+ const gesture = GestureService.swipeGesture(
+ GestureService.DIRECTION_RIGHT,
+ callback
+ )
+
+ GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
+ GestureService.updateSwipe(mockTouchEvent(150, 100), gesture)
+ GestureService.updateSwipe(mockTouchEvent(200, 100), gesture)
+
+ expect(hits).to.eql(1)
+ })
+
+ it('doesn\'t call the callback on an opposite swipe', () => {
+ let swiped = false
+ const callback = () => { swiped = true }
+ const gesture = GestureService.swipeGesture(
+ GestureService.DIRECTION_RIGHT,
+ callback
+ )
+
+ GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
+ GestureService.updateSwipe(mockTouchEvent(0, 100), gesture)
+
+ expect(swiped).to.eql(false)
+ })
+
+ it('doesn\'t call the callback on a swipe below threshold', () => {
+ let swiped = false
+ const callback = () => { swiped = true }
+ const gesture = GestureService.swipeGesture(
+ GestureService.DIRECTION_RIGHT,
+ callback,
+ 100
+ )
+
+ GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
+ GestureService.updateSwipe(mockTouchEvent(150, 100), gesture)
+
+ expect(swiped).to.eql(false)
+ })
+
+ it('doesn\'t call the callback on a perpendicular swipe', () => {
+ let swiped = false
+ const callback = () => { swiped = true }
+ const gesture = GestureService.swipeGesture(
+ GestureService.DIRECTION_RIGHT,
+ callback,
+ 30,
+ 0.5
+ )
+
+ GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
+ GestureService.updateSwipe(mockTouchEvent(150, 200), gesture)
+
+ expect(swiped).to.eql(false)
+ })
+
+ it('calls the callback on perpendicular swipe if within tolerance', () => {
+ let swiped = false
+ const callback = () => { swiped = true }
+ const gesture = GestureService.swipeGesture(
+ GestureService.DIRECTION_RIGHT,
+ callback,
+ 30,
+ 2.0
+ )
+
+ GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
+ GestureService.updateSwipe(mockTouchEvent(150, 150), gesture)
+
+ expect(swiped).to.eql(true)
+ })
+
+ it('works with any arbitrary 2d directions', () => {
+ let swiped = false
+ const callback = () => { swiped = true }
+ const gesture = GestureService.swipeGesture(
+ [-1, -1],
+ callback,
+ 30,
+ 0.1
+ )
+
+ GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
+ GestureService.updateSwipe(mockTouchEvent(60, 60), gesture)
+
+ expect(swiped).to.eql(true)
+ })
+ })
+})