Added tests for coloring text fields

This commit is contained in:
Cameron McCord 2015-05-05 18:32:20 -06:00
parent 19490824c3
commit 4c7462e6a5
2 changed files with 16 additions and 3 deletions

View File

@ -18,7 +18,7 @@ public class Validator {
// dictionary to handle complex view hierarchies like dynamic tableview cells
public var errors:[UITextField:ValidationError] = [:]
public var validations:[UITextField:ValidationRule] = [:]
public var markTextFieldsInError:Bool = false
public var shouldMarkTextFieldsInError:Bool = false
public var textFieldErrorColor:UIColor = UIColor.redColor()
public init(){}
@ -51,7 +51,7 @@ public class Validator {
if let errorLabel = currentRule.errorLabel {
errorLabel.text = error.errorMessage
}
if markTextFieldsInError {
if shouldMarkTextFieldsInError {
self.markTextFieldAsInError(field)
}
errors[field] = error
@ -79,7 +79,7 @@ public class Validator {
if let errorLabel = currentRule.errorLabel {
errorLabel.text = error.errorMessage
}
if markTextFieldsInError {
if shouldMarkTextFieldsInError {
self.markTextFieldAsInError(field)
}
errors[field] = error

View File

@ -44,6 +44,8 @@ class ValidatorTests: XCTestCase {
let ERROR_LABEL = UILabel()
let GREEN_COLOR = UIColor.greenColor()
override func setUp() {
super.setUp()
// 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 {
}
}
}
func testTextFieldBorderColorSet() {
REGISTER_VALIDATOR.registerField(REGISTER_TXT_FIELD, errorLabel: ERROR_LABEL, rules: [EmailRule()])
REGISTER_TXT_FIELD.text = INVALID_EMAIL
REGISTER_VALIDATOR.textFieldErrorColor = GREEN_COLOR
REGISTER_VALIDATOR.shouldMarkTextFieldsInError = true
REGISTER_VALIDATOR.validate { (errors) -> Void in
XCTAssert(errors.count == 1, "Should come back with errors")
XCTAssert(CGColorEqualToColor(self.REGISTER_TXT_FIELD.layer.borderColor, self.GREEN_COLOR.CGColor), "Color should be what it was set as")
}
}
}