mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +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:
@@ -8,40 +8,43 @@
|
||||
|
||||
@testable import ElementX
|
||||
import Foundation
|
||||
import XCTest
|
||||
import Testing
|
||||
|
||||
@MainActor
|
||||
class UserIndicatorControllerTests: XCTestCase {
|
||||
private var indicatorController: UserIndicatorController!
|
||||
@Suite
|
||||
struct UserIndicatorControllerTests {
|
||||
private var indicatorController: UserIndicatorController
|
||||
|
||||
override func setUp() {
|
||||
init() {
|
||||
indicatorController = UserIndicatorController()
|
||||
}
|
||||
|
||||
func testIndicatorQueueing() {
|
||||
@Test
|
||||
mutating func indicatorQueueing() {
|
||||
indicatorController.minimumDisplayDuration = 0.0
|
||||
|
||||
indicatorController.submitIndicator(.init(id: "First", title: ""))
|
||||
indicatorController.submitIndicator(.init(id: "Second", title: ""))
|
||||
indicatorController.submitIndicator(.init(id: "Third", title: ""))
|
||||
|
||||
XCTAssertEqual(indicatorController.indicatorQueue.count, 3)
|
||||
XCTAssertEqual(indicatorController.indicatorQueue[2].id, "Third")
|
||||
XCTAssertEqual(indicatorController.indicatorQueue[1].id, "Second")
|
||||
XCTAssertEqual(indicatorController.indicatorQueue[0].id, "First")
|
||||
#expect(indicatorController.indicatorQueue.count == 3)
|
||||
#expect(indicatorController.indicatorQueue[2].id == "Third")
|
||||
#expect(indicatorController.indicatorQueue[1].id == "Second")
|
||||
#expect(indicatorController.indicatorQueue[0].id == "First")
|
||||
|
||||
indicatorController.retractIndicatorWithId("Second")
|
||||
|
||||
XCTAssertEqual(indicatorController.indicatorQueue.count, 2)
|
||||
XCTAssertEqual(indicatorController.indicatorQueue[1].id, "Third")
|
||||
XCTAssertEqual(indicatorController.indicatorQueue[0].id, "First")
|
||||
#expect(indicatorController.indicatorQueue.count == 2)
|
||||
#expect(indicatorController.indicatorQueue[1].id == "Third")
|
||||
#expect(indicatorController.indicatorQueue[0].id == "First")
|
||||
|
||||
indicatorController.retractAllIndicators()
|
||||
|
||||
XCTAssertEqual(indicatorController.indicatorQueue.count, 0)
|
||||
#expect(indicatorController.indicatorQueue.count == 0)
|
||||
}
|
||||
|
||||
func testChainedPresentation() async throws {
|
||||
@Test
|
||||
mutating func chainedPresentation() async throws {
|
||||
indicatorController.minimumDisplayDuration = 0.25
|
||||
indicatorController.nonPersistentDisplayDuration = 2.5
|
||||
|
||||
@@ -49,19 +52,21 @@ class UserIndicatorControllerTests: XCTestCase {
|
||||
indicatorController.submitIndicator(.init(id: "Second", title: ""))
|
||||
indicatorController.submitIndicator(.init(id: "Third", title: ""))
|
||||
|
||||
XCTAssertEqual(indicatorController.activeIndicator?.id, "Third")
|
||||
#expect(indicatorController.activeIndicator?.id == "Third")
|
||||
|
||||
let fulfillment = deferFulfillment(indicatorController.$activeIndicator, message: "Waiting for last indicator to be dismissed") { indicator in
|
||||
let fulfillment = deferFulfillment(indicatorController.$activeIndicator,
|
||||
message: "Waiting for last indicator to be dismissed") { indicator in
|
||||
indicator?.id == "Second"
|
||||
}
|
||||
|
||||
try await fulfillment.fulfill()
|
||||
|
||||
XCTAssertEqual(indicatorController.indicatorQueue.count, 2)
|
||||
XCTAssertEqual(indicatorController.activeIndicator?.id, "Second")
|
||||
#expect(indicatorController.indicatorQueue.count == 2)
|
||||
#expect(indicatorController.activeIndicator?.id == "Second")
|
||||
}
|
||||
|
||||
func testMinimumDisplayDuration() async throws {
|
||||
@Test
|
||||
mutating func minimumDisplayDuration() async throws {
|
||||
indicatorController.minimumDisplayDuration = 0.25
|
||||
indicatorController.nonPersistentDisplayDuration = 2.5
|
||||
|
||||
@@ -69,9 +74,10 @@ class UserIndicatorControllerTests: XCTestCase {
|
||||
indicatorController.submitIndicator(.init(id: "Second", title: ""))
|
||||
indicatorController.submitIndicator(.init(id: "Third", title: ""))
|
||||
|
||||
XCTAssertEqual(indicatorController.indicatorQueue.count, 3)
|
||||
#expect(indicatorController.indicatorQueue.count == 3)
|
||||
|
||||
var fulfillment = deferFulfillment(indicatorController.$activeIndicator, message: "Waiting for minimum display duration to pass") { indicator in
|
||||
var fulfillment = deferFulfillment(indicatorController.$activeIndicator,
|
||||
message: "Waiting for minimum display duration to pass") { indicator in
|
||||
indicator?.id == "First"
|
||||
}
|
||||
|
||||
@@ -79,16 +85,17 @@ class UserIndicatorControllerTests: XCTestCase {
|
||||
|
||||
try await fulfillment.fulfill()
|
||||
|
||||
XCTAssertEqual(indicatorController.indicatorQueue.count, 1)
|
||||
XCTAssertEqual(indicatorController.activeIndicator?.id, "First")
|
||||
#expect(indicatorController.indicatorQueue.count == 1)
|
||||
#expect(indicatorController.activeIndicator?.id == "First")
|
||||
|
||||
fulfillment = deferFulfillment(indicatorController.$activeIndicator, message: "Waiting for last indicator to be dismissed") { indicator in
|
||||
fulfillment = deferFulfillment(indicatorController.$activeIndicator,
|
||||
message: "Waiting for last indicator to be dismissed") { indicator in
|
||||
indicator == nil
|
||||
}
|
||||
|
||||
try await fulfillment.fulfill()
|
||||
|
||||
XCTAssertEqual(indicatorController.indicatorQueue.count, 0)
|
||||
XCTAssertNil(indicatorController.activeIndicator)
|
||||
#expect(indicatorController.indicatorQueue.count == 0)
|
||||
#expect(indicatorController.activeIndicator == nil)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user