Skip to content

Commit eaae3a2

Browse files
Mark Pospeselmpospese
authored andcommitted
[CM-735] Mark isBoldTextEnabled public
1 parent eb00238 commit eaae3a2

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

Sources/YMatterType/Typography/FontRepresentable.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,14 @@ extension FontRepresentable {
141141
return .black
142142
}
143143
}
144-
}
145144

146-
internal extension FontRepresentable {
147-
func isBoldTextEnabled(compatibleWith traitCollection: UITraitCollection?) -> Bool {
145+
/// Determines whether the accessibility Bold Text feature is enabled within the given trait collection.
146+
/// - Parameter traitCollection: the trait collection to evaluate (or nil to use system settings)
147+
/// - Returns: `true` if the accessibility Bold Text feature is enabled.
148+
///
149+
/// If `traitCollection` is not `nil`, it checks for `legibilityWeight == .bold`.
150+
/// If `traitCollection` is `nil`, then it examines the system wide `UIAccessibility` setting of the same name.
151+
public func isBoldTextEnabled(compatibleWith traitCollection: UITraitCollection?) -> Bool {
148152
guard let traitCollection = traitCollection else {
149153
return UIAccessibility.isBoldTextEnabled
150154
}

Tests/YMatterTypeTests/Typography/FontRepresentableTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ final class FontRepresentableTests: XCTestCase {
6666
XCTAssertEqual(font.pointSize, systemFont.pointSize)
6767
XCTAssertEqual(font.lineHeight, systemFont.lineHeight)
6868
}
69+
70+
func testIsBoldTextEnabled() {
71+
let (sut, _, _) = makeSUT()
72+
73+
// given a traitCollection with legibilityWeight == .bold, it should return `true`
74+
XCTAssertTrue(sut.isBoldTextEnabled(compatibleWith: UITraitCollection(legibilityWeight: .bold)))
75+
XCTAssertTrue(sut.isBoldTextEnabled(compatibleWith: UITraitCollection(traitsFrom: [
76+
UITraitCollection(preferredContentSizeCategory: .extraLarge),
77+
UITraitCollection(legibilityWeight: .bold)
78+
])))
79+
80+
// given a traitCollection with legibilityWeight != .bold, it should return `false`
81+
XCTAssertFalse(sut.isBoldTextEnabled(compatibleWith: UITraitCollection(legibilityWeight: .regular)))
82+
XCTAssertFalse(sut.isBoldTextEnabled(compatibleWith: UITraitCollection(legibilityWeight: .unspecified)))
83+
84+
// given a traitCollection without legibilityWeight trait, it should return `false`
85+
XCTAssertFalse(sut.isBoldTextEnabled(compatibleWith: UITraitCollection()))
86+
XCTAssertFalse(sut.isBoldTextEnabled(compatibleWith: UITraitCollection(preferredContentSizeCategory: .small)))
87+
88+
// given traitCollection is nil, it should return the system setting
89+
XCTAssertEqual(sut.isBoldTextEnabled(compatibleWith: nil), UIAccessibility.isBoldTextEnabled)
90+
}
6991
}
7092

7193
// We use large tuples in makeSUT()

0 commit comments

Comments
 (0)