* 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
102 lines
3.8 KiB
Swift
102 lines
3.8 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
// Copyright 2022-2025 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
@testable import ElementX
|
|
import Foundation
|
|
import Testing
|
|
|
|
@MainActor
|
|
@Suite
|
|
struct UserIndicatorControllerTests {
|
|
private var indicatorController: UserIndicatorController
|
|
|
|
init() {
|
|
indicatorController = UserIndicatorController()
|
|
}
|
|
|
|
@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: ""))
|
|
|
|
#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")
|
|
|
|
#expect(indicatorController.indicatorQueue.count == 2)
|
|
#expect(indicatorController.indicatorQueue[1].id == "Third")
|
|
#expect(indicatorController.indicatorQueue[0].id == "First")
|
|
|
|
indicatorController.retractAllIndicators()
|
|
|
|
#expect(indicatorController.indicatorQueue.count == 0)
|
|
}
|
|
|
|
@Test
|
|
mutating func chainedPresentation() async throws {
|
|
indicatorController.minimumDisplayDuration = 0.25
|
|
indicatorController.nonPersistentDisplayDuration = 2.5
|
|
|
|
indicatorController.submitIndicator(.init(id: "First", title: ""))
|
|
indicatorController.submitIndicator(.init(id: "Second", title: ""))
|
|
indicatorController.submitIndicator(.init(id: "Third", title: ""))
|
|
|
|
#expect(indicatorController.activeIndicator?.id == "Third")
|
|
|
|
let fulfillment = deferFulfillment(indicatorController.$activeIndicator,
|
|
message: "Waiting for last indicator to be dismissed") { indicator in
|
|
indicator?.id == "Second"
|
|
}
|
|
|
|
try await fulfillment.fulfill()
|
|
|
|
#expect(indicatorController.indicatorQueue.count == 2)
|
|
#expect(indicatorController.activeIndicator?.id == "Second")
|
|
}
|
|
|
|
@Test
|
|
mutating func minimumDisplayDuration() async throws {
|
|
indicatorController.minimumDisplayDuration = 0.25
|
|
indicatorController.nonPersistentDisplayDuration = 2.5
|
|
|
|
indicatorController.submitIndicator(.init(id: "First", title: ""))
|
|
indicatorController.submitIndicator(.init(id: "Second", title: ""))
|
|
indicatorController.submitIndicator(.init(id: "Third", title: ""))
|
|
|
|
#expect(indicatorController.indicatorQueue.count == 3)
|
|
|
|
var fulfillment = deferFulfillment(indicatorController.$activeIndicator,
|
|
message: "Waiting for minimum display duration to pass") { indicator in
|
|
indicator?.id == "First"
|
|
}
|
|
|
|
indicatorController.retractIndicatorWithId("Second")
|
|
|
|
try await fulfillment.fulfill()
|
|
|
|
#expect(indicatorController.indicatorQueue.count == 1)
|
|
#expect(indicatorController.activeIndicator?.id == "First")
|
|
|
|
fulfillment = deferFulfillment(indicatorController.$activeIndicator,
|
|
message: "Waiting for last indicator to be dismissed") { indicator in
|
|
indicator == nil
|
|
}
|
|
|
|
try await fulfillment.fulfill()
|
|
|
|
#expect(indicatorController.indicatorQueue.count == 0)
|
|
#expect(indicatorController.activeIndicator == nil)
|
|
}
|
|
}
|