Skip to content

Commit

Permalink
Add disabled color test
Browse files Browse the repository at this point in the history
  • Loading branch information
miang committed Oct 28, 2017
1 parent 5172c86 commit 90b5149
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,107 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
// then
XCTAssertEqual(floatingLabelTextField.titleLabel.textColor, self.customColor)
}

func test_whenSettingDisabledColor_withTextFieldBeingEnabled_thenTitleLabelTextColorIsNotChangedToThisColor() {
// given
floatingLabelTextField.isEnabled = true

// when
floatingLabelTextField.disabledColor = self.customColor

// then
XCTAssertNotEqual(floatingLabelTextField.titleLabel.textColor, self.customColor)
}

func test_whenSettingDisabledColor_withTextFieldBeingEnabled_thenPlaceholderColorIsNotChangedToThisColor() {
// given
floatingLabelTextField.isEnabled = true
floatingLabelTextField.placeholder = "test"
var fullRange =
NSRange(location: 0, length: floatingLabelTextField.placeholder!.characters.count)

// when
floatingLabelTextField.disabledColor = self.customColor

// then
#if swift(>=4.0)
XCTAssertNotEqual(
floatingLabelTextField.attributedPlaceholder!.attribute(
NSAttributedStringKey.foregroundColor, at: 0, effectiveRange: &fullRange
) as? UIColor,
customColor
)
#else
XCTAssertNotEqual(
floatingLabelTextField.attributedPlaceholder!.attribute(
NSForegroundColorAttributeName, at: 0, effectiveRange: &fullRange
) as? UIColor,
customColor
)
#endif
}

func test_whenSettingDisabledColor_withTextFieldBeingEnabled_thenLineViewBackgroundColorIsNotChangedToThisColor() {
// given
floatingLabelTextField.isEnabled = true

// when
floatingLabelTextField.disabledColor = self.customColor

// then
XCTAssertNotEqual(floatingLabelTextField.lineView.backgroundColor, self.customColor)
}

func test_whenSettingDisabledColor_withTextFieldBeingDisabled_thenTitleLabelTextColorIsChangedToThisColor() {
// given
floatingLabelTextField.isEnabled = false

// when
floatingLabelTextField.disabledColor = self.customColor

// then
XCTAssertEqual(floatingLabelTextField.titleLabel.textColor, self.customColor)
}

func test_whenSettingDisabledColor_withTextFieldBeingDisabled_thenPlaceholderColorIsChangedToThisColor() {
// given
floatingLabelTextField.isEnabled = false
floatingLabelTextField.placeholder = "test"
var fullRange =
NSRange(location: 0, length: floatingLabelTextField.placeholder!.characters.count)

// when
floatingLabelTextField.disabledColor = self.customColor

// then
#if swift(>=4.0)
XCTAssertEqual(
floatingLabelTextField.attributedPlaceholder!.attribute(
NSAttributedStringKey.foregroundColor, at: 0, effectiveRange: &fullRange
) as? UIColor,
customColor
)
#else
XCTAssertEqual(
floatingLabelTextField.attributedPlaceholder!.attribute(
NSForegroundColorAttributeName, at: 0, effectiveRange: &fullRange
) as? UIColor,
customColor
)
#endif
}

func test_whenSettingDisabledColor_withTextFieldBeingDisabled_thenLineViewBackgroundColorIsChangedToThisColor() {
// given
floatingLabelTextField.isEnabled = false

// when
floatingLabelTextField.disabledColor = self.customColor

// then
XCTAssertEqual(floatingLabelTextField.lineView.backgroundColor, self.customColor)
}

// MARK: - fonts

func test_whenSettingPlaceholderFont_thenAttributedPlaceholderTextIsSet_withFont() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ class SkyFloatingLabelTextFieldWithIconTests: XCTestCase {
// then
XCTAssertEqual(floatingLabelTextFieldWithIcon.iconLabel.textColor, customColor)
}


func test_whenSettingDisabledColor_withTextFieldBeingDisabled_thenColorAppliedToIconLabel() {
// when
floatingLabelTextFieldWithIcon.disabledColor = customColor
floatingLabelTextFieldWithIcon.isEnabled = false

// then
XCTAssertEqual(floatingLabelTextFieldWithIcon.iconLabel.textColor, customColor)
}

func test_whenSettingSelectedIconColor_withTextFieldBeingSelected_thenColorAppliedToIconLabel() {
// when
floatingLabelTextFieldWithIcon.selectedIconColor = customColor
Expand Down

0 comments on commit 90b5149

Please sign in to comment.