Skip to content

Commit ac77ff7

Browse files
CGRectmaterial-automation
authored andcommitted
Add unit tests for M3CTextField's color setters.
PiperOrigin-RevId: 686161099
1 parent 6046d06 commit ac77ff7

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

components/M3CTextField/tests/unit/M3CTextFieldTests.swift

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,96 @@ class M3CTextFieldTests: XCTestCase {
147147
assertSUTExpectations(for: errorColor)
148148
XCTAssertTrue(sutTextContainer.isFirstResponder)
149149
}
150+
151+
/// Tests that a new background color for a specific state is applied to the underlying
152+
/// UITextField when calling `setBackgroundColor`.
153+
func testSetBackgroundColorAppliesNewColor() {
154+
applyInitialColorTestingConfiguration(for: .normal)
155+
let defaultColor = expectedColor(for: .normal)
156+
let customColor = UIColor.green
157+
XCTAssertEqual(sutTextContainer.backgroundColor, defaultColor)
158+
159+
sutTextField.setBackgroundColor(customColor, for: .normal)
160+
XCTAssertEqual(sutTextContainer.backgroundColor, customColor)
161+
}
162+
163+
/// Tests that a new border color for a specific state is applied to the underlying
164+
/// UITextField when calling `setBorderColor`.
165+
func testSetBorderColorAppliesNewColor() {
166+
applyInitialColorTestingConfiguration(for: .normal)
167+
let defaultColor = expectedColor(for: .normal)
168+
let customColor = UIColor.green
169+
XCTAssertEqual(sutTextContainer.layer.borderColor, defaultColor.cgColor)
170+
171+
sutTextField.setBorderColor(customColor, for: .normal)
172+
173+
XCTAssertEqual(sutTextContainer.layer.borderColor, customColor.cgColor)
174+
}
175+
176+
/// Tests that a new input color for a specific state is applied to the underlying
177+
/// UITextField when calling `setInputColor`.
178+
func testSetInputColorAppliesNewColor() {
179+
applyInitialColorTestingConfiguration(for: .normal)
180+
let defaultColor = expectedColor(for: .normal)
181+
let customColor = UIColor.green
182+
XCTAssertEqual(sutTextContainer.textColor, defaultColor)
183+
184+
sutTextField.setInputColor(customColor, for: .normal)
185+
186+
XCTAssertEqual(sutTextContainer.textColor, customColor)
187+
}
188+
189+
/// Tests that a new supporting label color for a specific state is applied to the underlying
190+
/// UILabel when calling `setSupportingLabelColor`.
191+
func testSetSupportingLabelColorAppliesNewColor() {
192+
applyInitialColorTestingConfiguration(for: .normal)
193+
let defaultColor = expectedColor(for: .normal)
194+
let customColor = UIColor.green
195+
XCTAssertEqual(sutTextField.supportingLabel.textColor, defaultColor)
196+
197+
sutTextField.setSupportingLabelColor(customColor, for: .normal)
198+
199+
XCTAssertEqual(sutTextField.supportingLabel.textColor, customColor)
200+
}
201+
202+
/// Tests that a new tint color for a specific state is applied to the underlying
203+
/// UITextField when calling `setTintColor`.
204+
func testSetTintColorAppliesNewColor() {
205+
applyInitialColorTestingConfiguration(for: .normal)
206+
let defaultColor = expectedColor(for: .normal)
207+
let customColor = UIColor.green
208+
XCTAssertEqual(sutTextContainer.tintColor, defaultColor)
209+
210+
sutTextField.setTintColor(customColor, for: .normal)
211+
212+
XCTAssertEqual(sutTextContainer.tintColor, customColor)
213+
}
214+
215+
/// Tests that a new title label color for a specific state is applied to the underlying
216+
/// UILabel when calling `setTitleLabelColor`.
217+
func testSetTitleLabelColorAppliesNewColor() {
218+
applyInitialColorTestingConfiguration(for: .normal)
219+
let defaultColor = expectedColor(for: .normal)
220+
let customColor = UIColor.green
221+
XCTAssertEqual(sutTextField.titleLabel.textColor, defaultColor)
222+
223+
sutTextField.setTitleLabelColor(customColor, for: .normal)
224+
225+
XCTAssertEqual(sutTextField.titleLabel.textColor, customColor)
226+
}
227+
228+
/// Tests that a new trailing label color for a specific state is applied to the underlying
229+
/// UILabel when calling `setTrailingLabelColor`.
230+
func testSetTrailingLabelColorAppliesNewColor() {
231+
applyInitialColorTestingConfiguration(for: .normal)
232+
let defaultColor = expectedColor(for: .normal)
233+
let customColor = UIColor.green
234+
XCTAssertEqual(sutTextField.trailingLabel.textColor, defaultColor)
235+
236+
sutTextField.setTrailingLabelColor(customColor, for: .normal)
237+
238+
XCTAssertEqual(sutTextField.trailingLabel.textColor, customColor)
239+
}
150240
}
151241

152242
// MARK: - Test Assertion Helpers

0 commit comments

Comments
 (0)