Skip to content

Commit

Permalink
- r Move @mainactor from suites to test to prepare for Swift 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jonreid committed Jun 26, 2024
1 parent c5c4a80 commit 1c26ae4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
9 changes: 8 additions & 1 deletion SwiftSample/Tests/AlertVerifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import ViewControllerPresentationSpy
@testable import SwiftSampleViewControllerPresentationSpy
import XCTest

@MainActor
final class AlertVerifierTests: XCTestCase {
private var sut: AlertVerifier!
private var vc: ViewController!

@MainActor
override func setUp() {
super.setUp()
sut = AlertVerifier()
Expand All @@ -25,22 +25,26 @@ final class AlertVerifierTests: XCTestCase {
super.tearDown()
}

@MainActor
private func showAlert() {
vc.showAlertButton.sendActions(for: .touchUpInside)
}

@MainActor
func test_executeActionForButtonWithTitle_withNonexistentTitle_shouldThrowException() {
showAlert()

XCTAssertThrowsError(try sut.executeAction(forButton: "NO SUCH BUTTON"))
}

@MainActor
func test_executeActionForButtonWithTitle_withoutHandler_shouldNotCrash() throws {
showAlert()

try sut.executeAction(forButton: "No Handler")
}

@MainActor
func test_showingAlert_withCompletion_shouldCaptureCompletionBlock() {
var completionCallCount = 0
vc.alertPresentedCompletion = {
Expand All @@ -53,12 +57,14 @@ final class AlertVerifierTests: XCTestCase {
XCTAssertEqual(completionCallCount, 1)
}

@MainActor
func test_showingAlert_withoutCompletion_shouldNotCaptureCompletionBlock() {
showAlert()

XCTAssertNil(sut.capturedCompletion)
}

@MainActor
func test_showingAlert_shouldExecuteTestCompletionBlock() {
var completionCallCount = 0
sut.testCompletion = {
Expand All @@ -70,6 +76,7 @@ final class AlertVerifierTests: XCTestCase {
XCTAssertEqual(completionCallCount, 1)
}

@MainActor
func test_notShowingAlert_shouldNotExecuteTestCompletionBlock() {
var completionCallCount = 0
sut.testCompletion = {
Expand Down
9 changes: 8 additions & 1 deletion SwiftSample/Tests/DismissalVerifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import ViewControllerPresentationSpy
import XCTest

@MainActor
final class DismissalVerifierTests: XCTestCase {
private var sut: DismissalVerifier!
private var vc: StoryboardNextViewController!

@MainActor
override func setUp() {
super.setUp()
sut = DismissalVerifier()
Expand All @@ -25,16 +25,19 @@ final class DismissalVerifierTests: XCTestCase {
super.tearDown()
}

@MainActor
private func dismissViewController() {
tap(vc.cancelButton)
}

@MainActor
func test_dismissingVC_shouldCaptureAnimationFlag() {
dismissViewController()

XCTAssertTrue(sut.animated)
}

@MainActor
func test_dismissingVC_shouldCaptureDismissedViewController() {
dismissViewController()

Expand All @@ -45,6 +48,7 @@ final class DismissalVerifierTests: XCTestCase {
""")
}

@MainActor
func test_dismissingVC_withCompletion_shouldCaptureCompletionBlock() {
var completionCallCount = 0
vc.viewControllerDismissedCompletion = {
Expand All @@ -58,12 +62,14 @@ final class DismissalVerifierTests: XCTestCase {
XCTAssertEqual(completionCallCount, 1)
}

@MainActor
func test_dismissingVC_withoutCompletion_shouldNotCaptureCompletionBlock() {
dismissViewController()

XCTAssertNil(sut.capturedCompletion)
}

@MainActor
func test_dismissingVC_shouldExecuteTestCompletionBlock() {
var completionCallCount = 0
sut.testCompletion = {
Expand All @@ -75,6 +81,7 @@ final class DismissalVerifierTests: XCTestCase {
XCTAssertEqual(completionCallCount, 1)
}

@MainActor
func test_notDismissingVC_shouldNotExecuteTestCompletionBlock() {
var completionCallCount = 0
sut.testCompletion = {
Expand Down
7 changes: 6 additions & 1 deletion SwiftSample/Tests/PresentationVerifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import ViewControllerPresentationSpy
@testable import SwiftSampleViewControllerPresentationSpy
import XCTest

@MainActor
final class PresentationVerifierTests: XCTestCase {
private var sut: PresentationVerifier!
private var vc: ViewController!

@MainActor
override func setUp() {
super.setUp()
sut = PresentationVerifier()
Expand All @@ -25,10 +25,12 @@ final class PresentationVerifierTests: XCTestCase {
super.tearDown()
}

@MainActor
private func presentViewController() {
vc.codePresentModalButton.sendActions(for: .touchUpInside)
}

@MainActor
func test_presentingVC_withCompletion_shouldCaptureCompletionBlock() {
var completionCallCount = 0
vc.viewControllerPresentedCompletion = {
Expand All @@ -41,12 +43,14 @@ final class PresentationVerifierTests: XCTestCase {
XCTAssertEqual(completionCallCount, 1)
}

@MainActor
func test_presentingVC_withoutCompletion_shouldNotCaptureCompletionBlock() {
presentViewController()

XCTAssertNil(sut.capturedCompletion)
}

@MainActor
func test_presentingVC_shouldExecuteTestCompletionBlock() {
var completionCallCount = 0
sut.testCompletion = {
Expand All @@ -58,6 +62,7 @@ final class PresentationVerifierTests: XCTestCase {
XCTAssertEqual(completionCallCount, 1)
}

@MainActor
func test_notPresentingVC_shouldNotExecuteTestCompletionBlock() {
var completionCallCount = 0
sut.testCompletion = {
Expand Down
12 changes: 11 additions & 1 deletion SwiftSample/Tests/ViewControllerAlertTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import ViewControllerPresentationSpy
import XCTest

@MainActor
final class ViewControllerAlertTests: XCTestCase {
private var alertVerifier: AlertVerifier!
private var sut: ViewController!

@MainActor
override func setUp() {
super.setUp()
alertVerifier = AlertVerifier()
Expand All @@ -25,11 +25,13 @@ final class ViewControllerAlertTests: XCTestCase {
super.tearDown()
}

@MainActor
func test_outlets_shouldBeConnected() {
XCTAssertNotNil(sut.showAlertButton)
XCTAssertNotNil(sut.showActionSheetButton)
}

@MainActor
func test_tappingShowAlertButton_shouldShowAlert() {
sut.showAlertButton.sendActions(for: .touchUpInside)

Expand All @@ -46,6 +48,7 @@ final class ViewControllerAlertTests: XCTestCase {
)
}

@MainActor
func test_tappingShowActionSheetButton_shouldShowActionSheet() {
sut.showActionSheetButton.sendActions(for: .touchUpInside)

Expand All @@ -62,6 +65,7 @@ final class ViewControllerAlertTests: XCTestCase {
preferredStyle: .actionSheet)
}

@MainActor
func test_popoverForActionSheet() throws {
sut.showActionSheetButton.sendActions(for: .touchUpInside)

Expand All @@ -72,12 +76,14 @@ final class ViewControllerAlertTests: XCTestCase {
XCTAssertEqual(popover.permittedArrowDirections, UIPopoverArrowDirection.any, "permitted arrow directions")
}

@MainActor
func test_preferredActionForAlert() {
sut.showAlertButton.sendActions(for: .touchUpInside)

XCTAssertEqual(alertVerifier.preferredAction?.title, "Default")
}

@MainActor
func test_executeActionForButton_withDefaultButton_shouldExecuteDefaultAction() throws {
sut.showAlertButton.sendActions(for: .touchUpInside)

Expand All @@ -86,6 +92,7 @@ final class ViewControllerAlertTests: XCTestCase {
XCTAssertEqual(sut.alertDefaultActionCount, 1)
}

@MainActor
func test_executeActionForButton_withCancelButton_shouldExecuteCancelAction() throws {
sut.showAlertButton.sendActions(for: .touchUpInside)

Expand All @@ -94,6 +101,7 @@ final class ViewControllerAlertTests: XCTestCase {
XCTAssertEqual(sut.alertCancelActionCount, 1)
}

@MainActor
func test_executeActionForButton_withDestroyButton_shouldExecuteDestroyAction() throws {
sut.showAlertButton.sendActions(for: .touchUpInside)

Expand All @@ -102,13 +110,15 @@ final class ViewControllerAlertTests: XCTestCase {
XCTAssertEqual(sut.alertDestroyActionCount, 1)
}

@MainActor
func test_textFieldsForAlert() {
sut.showAlertButton.sendActions(for: .touchUpInside)

XCTAssertEqual(alertVerifier.textFields?.count, 1)
XCTAssertEqual(alertVerifier.textFields?[0].placeholder, "Placeholder")
}

@MainActor
func test_textFields_shouldNotBeAddedToActionSheets() {
sut.showActionSheetButton.sendActions(for: .touchUpInside)

Expand Down
6 changes: 5 additions & 1 deletion SwiftSample/Tests/ViewControllerPresentationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import ViewControllerPresentationSpy
import XCTest

@MainActor
final class ViewControllerPresentationTests: XCTestCase {
private var presentationVerifier: PresentationVerifier!
private var sut: ViewController!

@MainActor
override func setUp() {
super.setUp()
presentationVerifier = PresentationVerifier()
Expand All @@ -26,12 +26,14 @@ final class ViewControllerPresentationTests: XCTestCase {
super.tearDown()
}

@MainActor
func test_outlets_shouldBeConnected() {
XCTAssertNotNil(sut.seguePresentModalButton)
XCTAssertNotNil(sut.segueShowButton)
XCTAssertNotNil(sut.codePresentModalButton)
}

@MainActor
func test_tappingSeguePresentModalButton_shouldPresentNextViewControllerWithGreenBackground() {
sut.seguePresentModalButton.sendActions(for: .touchUpInside)

Expand All @@ -40,6 +42,7 @@ final class ViewControllerPresentationTests: XCTestCase {
XCTAssertEqual(nextVC?.backgroundColor, .green, "Background color passed in")
}

@MainActor
func test_tappingSegueShowButton_shouldShowNextViewControllerWithRedBackground() {
let window = UIWindow()
window.rootViewController = sut
Expand All @@ -52,6 +55,7 @@ final class ViewControllerPresentationTests: XCTestCase {
XCTAssertEqual(nextVC?.backgroundColor, .red, "Background color passed in")
}

@MainActor
func test_tappingCodeModalButton_shouldPresentNextViewControllerWithPurpleBackground() {
sut.codePresentModalButton.sendActions(for: .touchUpInside)

Expand Down

0 comments on commit 1c26ae4

Please sign in to comment.