-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create PanGestureOverlayTranslationDriverTests
- Loading branch information
1 parent
80ab88d
commit d50800c
Showing
5 changed files
with
147 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// PanGestureOverlayTranslationDriverTests.swift | ||
// OverlayContainer | ||
// | ||
// Created by Gaétan Zanella on 21/04/2021. | ||
// Copyright © 2021 Gaétan Zanella. All rights reserved. | ||
// | ||
|
||
import Quick | ||
import Nimble | ||
@testable import OverlayContainer | ||
|
||
class FakeOverlayTranslationGestureRecognizer: OverlayTranslationGestureRecognizer { | ||
|
||
var isCancelled = false | ||
|
||
var mutableView: UIView? | ||
|
||
var translation: CGPoint = .zero | ||
|
||
override var view: UIView? { | ||
mutableView | ||
} | ||
|
||
override func translation(in view: UIView?) -> CGPoint { | ||
translation | ||
} | ||
|
||
func changeState(_ state: State) { | ||
self.state = state | ||
(target as! NSObject).perform(action, with: self) | ||
} | ||
|
||
private var target: Any! | ||
private var action: Selector! | ||
|
||
override func addTarget(_ target: Any, action: Selector) { | ||
self.target = target | ||
self.action = action | ||
} | ||
|
||
override func cancel() { | ||
isCancelled = true | ||
} | ||
} | ||
|
||
class PanGestureOverlayTranslationDriverTests: QuickSpec { | ||
|
||
override func spec() { | ||
|
||
var controller: FakeOverlayTranslationController! | ||
var gesture: FakeOverlayTranslationGestureRecognizer! | ||
var driver: PanGestureOverlayTranslationDriver! | ||
|
||
beforeEach { | ||
controller = FakeOverlayTranslationController() | ||
gesture = FakeOverlayTranslationGestureRecognizer() | ||
driver = PanGestureOverlayTranslationDriver( | ||
translationController: controller, | ||
panGestureRecognizer: gesture | ||
) | ||
let view = UIView() | ||
gesture.mutableView = view | ||
} | ||
|
||
it("should not drag not draggable content") { | ||
controller.isDraggable = false | ||
XCTAssertFalse(driver.gestureRecognizerShouldBegin(gesture)) | ||
} | ||
|
||
it("should drag draggable content") { | ||
controller.isDraggable = true | ||
XCTAssertTrue(driver.gestureRecognizerShouldBegin(gesture)) | ||
} | ||
|
||
it("should drag overlay according to the translation") { | ||
XCTAssertFalse(controller.isInTranslation) | ||
gesture.changeState(.began) | ||
XCTAssertTrue(controller.isInTranslation) | ||
gesture.translation.y = -100 | ||
gesture.changeState(.changed) | ||
XCTAssertEqual(controller.translationHeight, 100) | ||
gesture.translation.y = -90 | ||
gesture.changeState(.changed) | ||
XCTAssertEqual(controller.translationHeight, 90) | ||
gesture.changeState(.ended) | ||
XCTAssertFalse(controller.isInTranslation) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// FakeOverlayTranslationController.swift | ||
// OverlayContainer_Tests | ||
// | ||
// Created by Gaétan Zanella on 21/04/2021. | ||
// Copyright © 2021 Gaétan Zanella. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
@testable import OverlayContainer | ||
|
||
class FakeOverlayTranslationController: OverlayTranslationController { | ||
|
||
var lastTranslationEndNotchIndex: Int = 0 | ||
|
||
private var initialTranslationHeight: CGFloat = 0.0 | ||
var translationHeight: CGFloat = 0.0 | ||
|
||
var translationPosition: OverlayTranslationPosition = .bottom | ||
|
||
var isDraggable = true | ||
|
||
private(set) var isInTranslation = false | ||
|
||
var hasReachedANotch = false | ||
|
||
func isDraggable(at point: CGPoint, in coordinateSpace: UICoordinateSpace) -> Bool { | ||
isDraggable | ||
} | ||
|
||
func overlayHasReachedANotch() -> Bool { | ||
hasReachedANotch | ||
} | ||
|
||
func startOverlayTranslation() { | ||
initialTranslationHeight = translationHeight | ||
isInTranslation = true | ||
} | ||
|
||
func dragOverlay(withOffset offset: CGFloat, usesFunction: Bool) { | ||
translationHeight = initialTranslationHeight - offset | ||
} | ||
|
||
func endOverlayTranslation(withVelocity velocity: CGPoint) { | ||
isInTranslation = false | ||
} | ||
} |