Skip to content

Commit

Permalink
Add unit test for M3CTextField's traitCollectionDidChange.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 692300627
  • Loading branch information
CGRect authored and material-automation committed Nov 1, 2024
1 parent 8eb898d commit 3692400
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions components/M3CTextField/tests/unit/M3CTextFieldTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,22 @@ class M3CTextFieldTests: XCTestCase {

XCTAssertFalse(trailingLabel.isHidden)
}

/// Tests that the border color is updated after a trait collection change.
func testTraitCollectionChangeToDifferentTraitCollectionUpdatesSubviews() {
let lightTraitCollection = UITraitCollection(userInterfaceStyle: .light)
let darkTraitCollection = UITraitCollection(userInterfaceStyle: .dark)
let initialBorderColor = expectedColor(for: .normal).cgColor
let expectedNewBorderColor = expectedColor(for: .error).cgColor
sutTextField.traitCollectionDidChange(lightTraitCollection)
sutTextField.isInErrorState = true
sutTextField.borderColors = testColorValues
sutTextContainer.layer.borderColor = initialBorderColor

sutTextField.traitCollectionDidChange(darkTraitCollection)

XCTAssertEqual(sutTextContainer.layer.borderColor, expectedNewBorderColor)
}
}

// MARK: - Test Assertion Helpers
Expand Down

0 comments on commit 3692400

Please sign in to comment.