mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 03:06:37 +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,19 @@
|
||||
//
|
||||
|
||||
@testable import ElementX
|
||||
import XCTest
|
||||
import Testing
|
||||
|
||||
@MainActor
|
||||
class AppLockSetupBiometricsScreenViewModelTests: XCTestCase {
|
||||
var appLockService: AppLockServiceMock!
|
||||
var viewModel: AppLockSetupBiometricsScreenViewModelProtocol!
|
||||
@Suite
|
||||
final class AppLockSetupBiometricsScreenViewModelTests {
|
||||
var appLockService: AppLockServiceMock
|
||||
var viewModel: AppLockSetupBiometricsScreenViewModelProtocol
|
||||
|
||||
var context: AppLockSetupBiometricsScreenViewModelType.Context {
|
||||
viewModel.context
|
||||
}
|
||||
|
||||
override func setUp() {
|
||||
init() {
|
||||
AppSettings.resetAllSettings()
|
||||
|
||||
appLockService = AppLockServiceMock()
|
||||
@@ -28,27 +29,29 @@ class AppLockSetupBiometricsScreenViewModelTests: XCTestCase {
|
||||
viewModel = AppLockSetupBiometricsScreenViewModel(appLockService: appLockService)
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
deinit {
|
||||
AppSettings.resetAllSettings()
|
||||
}
|
||||
|
||||
func testAllow() async throws {
|
||||
@Test
|
||||
func allow() async throws {
|
||||
// When allowing Touch/Face ID.
|
||||
let deferred = deferFulfillment(viewModel.actions) { $0 == .continue }
|
||||
context.send(viewAction: .allow)
|
||||
try await deferred.fulfill()
|
||||
|
||||
// Then the service should now have biometric unlock enabled.
|
||||
XCTAssertEqual(appLockService.enableBiometricUnlockCallsCount, 1)
|
||||
#expect(appLockService.enableBiometricUnlockCallsCount == 1)
|
||||
}
|
||||
|
||||
func testSkip() async throws {
|
||||
@Test
|
||||
func skip() async throws {
|
||||
// When skipping biometrics.
|
||||
let deferred = deferFulfillment(viewModel.actions) { $0 == .continue }
|
||||
context.send(viewAction: .skip)
|
||||
try await deferred.fulfill()
|
||||
|
||||
// Then the service should now have biometric unlock enabled.
|
||||
XCTAssertEqual(appLockService.enableBiometricUnlockCallsCount, 0)
|
||||
#expect(appLockService.enableBiometricUnlockCallsCount == 0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user