Skip to content

Commit

Permalink
Minor test additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Aug 1, 2024
1 parent 17c15b1 commit 07b76d2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
12 changes: 12 additions & 0 deletions Tests/SpeziTests/DependenciesTests/DependencyBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ final class DependencyBuilderTests: XCTestCase {
XCTAssertEqual(collection.count, 2)
}

@available(*, deprecated, message: "Propagate deprecation warning.")
@MainActor
func testDeprecatedInits() {
let collection1 = DependencyCollection(singleEntry: ExampleDependentModule())
let collection2 = DependencyCollection(singleEntry: {
ExampleDependentModule()
})

XCTAssertEqual(collection1.count, 1)
XCTAssertEqual(collection2.count, 1)
}


@MainActor
func testDependencyBuilder() throws {
Expand Down
35 changes: 25 additions & 10 deletions Tests/SpeziTests/DependenciesTests/DependencyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,6 @@ private final class InjectionOfOptionalDefaultValue: Module {
init() {}
}


/*
private final class TestModuleCircle11: Module {
@Dependency var testModuleCircle2 = TestModuleCircle22()
}

private final class TestModuleCircle22: Module {
@Dependency var testModuleCircle1 = TestModuleCircle11()
}*/

private final class TestModuleCircle1: Module {
@Dependency var modules: [any Module]

Expand Down Expand Up @@ -659,6 +649,31 @@ final class DependencyTests: XCTestCase { // swiftlint:disable:this type_body_le
_ = DependencyManager.resolve([module1])
}
}

@MainActor
func testMissingRequiredModule() throws {
class Module1: Module {
@Dependency(TestModuleX.self) var module
}

try XCTRuntimePrecondition {
_ = DependencyManager.resolve([Module1()])
}
}

@available(*, deprecated, message: "Propagate deprecation warning")
@MainActor
func testDeprecatedInits() throws {
let spezi = Spezi(standard: DefaultStandard(), modules: [DeprecatedDeclarations()])

let modules = spezi.modules

let module: DeprecatedDeclarations = try getModule(in: modules)

XCTAssertNil(module.testModule6)
XCTAssertEqual(module.testModule3.state, 0)
XCTAssertEqual(module.testModule3.num, 3)
}
}

// swiftlint:disable:this file_length
4 changes: 4 additions & 0 deletions Tests/UITests/TestAppUITests/LifecycleHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ final class LifecycleHandlerTests: XCTestCase {
app.launchArguments = ["--lifecycleTests"]
app.launch()

XCTAssertTrue(app.wait(for: .runningForeground, timeout: 2.0))

app.buttons["LifecycleHandler"].tap()

XCTAssert(app.staticTexts["WillFinishLaunchingWithOptions: 1"].waitForExistence(timeout: 2))
Expand All @@ -43,6 +45,8 @@ final class LifecycleHandlerTests: XCTestCase {
app.activate()
#endif

XCTAssertTrue(app.wait(for: .runningForeground, timeout: 2.0))

XCTAssert(app.staticTexts["WillFinishLaunchingWithOptions: 1"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["SceneWillEnterForeground: 2"].exists)
XCTAssert(app.staticTexts["SceneDidBecomeActive: 2"].exists)
Expand Down
2 changes: 2 additions & 0 deletions Tests/UITests/TestAppUITests/ModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ final class ModelTests: XCTestCase {
let app = XCUIApplication()
app.launch()

XCTAssertTrue(app.wait(for: .runningForeground, timeout: 2.0))

app.buttons["Model"].tap()

XCTAssert(app.staticTexts["Passed"].waitForExistence(timeout: 1))
Expand Down
4 changes: 3 additions & 1 deletion Tests/UITests/TestAppUITests/ViewModifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ final class ViewModifierTests: XCTestCase {
func testViewModifierPropertyWrapper() throws {
let app = XCUIApplication()
app.launch()


XCTAssertTrue(app.wait(for: .runningForeground, timeout: 2.0))

app.buttons["ViewModifier"].tap()

XCTAssert(app.staticTexts["Passed"].waitForExistence(timeout: 1))
Expand Down

0 comments on commit 07b76d2

Please sign in to comment.