mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Swift Testing for Unit Tests PART 1 (#5119)
* migrated a lot of unit tests to Swift Testing and added a new implementation for deferred fulfillment more tests migration Cleaned the code manually to establish some good patterns more code improvements some more code improvements removed empty tests update project * more pr suggestions and cleanups * removed the TestSetup pattern * fixing claude not reusing tests * pr suggestion + added indent rule to swiftformat so that we can prevent AIs to change that
This commit is contained in:
@@ -7,18 +7,21 @@
|
||||
//
|
||||
|
||||
@testable import ElementX
|
||||
import XCTest
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
@MainActor
|
||||
class NavigationRootCoordinatorTests: XCTestCase {
|
||||
private var navigationRootCoordinator: NavigationRootCoordinator!
|
||||
@Suite
|
||||
struct NavigationRootCoordinatorTests {
|
||||
private var navigationRootCoordinator: NavigationRootCoordinator
|
||||
|
||||
override func setUp() {
|
||||
init() {
|
||||
navigationRootCoordinator = NavigationRootCoordinator()
|
||||
}
|
||||
|
||||
func testRootChanges() {
|
||||
XCTAssertNil(navigationRootCoordinator.rootCoordinator)
|
||||
@Test
|
||||
func rootChanges() {
|
||||
#expect(navigationRootCoordinator.rootCoordinator == nil)
|
||||
|
||||
let firstRootCoordinator = SomeTestCoordinator()
|
||||
navigationRootCoordinator.setRootCoordinator(firstRootCoordinator)
|
||||
@@ -31,7 +34,8 @@ class NavigationRootCoordinatorTests: XCTestCase {
|
||||
assertCoordinatorsEqual(secondRootCoordinator, navigationRootCoordinator.rootCoordinator)
|
||||
}
|
||||
|
||||
func testOverlay() {
|
||||
@Test
|
||||
func overlay() {
|
||||
let rootCoordinator = SomeTestCoordinator()
|
||||
navigationRootCoordinator.setRootCoordinator(rootCoordinator)
|
||||
|
||||
@@ -44,35 +48,37 @@ class NavigationRootCoordinatorTests: XCTestCase {
|
||||
navigationRootCoordinator.setOverlayCoordinator(nil)
|
||||
|
||||
assertCoordinatorsEqual(rootCoordinator, navigationRootCoordinator.rootCoordinator)
|
||||
XCTAssertNil(navigationRootCoordinator.overlayCoordinator)
|
||||
#expect(navigationRootCoordinator.overlayCoordinator == nil)
|
||||
}
|
||||
|
||||
// MARK: - Dismissal Callbacks
|
||||
|
||||
func testReplacementDismissalCallbacks() {
|
||||
XCTAssertNil(navigationRootCoordinator.rootCoordinator)
|
||||
@Test
|
||||
func replacementDismissalCallbacks() async {
|
||||
#expect(navigationRootCoordinator.rootCoordinator == nil)
|
||||
|
||||
let rootCoordinator = SomeTestCoordinator()
|
||||
|
||||
let expectation = expectation(description: "Wait for callback")
|
||||
navigationRootCoordinator.setRootCoordinator(rootCoordinator) {
|
||||
expectation.fulfill()
|
||||
await confirmation("Wait for callback") { confirm in
|
||||
navigationRootCoordinator.setRootCoordinator(rootCoordinator) {
|
||||
confirm()
|
||||
}
|
||||
|
||||
navigationRootCoordinator.setRootCoordinator(nil)
|
||||
}
|
||||
|
||||
navigationRootCoordinator.setRootCoordinator(nil)
|
||||
waitForExpectations(timeout: 1.0)
|
||||
}
|
||||
|
||||
func testOverlayDismissalCallback() {
|
||||
@Test
|
||||
func overlayDismissalCallback() async {
|
||||
let overlayCoordinator = SomeTestCoordinator()
|
||||
|
||||
let expectation = expectation(description: "Wait for callback")
|
||||
navigationRootCoordinator.setOverlayCoordinator(overlayCoordinator) {
|
||||
expectation.fulfill()
|
||||
await confirmation("Wait for callback") { confirm in
|
||||
navigationRootCoordinator.setOverlayCoordinator(overlayCoordinator) {
|
||||
confirm()
|
||||
}
|
||||
|
||||
navigationRootCoordinator.setOverlayCoordinator(nil)
|
||||
}
|
||||
|
||||
navigationRootCoordinator.setOverlayCoordinator(nil)
|
||||
waitForExpectations(timeout: 1.0)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
@@ -80,11 +86,11 @@ class NavigationRootCoordinatorTests: XCTestCase {
|
||||
private func assertCoordinatorsEqual(_ lhs: CoordinatorProtocol?, _ rhs: CoordinatorProtocol?) {
|
||||
guard let lhs = lhs as? SomeTestCoordinator,
|
||||
let rhs = rhs as? SomeTestCoordinator else {
|
||||
XCTFail("Coordinators are not the same")
|
||||
Issue.record("Coordinators are not the same")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(lhs.id, rhs.id)
|
||||
#expect(lhs.id == rhs.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user