Skip to content

Commit

Permalink
Add debounce timing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Nov 9, 2023
1 parent 583d884 commit 55ac005
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ let package = Package(
.testTarget(
name: "SpeziViewsTests",
dependencies: [
.target(name: "SpeziViews")
.target(name: "SpeziViews"),
.target(name: "SpeziValidation")
]
)
]
Expand Down
34 changes: 34 additions & 0 deletions Tests/SpeziViewsTests/SpeziValidationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// This source file is part of the Stanford Spezi open-source project
//
// SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
//
// SPDX-License-Identifier: MIT
//

@testable import SpeziValidation
import XCTest


final class SpeziValidationTests: XCTestCase {
@MainActor
func testValidationDebounce() async throws {
let engine = ValidationEngine(rules: .nonEmpty)

engine.submit(input: "Valid")
XCTAssertTrue(engine.inputValid)
XCTAssertEqual(engine.validationResults, [])

engine.submit(input: "", debounce: true)
XCTAssertTrue(engine.inputValid)
XCTAssertEqual(engine.validationResults, [])

sleep(1)
XCTAssertFalse(engine.inputValid)
XCTAssertEqual(engine.validationResults.count, 1)

engine.submit(input: "Valid", debounce: true)
XCTAssertTrue(engine.inputValid) // valid state is reported instantly
XCTAssertEqual(engine.validationResults, [])
}
}
17 changes: 0 additions & 17 deletions Tests/SpeziViewsTests/SpeziViewsTests.swift

This file was deleted.

0 comments on commit 55ac005

Please sign in to comment.