forked from salemove/ios-sdk-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend TestingApp with UI for visitor info update in acceptance tests
Add UI that allows testing visitor info loading and updating visitor info in acceptance tests. At the moment error handling is not taken into account. MOB-2339
- Loading branch information
1 parent
f149476
commit bab5620
Showing
10 changed files
with
1,614 additions
and
10 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,70 @@ | ||
/// Developer-friendly wrapper around a closure. | ||
/// It makes debugging easier by providing callee information. | ||
/// Note: since closure does not conform to `Equatable`, it will | ||
/// also be ignored in `Equatable` and `Hashable` implementations | ||
/// of `Command`. | ||
/// | ||
/// Example of declaration and execution: | ||
/// ``` | ||
/// let validateEmail = Command<String> { email in /* email validation goes here */ } | ||
/// validateEmail("[email protected]") | ||
/// ``` | ||
struct Command<T>: Hashable { | ||
let tag: String | ||
let file: String | ||
let function: String | ||
let line: UInt | ||
let closure: (T) -> Void | ||
|
||
init( | ||
tag: String = "", | ||
file: StaticString = #file, | ||
function: StaticString = #function, | ||
line: UInt = #line, | ||
closure: @escaping (T) -> Void | ||
) { | ||
self.tag = tag | ||
self.file = "\(file)" | ||
self.function = "\(function)" | ||
self.line = line | ||
self.closure = closure | ||
} | ||
|
||
func execute(with value: T) { | ||
closure(value) | ||
} | ||
|
||
func callAsFunction(_ value: T) { | ||
execute(with: value) | ||
} | ||
|
||
static func == (lhs: Self, rhs: Self) -> Bool { | ||
lhs.tag == rhs.tag && | ||
lhs.file == rhs.file && | ||
lhs.function == rhs.function && | ||
lhs.line == rhs.line | ||
} | ||
|
||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(tag) | ||
hasher.combine(file) | ||
hasher.combine(function) | ||
hasher.combine(line) | ||
} | ||
|
||
/// Command with empty closure. | ||
static var nop: Self { Self(tag: "nop", closure: { _ in }) } | ||
} | ||
|
||
/// A shorthand for Command for closure with zero parameters. | ||
typealias Cmd = Command<Void> | ||
|
||
extension Cmd { | ||
func execute() where T == Void { | ||
self.execute(with: ()) | ||
} | ||
|
||
func callAsFunction() { | ||
execute() | ||
} | ||
} |
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,43 @@ | ||
import UIKit | ||
|
||
extension UIView { | ||
/// Checks if current view is firstResponder, if not check the same | ||
/// for every subview. This is handy when we need to know if keyboard | ||
/// is presented at the moment by the view or its subviews. | ||
/// - Returns: `true` if view or subviews has `isFirstResponder` set to `true`. | ||
func isKeyboardPresented() -> Bool { | ||
Self.hasResponder(self) | ||
} | ||
|
||
private static func hasResponder(_ view: UIView) -> Bool { | ||
if view.isFirstResponder { | ||
return true | ||
} | ||
for subview in view.subviews { | ||
if hasResponder(subview) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
/// Search for superview in view hierarchy using predicate closure. | ||
/// This is useful when we need to get access from cell to table view for | ||
/// example. | ||
/// - Parameter predicate: Closure that receives view, as parameter, | ||
/// to be inspected by the predicate. `superview` traversal is stopped when there's no `superview` | ||
/// or if `superview` matches predicate. | ||
/// - Returns: View that matches predicate or nil otherwise. | ||
func superview(by predicate: (UIView) -> Bool) -> UIView? { | ||
if let superview { | ||
if predicate(superview) { | ||
return superview | ||
} else { | ||
return superview.superview(by: predicate) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
Oops, something went wrong.