From d155d2c211389b67b5c24f5f16bce91fb310b69d Mon Sep 17 00:00:00 2001 From: Jared Friese Date: Wed, 15 Apr 2020 15:46:02 +1000 Subject: [PATCH] Add documentation for UIToolbar changes --- Documentation/UIToolbar.md | 16 ++++++++++++++++ .../CoreExtensions/Toolbar/UIToolbar+Fleet.swift | 11 +++++++++++ README.md | 1 + 3 files changed, 28 insertions(+) create mode 100644 Documentation/UIToolbar.md diff --git a/Documentation/UIToolbar.md b/Documentation/UIToolbar.md new file mode 100644 index 0000000..2ece83f --- /dev/null +++ b/Documentation/UIToolbar.md @@ -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. +``` diff --git a/Fleet/CoreExtensions/Toolbar/UIToolbar+Fleet.swift b/Fleet/CoreExtensions/Toolbar/UIToolbar+Fleet.swift index e0247d9..2ae8bb5 100644 --- a/Fleet/CoreExtensions/Toolbar/UIToolbar+Fleet.swift +++ b/Fleet/CoreExtensions/Toolbar/UIToolbar+Fleet.swift @@ -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() diff --git a/README.md b/README.md index 551d6f9..e13afe1 100644 --- a/README.md +++ b/README.md @@ -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