diff --git a/AuthenticatorShared/UI/Platform/Application/Utilities/Alert/Alert+Error.swift b/AuthenticatorShared/UI/Platform/Application/Utilities/Alert/Alert+Error.swift index af0288f35..009cf7e7d 100644 --- a/AuthenticatorShared/UI/Platform/Application/Utilities/Alert/Alert+Error.swift +++ b/AuthenticatorShared/UI/Platform/Application/Utilities/Alert/Alert+Error.swift @@ -1,3 +1,4 @@ +import BitwardenKit import BitwardenResources import Foundation diff --git a/AuthenticatorShared/UI/Platform/Application/Utilities/Alert/AlertErrorTests.swift b/AuthenticatorShared/UI/Platform/Application/Utilities/Alert/AlertErrorTests.swift index 1447204fe..826b6218a 100644 --- a/AuthenticatorShared/UI/Platform/Application/Utilities/Alert/AlertErrorTests.swift +++ b/AuthenticatorShared/UI/Platform/Application/Utilities/Alert/AlertErrorTests.swift @@ -1,3 +1,4 @@ +import BitwardenKit import BitwardenResources import XCTest diff --git a/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/InputValidationError.swift b/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/InputValidationError.swift deleted file mode 100644 index 5ca832f36..000000000 --- a/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/InputValidationError.swift +++ /dev/null @@ -1,8 +0,0 @@ -/// An error thrown by an `InputValidator` for invalid input in a field. -/// -struct InputValidationError: Error, Equatable { - // MARK: Properties - - /// A localized error message describing the validation error. - let message: String -} diff --git a/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidator.swift b/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidator.swift deleted file mode 100644 index 3d8c7191a..000000000 --- a/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidator.swift +++ /dev/null @@ -1,18 +0,0 @@ -import BitwardenResources - -/// Validates that the input for a field is not empty. -/// -struct EmptyInputValidator: InputValidator { - // MARK: Properties - - /// The name of the field that is being validated. - let fieldName: String - - // MARK: InputValidator - - func validate(input: String?) throws { - guard input?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false else { - throw InputValidationError(message: Localizations.validationFieldRequired(fieldName)) - } - } -} diff --git a/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidatorTests.swift b/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidatorTests.swift deleted file mode 100644 index 7cf2a07f7..000000000 --- a/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidatorTests.swift +++ /dev/null @@ -1,39 +0,0 @@ -import XCTest - -@testable import AuthenticatorShared - -class EmptyInputValidatorTests: BitwardenTestCase { - // MARK: Tests - - /// `validate(input:)` doesn't throw an error if the input is valid. - func test_validate_success() { - let subject = EmptyInputValidator(fieldName: "Email") - - XCTAssertNoThrow(try subject.validate(input: "a")) - XCTAssertNoThrow(try subject.validate(input: "user@bitwarden.com")) - } - - /// `validate(input:)` throw an `InputValidationError` if the input is invalid. - func test_validate_error() { - let subject = EmptyInputValidator(fieldName: "Email") - - func assertThrowsInputValidationError( - input: String?, - file: StaticString = #filePath, - line: UInt = #line, - ) { - XCTAssertThrowsError(try subject.validate(input: input)) { error in - XCTAssertTrue(error is InputValidationError) - XCTAssertEqual( - error as? InputValidationError, - InputValidationError(message: "The Email field is required."), - ) - } - } - - assertThrowsInputValidationError(input: nil) - assertThrowsInputValidationError(input: " ") - assertThrowsInputValidationError(input: " ") - assertThrowsInputValidationError(input: "\n") - } -} diff --git a/BitwardenKit/UI/Platform/Application/Utilities/InputValidator/InputValidationError.swift b/BitwardenKit/UI/Platform/Application/Utilities/InputValidator/InputValidationError.swift new file mode 100644 index 000000000..7e108e0ef --- /dev/null +++ b/BitwardenKit/UI/Platform/Application/Utilities/InputValidator/InputValidationError.swift @@ -0,0 +1,20 @@ +// MARK: - InputValidationError + +/// An error thrown by an `InputValidator` for invalid input in a field. +/// +public struct InputValidationError: Error, Equatable { + // MARK: Properties + + /// A localized error message describing the validation error. + public let message: String + + // MARK: Initialization + + /// Initialize an input validation error. + /// + /// - Parameters: + /// - message: A localized error message describing the validation error. + public init(message: String) { + self.message = message + } +} diff --git a/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/InputValidator.swift b/BitwardenKit/UI/Platform/Application/Utilities/InputValidator/InputValidator.swift similarity index 81% rename from AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/InputValidator.swift rename to BitwardenKit/UI/Platform/Application/Utilities/InputValidator/InputValidator.swift index 9e70ca0d5..deda74a8c 100644 --- a/AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/InputValidator.swift +++ b/BitwardenKit/UI/Platform/Application/Utilities/InputValidator/InputValidator.swift @@ -1,6 +1,8 @@ +// - MARK: Input Validator + /// A protocol for an object that handles validating input for a field. /// -protocol InputValidator { +public protocol InputValidator { /// Validates that the specified input matches the requirements for the field. /// /// - Parameter input: The input to validate. diff --git a/BitwardenKit/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidator.swift b/BitwardenKit/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidator.swift new file mode 100644 index 000000000..5f1d155a6 --- /dev/null +++ b/BitwardenKit/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidator.swift @@ -0,0 +1,30 @@ +import BitwardenResources + +// MARK: - EmptyInputValidator + +/// Validates that the input for a field is not empty. +/// +public struct EmptyInputValidator: InputValidator { + // MARK: Properties + + /// The name of the field that is being validated. + public let fieldName: String + + // MARK: Initializer + + /// Initializes an `EmptyInputValidator`. + /// + /// - Parameters: + /// - fieldName: The name of the field that is being validated. + public init(fieldName: String) { + self.fieldName = fieldName + } + + // MARK: InputValidator + + public func validate(input: String?) throws { + guard input?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false else { + throw InputValidationError(message: Localizations.validationFieldRequired(fieldName)) + } + } +} diff --git a/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidatorTests.swift b/BitwardenKit/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidatorTests.swift similarity index 97% rename from BitwardenShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidatorTests.swift rename to BitwardenKit/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidatorTests.swift index bf0f7f9ed..26d37ca48 100644 --- a/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidatorTests.swift +++ b/BitwardenKit/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidatorTests.swift @@ -1,7 +1,6 @@ +import BitwardenKit import XCTest -@testable import BitwardenShared - class EmptyInputValidatorTests: BitwardenTestCase { // MARK: Tests diff --git a/BitwardenShared/UI/Auth/SetMasterPassword/SetMasterPasswordProcessorTests.swift b/BitwardenShared/UI/Auth/SetMasterPassword/SetMasterPasswordProcessorTests.swift index 162b6b131..7dca21836 100644 --- a/BitwardenShared/UI/Auth/SetMasterPassword/SetMasterPasswordProcessorTests.swift +++ b/BitwardenShared/UI/Auth/SetMasterPassword/SetMasterPasswordProcessorTests.swift @@ -1,3 +1,4 @@ +import BitwardenKit import BitwardenKitMocks import BitwardenResources import BitwardenSdk diff --git a/BitwardenShared/UI/Auth/UpdateMasterPassword/UpdateMasterPasswordProcessorTests.swift b/BitwardenShared/UI/Auth/UpdateMasterPassword/UpdateMasterPasswordProcessorTests.swift index 902ac7a1c..f4aa1bd16 100644 --- a/BitwardenShared/UI/Auth/UpdateMasterPassword/UpdateMasterPasswordProcessorTests.swift +++ b/BitwardenShared/UI/Auth/UpdateMasterPassword/UpdateMasterPasswordProcessorTests.swift @@ -1,3 +1,4 @@ +import BitwardenKit import BitwardenKitMocks import BitwardenResources import BitwardenSdk diff --git a/BitwardenShared/UI/Platform/Application/Utilities/Alert/Alert/Alert+Error.swift b/BitwardenShared/UI/Platform/Application/Utilities/Alert/Alert/Alert+Error.swift index 72736db1a..9944501b1 100644 --- a/BitwardenShared/UI/Platform/Application/Utilities/Alert/Alert/Alert+Error.swift +++ b/BitwardenShared/UI/Platform/Application/Utilities/Alert/Alert/Alert+Error.swift @@ -1,3 +1,4 @@ +import BitwardenKit import BitwardenResources import Foundation diff --git a/BitwardenShared/UI/Platform/Application/Utilities/Alert/Alert/AlertErrorTests.swift b/BitwardenShared/UI/Platform/Application/Utilities/Alert/Alert/AlertErrorTests.swift index 36063f295..c5f13d9d7 100644 --- a/BitwardenShared/UI/Platform/Application/Utilities/Alert/Alert/AlertErrorTests.swift +++ b/BitwardenShared/UI/Platform/Application/Utilities/Alert/Alert/AlertErrorTests.swift @@ -1,3 +1,4 @@ +import BitwardenKit import BitwardenResources import XCTest diff --git a/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/InputValidationError.swift b/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/InputValidationError.swift deleted file mode 100644 index 5ca832f36..000000000 --- a/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/InputValidationError.swift +++ /dev/null @@ -1,8 +0,0 @@ -/// An error thrown by an `InputValidator` for invalid input in a field. -/// -struct InputValidationError: Error, Equatable { - // MARK: Properties - - /// A localized error message describing the validation error. - let message: String -} diff --git a/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/InputValidator.swift b/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/InputValidator.swift deleted file mode 100644 index 9e70ca0d5..000000000 --- a/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/InputValidator.swift +++ /dev/null @@ -1,9 +0,0 @@ -/// A protocol for an object that handles validating input for a field. -/// -protocol InputValidator { - /// Validates that the specified input matches the requirements for the field. - /// - /// - Parameter input: The input to validate. - /// - func validate(input: String?) throws -} diff --git a/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidator.swift b/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidator.swift deleted file mode 100644 index 3d8c7191a..000000000 --- a/BitwardenShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidator.swift +++ /dev/null @@ -1,18 +0,0 @@ -import BitwardenResources - -/// Validates that the input for a field is not empty. -/// -struct EmptyInputValidator: InputValidator { - // MARK: Properties - - /// The name of the field that is being validated. - let fieldName: String - - // MARK: InputValidator - - func validate(input: String?) throws { - guard input?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false else { - throw InputValidationError(message: Localizations.validationFieldRequired(fieldName)) - } - } -}