Skip to content

Commit

Permalink
Add unit test for M3CTextField's layoutSubviews.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 691940350
  • Loading branch information
CGRect authored and material-automation committed Oct 31, 2024
1 parent c2b2772 commit 2d71b8a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions components/M3CTextField/tests/unit/M3CTextFieldTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,32 @@ class M3CTextFieldTests: XCTestCase {
XCTAssertEqual(sutTextField.placeholder, sutTextContainer.placeholder)
XCTAssertEqual(sutTextField.text, sutTextContainer.text)
}

/// Tests that `layoutSubviews` hides a visible trailing label with an empty `text`.
func testLayoutSubviewsHidesEmptyTrailingLabel() {
let trailingLabel = UILabel()
trailingLabel.text = ""
trailingLabel.isHidden = false
sutTextField.trailingLabel = trailingLabel
XCTAssertFalse(trailingLabel.isHidden)

sutTextField.layoutSubviews()

XCTAssertTrue(trailingLabel.isHidden)
}

/// Tests that `layoutSubviews` shows a hidden trailing label with a populated `text`.
func testLayoutSubviewsShowsTrailingLabelWithText() {
let trailingLabel = UILabel()
trailingLabel.text = "Trailing"
trailingLabel.isHidden = true
sutTextField.trailingLabel = trailingLabel
XCTAssertTrue(trailingLabel.isHidden)

sutTextField.layoutSubviews()

XCTAssertFalse(trailingLabel.isHidden)
}
}

// MARK: - Test Assertion Helpers
Expand Down

0 comments on commit 2d71b8a

Please sign in to comment.