Skip to content

Commit

Permalink
Add documentation for UIToolbar changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwfriese committed Apr 15, 2020
1 parent 050e2c9 commit d155d2c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Documentation/UIToolbar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## UIToolbar

Unit testing the behavior of items on `UIToolbar`s through UIKit is ordinarily a challenge because of how
difficult accessing the toolbar items directly can be.

Fleet aims to erase this pain by providing a way to "tap" on tooltip items in-test to fire their associated handlers.

Suppose you have a `UIToolbar` set up on a page in your storyboard. With Fleet, you can unit test the behavior of
tapping that toolbar's items much more easily than before. With one simple line of code, an item's handler can be fired:
```swift
// Suppose we have items in a toolbar associated with `navigationController`
let toolbar = navigationController.toolbar!
toolbar.tapItem(withTitle: "Some Item")

// Now you can make any assertions you'd like on the behavior of tapping that item.
```
11 changes: 11 additions & 0 deletions Fleet/CoreExtensions/Toolbar/UIToolbar+Fleet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ extension Fleet {
}

extension UIToolbar {
/**
Mimics a tap on the toolbar item with the given title,
firing any associated behavior.
- parameters:
- title: The title of the item to tap
- throws:
A `FleetError` if a toolbar item with the given title cannot be found, if there
in the are no items in the toolbar, or if the item's action is not properly set up.
*/
public func tapItem(withTitle title: String) {
guard let toolbarItems = items else {
FleetError(Fleet.ToolbarError.noToolbarItems).raise()
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Fleet extends UIKit classes in order to make it easier to test your code's inter
- [UITextField](./Documentation/UITextField.md) - Provides convenience methods for entering text. (iOS-only)
- [UISwitch](./Documentation/UISwitch.md) - Provides convenience methods for interacting with switches in test. (iOS-only)
- [UITextView](./Documentation/UITextView.md) - Provides convenience methods for entering text into a text view. (iOS-only)
- [UIToolbar](./Documentation/UIToolbar.md) - Tap on items in a toolbar. (iOS-only)

### Setup for view controller tests
Fleet provides another method of help in setting up view controller alongside storyboard injection and mocking. It makes it easy
Expand Down

0 comments on commit d155d2c

Please sign in to comment.