Skip to content

Commit 4c7462e

Browse files
Added tests for coloring text fields
1 parent 1949082 commit 4c7462e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Validator/Validator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Validator {
1818
// dictionary to handle complex view hierarchies like dynamic tableview cells
1919
public var errors:[UITextField:ValidationError] = [:]
2020
public var validations:[UITextField:ValidationRule] = [:]
21-
public var markTextFieldsInError:Bool = false
21+
public var shouldMarkTextFieldsInError:Bool = false
2222
public var textFieldErrorColor:UIColor = UIColor.redColor()
2323

2424
public init(){}
@@ -51,7 +51,7 @@ public class Validator {
5151
if let errorLabel = currentRule.errorLabel {
5252
errorLabel.text = error.errorMessage
5353
}
54-
if markTextFieldsInError {
54+
if shouldMarkTextFieldsInError {
5555
self.markTextFieldAsInError(field)
5656
}
5757
errors[field] = error
@@ -79,7 +79,7 @@ public class Validator {
7979
if let errorLabel = currentRule.errorLabel {
8080
errorLabel.text = error.errorMessage
8181
}
82-
if markTextFieldsInError {
82+
if shouldMarkTextFieldsInError {
8383
self.markTextFieldAsInError(field)
8484
}
8585
errors[field] = error

ValidatorTests/ValidatorTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class ValidatorTests: XCTestCase {
4444

4545
let ERROR_LABEL = UILabel()
4646

47+
let GREEN_COLOR = UIColor.greenColor()
48+
4749
override func setUp() {
4850
super.setUp()
4951
// Put setup code here. This method is called before the invocation of each test method in the class.
@@ -238,4 +240,15 @@ class ValidatorTests: XCTestCase {
238240
}
239241
}
240242
}
243+
244+
func testTextFieldBorderColorSet() {
245+
REGISTER_VALIDATOR.registerField(REGISTER_TXT_FIELD, errorLabel: ERROR_LABEL, rules: [EmailRule()])
246+
REGISTER_TXT_FIELD.text = INVALID_EMAIL
247+
REGISTER_VALIDATOR.textFieldErrorColor = GREEN_COLOR
248+
REGISTER_VALIDATOR.shouldMarkTextFieldsInError = true
249+
REGISTER_VALIDATOR.validate { (errors) -> Void in
250+
XCTAssert(errors.count == 1, "Should come back with errors")
251+
XCTAssert(CGColorEqualToColor(self.REGISTER_TXT_FIELD.layer.borderColor, self.GREEN_COLOR.CGColor), "Color should be what it was set as")
252+
}
253+
}
241254
}

0 commit comments

Comments
 (0)