Skip to content

Commit b51ba8d

Browse files
[PM-26060] Consolidate InputValidator to BitwardenKit (#2068)
1 parent bc7817b commit b51ba8d

File tree

16 files changed

+60
-103
lines changed

16 files changed

+60
-103
lines changed

AuthenticatorShared/UI/Platform/Application/Utilities/Alert/Alert+Error.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BitwardenKit
12
import BitwardenResources
23
import Foundation
34

AuthenticatorShared/UI/Platform/Application/Utilities/Alert/AlertErrorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BitwardenKit
12
import BitwardenResources
23
import XCTest
34

AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/InputValidationError.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.

AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidator.swift

Lines changed: 0 additions & 18 deletions
This file was deleted.

AuthenticatorShared/UI/Platform/Application/Utilities/InputValidator/Validators/EmptyInputValidatorTests.swift

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// MARK: - InputValidationError
2+
3+
/// An error thrown by an `InputValidator` for invalid input in a field.
4+
///
5+
public struct InputValidationError: Error, Equatable {
6+
// MARK: Properties
7+
8+
/// A localized error message describing the validation error.
9+
public let message: String
10+
11+
// MARK: Initialization
12+
13+
/// Initialize an input validation error.
14+
///
15+
/// - Parameters:
16+
/// - message: A localized error message describing the validation error.
17+
public init(message: String) {
18+
self.message = message
19+
}
20+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
// - MARK: Input Validator
2+
13
/// A protocol for an object that handles validating input for a field.
24
///
3-
protocol InputValidator {
5+
public protocol InputValidator {
46
/// Validates that the specified input matches the requirements for the field.
57
///
68
/// - Parameter input: The input to validate.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import BitwardenResources
2+
3+
// MARK: - EmptyInputValidator
4+
5+
/// Validates that the input for a field is not empty.
6+
///
7+
public struct EmptyInputValidator: InputValidator {
8+
// MARK: Properties
9+
10+
/// The name of the field that is being validated.
11+
public let fieldName: String
12+
13+
// MARK: Initializer
14+
15+
/// Initializes an `EmptyInputValidator`.
16+
///
17+
/// - Parameters:
18+
/// - fieldName: The name of the field that is being validated.
19+
public init(fieldName: String) {
20+
self.fieldName = fieldName
21+
}
22+
23+
// MARK: InputValidator
24+
25+
public func validate(input: String?) throws {
26+
guard input?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false else {
27+
throw InputValidationError(message: Localizations.validationFieldRequired(fieldName))
28+
}
29+
}
30+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import BitwardenKit
12
import XCTest
23

3-
@testable import BitwardenShared
4-
54
class EmptyInputValidatorTests: BitwardenTestCase {
65
// MARK: Tests
76

BitwardenShared/UI/Auth/SetMasterPassword/SetMasterPasswordProcessorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BitwardenKit
12
import BitwardenKitMocks
23
import BitwardenResources
34
import BitwardenSdk

0 commit comments

Comments
 (0)