Skip to content

Commit

Permalink
Feature/issue57/add assert alert body (#145)
Browse files Browse the repository at this point in the history
* Added alert to Other page, message function to to assert the message, test for checking alert message

* Merged develop in

* Updated Changelog & Readme

* Update CHANGELOG.md

Co-authored-by: Roger TAN <[email protected]>

* Delete IDEWorkspaceChecks.plist

* Fixing storyboard for XCode 10

- Storyboard no more crash on Xcode10

Co-authored-by: Anna Piktas <[email protected]>
Co-authored-by: Roger TAN <[email protected]>
Co-authored-by: Marco Guerrieri <[email protected]>
  • Loading branch information
4 people authored Jan 15, 2021
1 parent ff2408d commit 77bdc69
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Added `carthage.sh` to fix the issue with duplicated architecture when Carthage needs to build with Xcode 12.0
- Fixed Carthage issue to allow `Biometics` framework to be seperated from TABTestKit as the same of SwiftPM
- Fixed a timezone issue on TestExample when switching from Summer Time to Winter Time. We make sure that the DatePicker are now always in UTC Timezone
- Added a method to assert the alert message
- Added assert for tab bar tab count

---
Expand Down
19 changes: 13 additions & 6 deletions Example/TABTestKit/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,25 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qtX-qz-K6y">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qtX-qz-K6y">
<rect key="frame" x="20" y="56.5" width="335" height="30"/>
<state key="normal" title="Example button"/>
<connections>
<action selector="buttonTapped" destination="jT9-QJ-sAL" eventType="touchUpInside" id="hhd-Ly-GM8"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="xdr-1c-3so">
<rect key="frame" x="20" y="102.5" width="335" height="30"/>
<state key="normal" title="Alert button"/>
<connections>
<action selector="buttonAlertTapped" destination="jT9-QJ-sAL" eventType="touchUpInside" id="4Gz-wK-tff"/>
</connections>
</button>
<view contentMode="scaleToFill" verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="kY2-0d-g5B">
<rect key="frame" x="20" y="102.5" width="335" height="28"/>
<rect key="frame" x="20" y="148.5" width="335" height="31"/>
<subviews>
<segmentedControl opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="1000" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="Lbh-uE-7oV">
<rect key="frame" x="0.0" y="0.0" width="335" height="29"/>
<rect key="frame" x="0.0" y="0.0" width="335" height="32"/>
<segments>
<segment title="First"/>
<segment title="Second"/>
Expand Down Expand Up @@ -290,8 +297,8 @@
<!--2007-01-09 09:41:00 +0000-->
</date>
</datePicker>
<datePicker contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="date" minuteInterval="1" style="wheels" useCurrentDate="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wph-qF-GtI">
<rect key="frame" x="20" y="1327.5" width="335" height="216"/>
<datePicker contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="date" style="wheels" useCurrentDate="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wph-qF-GtI">
<rect key="frame" x="20" y="1410" width="335" height="216"/>
<constraints>
<constraint firstAttribute="height" constant="216" id="nBS-T0-mn3"/>
</constraints>
Expand Down Expand Up @@ -415,7 +422,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="z4D-6q-tVm">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="z4D-6q-tVm">
<rect key="frame" x="166.5" y="605" width="42" height="30"/>
<state key="normal" title="Log in"/>
<connections>
Expand Down
11 changes: 11 additions & 0 deletions Example/TABTestKit/OtherElementsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ final class OtherElementsController: UIViewController {
present(sheet, animated: true)
}

@IBAction func buttonAlertTapped() {
let alertController = UIAlertController(title: "Alert title", message: "Alert Message", preferredStyle: .alert)

let dismissAction = UIAlertAction(title: "Dismiss", style: .cancel, handler: { _ in
alertController.dismiss(animated: true)
})

alertController.addAction(dismissAction)

present(alertController, animated: true)
}
}

extension OtherElementsController: UITextFieldDelegate {
Expand Down
2 changes: 2 additions & 0 deletions Example/TABTestKit_ExampleUITests/OtherElementsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct OtherElementsScreen: Screen {
let scrollView = ScrollView(id: "MyScrollView") // In iOS 13, XCUI matches a hidden scroll view when the keyboard is showing :(
let label = Label(id: "Example label")
let button = Button(id: "Example button")
let alertButton = Button(id: "Alert button")
let segmentedControl = SegmentedControl(parent: View(id: "ExampleSegmentedControl"))
let textField = TextField(id: "ExampleTextField")
let numberPadTextField = TextField(id: "NumberPadTextField")
Expand All @@ -38,6 +39,7 @@ struct OtherElementsScreen: Screen {
let dateTimePicker = DatePicker(id: "ExampleDateTimePicker")
let countdownTimerPicker = DatePicker(id: "ExampleCountDownTimerPicker")
let shareSheet = ActivitySheet()
let alert = Alert(id: "Alert title", message: "Alert message", dismissButtonID: "Dismiss")

}

Expand Down
13 changes: 13 additions & 0 deletions Example/TABTestKit_ExampleUITests/OtherElementsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ final class OtherElementsTests: TABTestCase, SystemPreferencesContext {
And(I: see(otherElementsScreen))
}

Scenario("Asserting the alert message") {
Given(I: see(otherElementsScreen.alertButton))
And(I: tap(otherElementsScreen.alertButton))
Then(I: see(otherElementsScreen.alert))
And(the: message(in: otherElementsScreen.alert, is: "Alert message"))
}

Scenario("Dismissing the alert") {
Given(I: see(otherElementsScreen.alert))
When(I: tap(otherElementsScreen.alert.dismissButton))
Then(I: see(otherElementsScreen))
}

Scenario("Seeing and interacting with the segmented control") {
Given(I: see(otherElementsScreen.segmentedControl))
Then(I: tap(otherElementsScreen.segmentedControl.button(withID: "Second")))
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,11 @@ tap("OK", in: myScreen.alert)

Given(I: tap("OK", in: myScreen.alert))
```
```swift
message(in: myScreen.alert, is: "Alert message")

Then(the: message(in: myScreen.alert, is: "Alert message"))
```

#### SheetContext

Expand Down
3 changes: 3 additions & 0 deletions TABTestKit/Classes/Contexts/AlertContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public extension AlertContext {
alert.actionButton(withID: actionButtonID).tap()
}

func message(in alert: Alert, is message: String) {
XCTAssertEqual(alert.message, message)
}
}
4 changes: 3 additions & 1 deletion TABTestKit/Classes/Elements/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ public struct Alert: Element {

public let id: String?
public let parent: Element
public let message: String?
public let type: XCUIElement.ElementType = .alert
public var dismissButton: Button {
return Button(id: dismissButtonID, parent: self)
}

private let dismissButtonID: String

public init(id: String?, parent: Element = App.shared, dismissButtonID: String = "Cancel") {
public init(id: String?, message: String? = nil, parent: Element = App.shared, dismissButtonID: String = "Cancel") {
self.id = id
self.message = message
self.parent = parent
self.dismissButtonID = dismissButtonID
}
Expand Down

0 comments on commit 77bdc69

Please sign in to comment.